i am new to CUDA and is trying to learn the usage. can someone please help. i have the following in the main function (i am in visual studio and my source and header files are .cu and .cuh respectively)
thrust::device_vector<float> d_vec(100);
kernel<<<100,1>>>(d_vec);
and then in the kernel i have
template <typename T> __global__ kernel(thrust::device_vector<T> d_vec)
{ int tid = threadIdx.x + blockIdx.x*blockDim.x;
T xxx = 3.0;
d_vec[tid] = xxx;
}
my objective is to call the kernel once with float and once with double. Also note that in this simple example i have variable xxx (which in my real case is some computation producing double or float numbers).
and i get two error:
1> calling a __host__
function (operator =) from a __global__
function is not allowed
2> calling a __host__
function (operator []) from a __global__
function is not allowed
so i guess "[]" and "=" in "d_vec[tid] = .." is the problem. But my question is how do i access the device vector inside my kernel. Can someone please clarify what is the correct procedure and what i am doing wrong. thanks in advance