
[英]thrust set difference fails to compile with calling a __host__ function from a __host__ __device__ function is not allowed
[英]cuda::cub error calling a __host__ function from a __device__ functionis not allowed
我使用cub :: DeviceReduce :: Sum来计算向量的总和,但这给了我错误:
error: calling a __host__ function("cub::DeviceReduce::Sum<double *, double *> ") from a __device__ function("dotcubdev") is not allowed
error: identifier "cub::DeviceReduce::Sum<double *, double *> " is undefined in device code
代码示例如下:
__device__ void sumcubdev(double* a, double *sum, int N)
{
// Declare, allocate, and initialize device-accessible pointers
//for input and output
// Determine temporary device storage requirements
void *d_temp_storage = NULL;
size_t temp_storage_bytes = 0;
cub::DeviceReduce::Sum(d_temp_storage, temp_storage_bytes, a, sum, N);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sum-reduction
cub::DeviceReduce::Sum(d_temp_storage, temp_storage_bytes, a, sum, N);
}
该代码可以在“ main {}”主体中成功运行,但不能在该函数中运行。
要使用设备代码中的cub设备范围的功能,必须构建您的项目以支持CUDA动态并行性。 在cub文档中 ,这在此处指示:
使用注意事项动态并行性。 可以在支持CUDA动态并行性的设备上的内核代码中调用DeviceReduce方法。
例如,您可以编译显示的代码:
$ cat t1364.cu
#include <cub/cub.cuh>
__device__ void sumcubdev(double* a, double *sum, int N)
{
// Declare, allocate, and initialize device-accessible pointers
//for input and output
// Determine temporary device storage requirements
void *d_temp_storage = NULL;
size_t temp_storage_bytes = 0;
cub::DeviceReduce::Sum(d_temp_storage, temp_storage_bytes, a, sum, N);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sum-reduction
cub::DeviceReduce::Sum(d_temp_storage, temp_storage_bytes, a, sum, N);
}
$ nvcc -arch=sm_35 -dc t1364.cu
$
(CUDA 9.2,CUB 1.8.0)
这意味着CUB将启动子内核以完成工作。
这不是有关如何使用CUDA动态并行(CDP)的完整教程。 上面仅是compile命令,省略了链接步骤。 在cuda
标记上,这里有许多讨论CDP的问题,您可以在两篇博客文章和编程指南中阅读有关CDP的内容,并且还有CUDA 示例项目显示了如何编译和使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.