If you are using the CUDA runtime API, then either you will need to initialize an array on the device or on the host to accomplish non-zero values. It can’t be done directly with cudaMemset, for an arbitrary non-zero value.
Hi guys,
So I wonder if my device array is made up of a struct, and the struct contains 3 integers, is it possible to initilize all integers in the array of struct to zero with cudaMemset?
cudaMemset, like memset, takes a size argument in bytes. Using this, you can initialize any size array.
struct mystruct{
int x;
int y;
int z;
};
...
const int num = 1234;
mystruct *d_a;
cudaMalloc(&d_a, num*sizeof(mystruct));
cudaMemset(d_a, 0, num*sizeof(mystruct));