C# + CUDA threading problem

Basically, my application consists of a C# and a C++ CUDA project.
The C# part is the main application, and the CUDA code is built to a dll which is accessed by the first one.
The problem is that if I do some memory allocation and copy from a C# thread, when I call functions that use these values, I get a lot of errors from CUDA, and sometimes my display blinks.
Is this expected?

Yes I did experience blinking of the screen and that prolly because of GPU memory allocation/copy or misuse. What error messages do you exactly get?

Generally, I get the Invalid Device Pointer error.

How long does it take for the longest of your kernels to finish? More than 2 seconds?

Something like 5ms

“CUDA device pointers” are thread-context specific. YOu cannot allocate in one thread (be it C++ / C#) and use in another thread…

You have to use them in the same thread (thread as seen by the OS – does not matter whether it was written in C# | C++)

that’s not true with context migration


Can you elaborate.?

What is not true? And, what is context migration? Is that a new CUDA 3.0 feature?

Could you tell us more about this context migration?

cuCtxPushCurrent/cuCtxPopCurrent, which have been in the driver API for years. as of 3.1, you can use them from the runtime API.

Runtime API context migration! Now we are talking…

no, full driver/runtime interop (cudaStream_t == CUstream, textures across APIs, the whole shebang)


Will it be good to understand it this way


“The contexts referred by “cuPushCurrent/popCurrent/CreateContext” etc. are basically sub-contexts inside the main threading context…So they can share pointers around…”

Well, this is not really “migration”… Just “switching” thats all… No?