不支持外部呼叫 - CUDA [英] External calls are not supported - CUDA
问题描述
目的是调用另一个文件中可用的设备函数,当我编译全局内核时,它显示以下错误 *不支持外部调用(发现非内联调用_Z6GoldenSectionCUDA )* 。
Objective is to call a device function available in another file, when i compile the global kernel it shows the following error *External calls are not supported (found non-inlined call to _Z6GoldenSectionCUDA)*.
问题代码(不是完整代码,但出现问题的地方),
cat norm.h
Problematic Code (not the full code but where the problem arises), cat norm.h
# ifndef NORM_H_
# define NORM_H_
# include<stdio.h>
__device__ double invcdf(double prob, double mean, double stddev);
#endif
cat norm.cu
cat norm.cu
# include <norm.h>
__device__ double invcdf(double prob, double mean, double stddev) {
return (mean + stddev*normcdfinv(prob));
}
cat test.cu
cat test.cu
# include <norm.h>
# include <curand.h>
# include <curand_kernel.h>
__global__ void phase2Kernel(double* out_profit, struct strategyHolder* strategy) {
curandState seedValue;
curand_init(threadIdx.x, 0, 0, &seedValue);
double randomD = invcdf(curand_uniform_double( &seedValue ), 300, 80);
}
nvcc -c norm.cu -o norm.o -I
nvcc -c test.cu -o test.o -I。
nvcc -c norm.cu -o norm.o -I"."
nvcc -c test.cu -o test.o -I"."
推荐答案
重新尝试单独编译,这需要一些特殊的命令行选项。请参见 NVCC手册,但这里是如何让你的示例编译。我已经针对sm_20,但你可以根据你有什么GPU目标sm_20或更高版本。
You're trying to do separate compilation, which needs some special command line options. See the NVCC manual for details, but here's how to get your example to compile. I've targeted sm_20, but you can target sm_20 or later depending on what GPU you have. Separate compilation is not possible on older devices (sm_1x).
- 您不需要声明
__ device __
作为extern
在你的头文件,但如果你有任何静态设备变量,他们需要被声明为extern
-
通过编译如下所示生成设备的可重定位代码(
-dc
等效于-c
,请参阅手册了解详情)
- You don't need to declare the
__device__
function asextern
in your header file, but if you have any static device variables they will need to be declared asextern
Generate relocatable code for the device by compiling as shown below (
-dc
is the device equivalent of-c
, see the manual for more information)
nvcc -arch=sm_20 -dc norm.cu -o norm.o -I.
nvcc -arch=sm_20 -dc test.cu -o test.o -I.
在最终主机链接之前通过调用nvlink链接代码的设备部分
Link the device parts of the code by calling nvlink before the final host link
nvlink -arch=sm_20 norm.o test.o -o final.o
这篇关于不支持外部呼叫 - CUDA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!