0
我有一個問題,從設備/全局內核訪問和分配變量與cusp array1d類型。附帶的代碼給出錯誤從設備內核訪問cusp變量元素
alay.cu(8): warning: address of a host variable "p1" cannot be directly taken in a device function
alay.cu(8): error: calling a __host__ function("thrust::detail::vector_base<float, thrust::device_malloc_allocator<float> > ::operator []") from a __global__ function("func") is not allowed
代碼下面
#include <cusp/blas.h>
cusp::array1d<float, cusp::device_memory> p1(10,3);
__global__ void func()
{
p1[blockIdx.x]=p1[blockIdx.x]+blockIdx.x*5;
}
int main()
{
func<<<10,1>>>();
return 0;
}
是的,我想通過設備線程操縱裝置array1d,你能不能詳細說明或給出示例代碼,因爲我仍然不明白? – user3040447
只是一個疑問,你的意思是'cusp :: array1d p2(10)= p1;'是cusp :: array1d p2(10)= p1; 「是嗎? –
不,我編輯了這個問題和代碼,使我的問題更易於理解 – user3040447