LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

C++/CUDA DLL fails to give correct results when running a second time

Hi all.

 

I just finished writing a C++/CUDA DLL that runs in labview.

It passes a 3d array, crunches the data, then spits out some results as a 2d array.

 

When I open labview, and run it, I get the predicted results. However if I run the labview code again, it gives me garbage data.

I have to not only close the open VI, but all of labview itself, reopen it, and then it will work again for one run.

 

I read a thread on somthing similar to this happening with C++ code due to the way labview handled threads, however this was over 10 years ago, and it seems that since LV 2008 this has been fixed. I am running LV 2011.

 

In my code, I checked that all dynamic memory allocated gets deleted, both on the GPU and CPU so other than that, I'm not sure what the problem could be. What changes when I call the DLL a second time?

 

Please ask me to clarify anything that you might need to know about the program, and its implimentation.

 

I have written other labview DLLs in just C++ that have not had this problem, so I wonder if it is a CUDA specific thing, or maybe somthing else I am overlooking.

0 Kudos
Message 1 of 3
(2,259 Views)

Hi again,

I wonder if this has to do with the Labview CUDA Compute Context thingy which I completely do not understand.

 

My DLL is basically an all in one. It takes labview values, handles etc for arrays and numbers, and then in my dll I allocate and delete and transfer etc all the memory there. The compute context seems to imply I should be using Labview CUDA VIs to initialize my memoery, create a compute context, etc...

0 Kudos
Message 2 of 3
(2,258 Views)

It seems to be that something not properly closed. What you can try is - unload DLL.

 

CUDA Compute Context should be theoretically not necessary if your CUDA functions executed "all in one call" (and properly closed at all). The reason for NI Compute is following: it is not guaranteed that thread safe DLL calls will be called in the same thread. So, for example if you have three separate DLL calls in LabVIEW, for example - transfer data to GPU memory, compute, transfer back to the host - they should be done in the same thread (in CUDA terms all functions should be executed within same context). You can call these functions in UI thread - it will work, but the UI thread will be blocked. Or you can mark calls as thread safe, and using NI Compute - then all three calls will be done within same thread and this thread is separated from UI thread.

 

Andrey.


0 Kudos
Message 3 of 3
(2,245 Views)