I used the this code.
int *cpu_ptr = (int *)malloc(sizeof(int)*10);
int *gpu_ptr;
err = cudaMalloc((void **)&gpu_ptr, sizeof(int)*10);
if (err != cudaSuccess) {
fprintf(stderr, "Failed to allocate gpu_ptr (error code %s)!\n", cudaGetErrorString(err));
exit(EXIT_FAILURE);
}
err = cudaMemcpy(gpu_ptr, cpu_ptr, sizeof(int)*10, cudaMemcpyHostToDevice);
if (err != cudaSuccess) {
fprintf(stderr, "Failed to copy host to device test (error code %s)!\n", cudaGetErrorString(err));
exit(EXIT_FAILURE);
}
when I use this code before, there is no error.
but I changed the total Device memory size which is using memory size, occurring the “illegal memory access was encountered” error.