Reputation: 204
I have a C dll that uses CUDA to perform operations on a CUDA texture object. I am repeatedly calling the C dll from C# managed code using the same data for the texture.
The time taken to transfer the data for the texture object onto the GPU is significantly longer than the time taken to perform the actual processing.
In order to speed up the processing, I am looking for the best way to keep a copy of the texture object on the card by keeping a pointer to it inbetween calls to the Dll from the managed code.
Is it better to keep hold of the pointer in the C dll somehow or is it better to pass the pointer to the texture object back into the managed code and pass that to the C DLL in subsequent function calls?
Any ideas on how to approach either method would be hugely appreciated.
I am not an expert in C/C++, so I may be missing something really obvious...
Upvotes: 0
Views: 265
Reputation: 204
I have found a solution which appears to work (thanks Robert for your comment above).
Because the dll itself exists in memory inbetween the function calls from managed code (I didn't know this originally), I simply declared two static variables in the C dll:-
static cudaTextureObject_t TexureVariable;
static cudaArray* ArrayPointer;
I can assign the data to the static texture as normal in one initial function call. I can then run multiple operations using that texture data and finally destroy/free both static objects from a single function call.
Upvotes: 1