I am using Cuda SDK 4.0 and am facing a problem that took me 2 days to destroy the following code.
#include <cuda.h> #include <cuda_runtime.h> void main (int argc, char ** argv) { int* test; cudaError_t err; err = cudaSetDevice( 1 ); err = cudaMallocHost(&test, 1024*sizeof(int)); err = cudaSetDevice( 0 ); err = cudaFreeHost(test); }
This causes the following error when calling cudaFreeHost:
First-chance exception at 0x000007fefd96aa7d in Test.exe: Microsoft C++ exception: cudaError_enum at memory location 0x0022f958..
Error value cudaErrorInvalidValue
The same error occurs with this change:
err = cudaSetDevice( 0 ); err = cudaMallocHost(&test, 1024*sizeof(int)); err = cudaSetDevice( 1 ); err = cudaFreeHost(test);
The following options do not throw an error:
err = cudaSetDevice( 0 ); err = cudaMallocHost(&test, 1024*sizeof(int)); err = cudaSetDevice( 0 ); err = cudaFreeHost(test);
and
err = cudaSetDevice( 1 ); err = cudaMallocHost(&test, 1024*sizeof(int)); err = cudaSetDevice( 1 ); err = cudaFreeHost(test);
It seemed to me that you only need to call cudaSetDevice if you want to allocate memory on a specific GPU. In the above example, I only allocate fixed memory on the CPU.
Is this a mistake or am I missing something in the manual?
twerdster
source share