动态并行 - 编译时对 __cudaRegisterLinkedBinary 链接错误的未定义引用 - 单独编译 [英] Dynamic Parallelism - undefined reference to __cudaRegisterLinkedBinary linking error while compiling - separate compilation

查看:29
本文介绍了动态并行 - 编译时对 __cudaRegisterLinkedBinary 链接错误的未定义引用 - 单独编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试编译一个简单的代码时遇到问题,C++ 和 Cuda 代码是分开编译的.

I got a problem when I try to compile a simple code there are C++ and Cuda code compile in a separated way.

这是我的代码

main.cpp:

#include "file.cuh"

int main( void )
{
     test();
     return 0;
}

文件.cuh:

void test( void );

文件.cu:

#include <cuda.h>
#include <cuda_runtime.h>
#include <cstdio>

#include "file.cuh"

__global__ void printId( void )
{
    printf("Hello from block %d 
", blockIdx.x);
}

__global__ void DynPara( void )
{
    dim3 grid( 2, 1, 1 );
    dim3 block( 1, 1, 1 );

    printId<<< grid, block >>>();
}

void test( void )
{
    dim3 grid( 1, 1, 1 );
    dim3 block( 1, 1, 1 );

    dynPara<<< grid, block >>>();
}

我编译:

nvcc -arch=sm_35 -lcudadevrt -rdc=true -c file.cu
g++ file.o main.cpp -L<path> -lcudart

这是编译时的错误:

file.o: In function `__sti____cudaRegisterAll_39_tmpxft_00005b2f_00000000_6_file_cpp1_ii_99181f96()':
tmpxft_00005b2f_00000000-3_file.cudafe1.cpp:(.text+0x1cd): undefined reference to `__cudaRegisterLinkedBinary_39_tmpxft_00005b2f_00000000_6_file_cpp1_ii_99181f96'

操作系统:红帽卡:K20x

os: Red Hat card: K20x

有什么想法吗?

谢谢

推荐答案

这个问题几乎是这个问题的重复 最近的问题.

This question is pretty much a duplicate of this recent question.

除了编译之外,动态并行还需要可重定位的设备代码链接.

Dynamic parallelism requires relocatable device code linking, in addition to compiling.

您的 nvcc 命令行指定了仅编译操作 (-rdc=true -c).

Your nvcc command line specifies a compile-only operation (-rdc=true -c).

g++ 不做任何设备代码链接.所以在这样的场景中,当使用 g++ 需要额外的设备代码链接步骤.

g++ does not do any device code linking. So in a scenario like this, when doing the final link operation using g++ an extra device code link step is required.

类似这样的:

nvcc -arch=sm_35 -rdc=true -c file.cu
nvcc -arch=sm_35 -dlink -o file_link.o file.o -lcudadevrt -lcudart
g++ file.o file_link.o main.cpp -L<path> -lcudart -lcudadevrt

这篇关于动态并行 - 编译时对 __cudaRegisterLinkedBinary 链接错误的未定义引用 - 单独编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆