1.显示blockDim等变量出现了未定义的错误:
![](https://img.haomeiwen.com/i1516503/313fca883fd5fddd.png)
解决方法:添加头文件
#include "device_launch_parameters.h"
2.无法打开 源 文件 "helper_cuda.h"
![](https://img.haomeiwen.com/i1516503/76ef134d5d23a792.png)
首先找到这些头文件的位置:
C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.5\common\inc
![](https://img.haomeiwen.com/i1516503/558233392877fd91.png)
将该位置include到项目中
![](https://img.haomeiwen.com/i1516503/0c6625a5902fa3fb.png)
但是仍然报错,不过程序可以正确运行了。
第二种方案:If you want to copy the samples to a customized place, you have to copy the whole samples dir, or modify some code/compile options to include staff in common/ dir.
3.使用
__device__ __managed__
报错error : managed variables require architecture compute_30 or higher
![](https://img.haomeiwen.com/i1516503/a8b037eb21c01092.png)
解决方法:由于vs 2013默认编译sm_20,但是Unifiled Memory需要3.0以上的计算能力,所以修改编译的条件。
![](https://img.haomeiwen.com/i1516503/a8ca74e2d8f82dc5.png)
4.kernel中递归调用出错
![](https://img.haomeiwen.com/i1516503/7a11dab0e1d56c22.png)
需要设置-rdc=true
5.在一个cu文件中,先include .h文件,再include .cuh文件报错,不知道原因是什么,但是如果先包含cuh文件再包含h文件则可以正确运行。
6.在global核函数中,不能直接使用thrust的device_vector,作为参数传递。https://stackoverflow.com/questions/5510715/thrust-inside-user-written-kernels
thrust::device_vector<int> dev;
int * raw_ptr = thrust::raw_pointer_cast(&dev[0]);
__global__ void test(int* raw, int len){
....
}
test<<<grid,block>>> test(raw_ptr,dev.size());
网友评论