I allocated the memory for an array of unsigned char using cudaMalloc and the initialized using cudaMemset.
unsigned char *device_channel_data;
cudaMalloc( device_channel_data, sizeof(unsigned char) * image_size);
cudaMemset( *device_channel_data, 0, sizeof(unsigned char) * image_size);
After that I'm checking whether it is really set to 0 by copying the data back to host. I'm printing some of the elements to check the data but the values printed are random.
unsigned char *host_channel_channel;
cudaMemcpy(host_channel_channel, device_channel_data, sizeof(unsigned char) * image_size, cudaMemcpyDeviceToHost);
for(int i = 0; i < 10; i ++)
{
std::cout<< (int)host_channel_channel[i] << std::endl;
}
I want to initialize the device_channel data to 0. My knowledge with pointers and CUDA programming is very limited. I'm just starting with CUDA Programming. Thanks in advance for the help.