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

查看:3063
本文介绍了动态并行性 - 未定义引用__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;
}

file.cuh:

void test( void );

file.cu:

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

#include "file.cuh"

__global__ void printId( void )
{
    printf("Hello from block %d \n", 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

这里是编译时出现的错误:

And here's the error while compiling:

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'

os:红帽
卡:K20x

os: Red Hat card: K20x

任何想法?

感谢

推荐答案

这是最近的问题的相当多重复。

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

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

nvcc 命令行指定一个只编译操作( -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天全站免登陆