卡达吉普车矢量
CUDA gpu vector
最近,当我尝试使用CUDA编程时,我想将一个向量发送到GPU内存。有人告诉我可以使用 thrust::device_vector 和 thrust::host_vector。我也看了帮助文档,但还是不知道怎么把这样一个vector送进内核函数。
我的代码如下:
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);
如果你有一个向量数组,你需要做一些像here.
中描述的那样的事情
最近,当我尝试使用CUDA编程时,我想将一个向量发送到GPU内存。有人告诉我可以使用 thrust::device_vector 和 thrust::host_vector。我也看了帮助文档,但还是不知道怎么把这样一个vector送进内核函数。 我的代码如下:
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);
如果你有一个向量数组,你需要做一些像here.
中描述的那样的事情