【发布时间】:2019-08-19 14:14:49
【问题描述】:
我一直在阅读 CUDA 编程指南中关于模板函数的内容,这样的东西是否有效?
#include <cstdio>
/* host struct */
template <typename T>
struct Test {
T *val;
int size;
};
/* struct device */
template <typename T>
__device__ Test<T> *d_test;
/* test function */
template <typename T>
T __device__ testfunc() {
return *d_test<T>->val;
}
/* test kernel */
__global__ void kernel() {
printf("funcout = %g \n", testfunc<float>());
}
我得到了正确的结果,但有一个警告:
“警告:不能在设备函数中直接读取主机变量“d_test [with T=T]”?
testfunction 中的结构是否用*d_test<float>->val 实例化?
韩国, 伊吉
【问题讨论】:
标签: cuda compiler-warnings nvcc compiler-bug template-variables