Using Device Pointers from different functions

Hi!

I have some trouble using device pointers from different functions. I have a class and defined a (private) member which I want to use as a device pointer to a table in the class. However it only works if the pointer is only used in one function.

So something like

Class::InitTable()

{

XX = cudaMalloc(size);

setTable<<<...>>>();

}

Class::UseTable

{

DoSomething<<<...>>>(XX);

}

doesn’t work and the table seems just to be filled with random values. While on the other hand

Class::InitAndUseTable()

{

if (!XX) {cudaMalloc(size); setTable<<<...>>>();}

DoSomething<<<...>>>(XX);

}

works perfectly fine.

Is this a known problem with CUDA? What else could be the reason?

Thanks!

Are these functions potentially called by different host threads? Device pointers are generally not portable between CUDA contexts, and each host thread is implicitly given a different context in the runtime API.

Indeed they are, thanks for the hint.

I guess I’ll have to rewrite things to execude all the CUDA stuff from one thread.

Improving support for multithreaded applications is something we’re actively working on.