Vector CUDA gpu矢量

Vector CUDA gpu矢量,vector,visual-studio-2015,cuda,gpu,thrust,Vector,Visual Studio 2015,Cuda,Gpu,Thrust,最近,当我尝试使用CUDA编程时,我想向GPU内存发送一个向量。有人告诉我,我可以使用推力::设备\向量和推力::主机\向量。我也阅读了帮助文档,但仍然不知道如何将这样一个向量发送到内核函数中。 我的代码如下: thrust::device_vector<int> dev_firetime[1000]; __global__ void computeCurrent(thrust::device_vector<int> d_ftime) { int idx = b

最近,当我尝试使用CUDA编程时,我想向GPU内存发送一个向量。有人告诉我,我可以使用推力::设备\向量和推力::主机\向量。我也阅读了帮助文档,但仍然不知道如何将这样一个向量发送到内核函数中。 我的代码如下:

thrust::device_vector<int> dev_firetime[1000];

__global__ void computeCurrent(thrust::device_vector<int> d_ftime)
{
    int idx = blockDim.x*blockIdx.x + threadIdx.x;
    printf("ftime = %d\n", d_ftime[idx]);   
}
事实上,我不知道如何将向量发送到核函数。如果你知道,请告诉我一些关于这个问题,有没有更好的方法来完成相同的功能?
非常感谢

推力装置矢量不能直接传递给CUDA内核。您需要向内核传递一个指向底层设备内存的指针。可以这样做:

__global__ void computeCurrent(int* d_ftime)
{
    int idx = blockDim.x*blockIdx.x + threadIdx.x;
    printf("ftime = %d\n", d_ftime[idx]);   
}

thrust::device_vector<int> dev_firetime(1000);
int* d_ftime = thrust::raw_pointer_cast<int*>(dev_firetime.data());
computeCurrent<<<....>>>(d_ftime);

如果你有一个向量数组,你需要像上面描述的那样做。

非常感谢。我照你说的做了,结果还是有点错。我将代码更改为:int*d_ftime=推力::原始指针\u castdev\u firetime[0];然后,它正常工作。但是,我有1000个向量,我必须一个接一个地得到它们的指针吗?我可以这样定义向量:推力::设备_向量开发_firetime[1000];?很抱歉,我没有注意到您实际上需要一个向量数组。我在我的回答中编辑了一个与最近一个问题相同的链接。