[CUDA: 4.0] Check context of given resouce

Hi,

Lets imagine the situation, that I have a lot of initialized resources for example: streams, host and device memory end events, part of them are initialized in context of one GPU and the rest of them belong to the other GPU context.

Is there a way to check if given resource (event, stream or memory) belongs to certain GPU context?

In some case it would worthy to assert such things, before order memory copy or kernel execution and then get cudaErrorInvalidArgument.

I’m afraid you have to track it manually. I’m working on small wrapper which helps doint that to some extent (with the driver api), plan to make it accessible when I finish it.

As for the device memory, you can use cuPointerGetAttribute to get the context which used to allocate it

Ok, so with methods cudaStreamQuery and with cudaEventQuery (those methods will return invalid argument error if given resources are uninitialized or if they are initialized but belong to other context) I can check almost all cuda resources. Only one thing left - pinned memory.