About mixing Runtime and Driver API


I’m trying to merge two CUDA 4.0 projects - a realtime raytracer (Runtime API) and a motion blur reconstruction algorithm (Driver API), neither written by me.

Samples are generated by the raytracer and passed to the reconstruction. This works fine.
For the next frame however, when the raytracer tries to access device data (like stored triangle positions), none of the old memory allocations seem valid and everything breaks.

It this a “feature” of CUDA, or a symptom of the code?

In general, it should be possible to “mix” the runtime and driver API - at least to the extent of sharing the same memory between both APIs. There may be many possible reasons for the error. Maybe the memory from one project is freed after each frame or so, but presumably you have already verified that this is not the case…

It’s a bit hard to infer from your description - how are the samples passed to the reconstruction algorithm? Also, when you say the memory allocations aren’t valid, what error message(s) do you receive?

My first guess is that the two projects are using different cuda contexts. i.e. if the runtime api code is executed first, then it’ll (implicitly) create a cuda context on a cuda call. Odds are the driver api code will explicitly creates its own cuda context, seeing as it was written independently of your raytracer project. This is a problem, as the device memory addresses are based on their contexts, meaning that a device pointer from 1 context won’t be valid in a different context. Is this the case?