Error when running

I keep getting this message

“terminate called after throwing an instance of ‘bool’”

when using cudaMemcpy to copy data back from GPU to CPU.

    Anyone has an idea why?


This is possibly a combination of a mistake in your code and a bug in the CUDA runtime. We have seen this before when a user takes the address of device data and uses the address in the host code (this is illegal).

This is an easy mistake to make when you are getting started:

__device__ int a;

int main(


  int h;

 cudaMemcpy(&h, &a, 4, cudaMemcpyDeviceToHost);


If a is a constant, you should probably declare it as constant and use cudaMemcpyToSymbol. If it is not a constant, use cudaMalloc to get a pointer, then do the cudaMemcpy. There are examples of this in the SDK.

Because of a bug in the runtime, an incorrect exception is thrown that is

not being caught be the runtime itself as it should, which obscures the real issue. The runtime should return a

cudaErrorInvalidDevicePointer error code. This will be fixed in the future.


Thanks, I have been using CUDA before the public release, and the document was not very clear how to use constant, so I never use it.

Well, I have yet to find where the error is.

thanks again


I solved the problem. I made a mistake when referencing memory in my kernel functions.

thanks again


I’m running into a simular problem, I’m trying to allocate some memory in the device and re use it in a few kernel calls, it works for the first few times but then craps out. In emu mode it throws this exception. You said something about a problem refrencing the item in the kernel ? can you explane ?

I can’t reproduce the problem in a simple programe, our code at some point creates another thread. The initial calls to the cuda functions are in the main thread and the later calls come from the new thread, could this cause a problem ?



This is most certainly your problem. Cuda has contexts that depend on running only from within their own threads.

You’ll have to reformulate your code to use this pardigm.