GPU Computing

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in wrapping CUDA function

Hi everyone, I'm new to labview CUDA. I'm trying to wrap the CUSPARSE functions in the CUDA package into a labview subvi, but it seems to be harder than I thought. I tried to start from scretch with the custum datatype class, but it seems the existing vis does not want to accept the new class for the CUSPARSE function handle. Then I turned to steal the structure and classes from an existing CUBLAS function, changing the kernal dll call to the CUSPARSE dll file and link all datatype according to the CODA document. I built a simple testing program according to the structure of a CUBLAS example, looked into every vi and subvi and replaced every dll call directing to the CUBLAS dll to the CUSPARSE dll. However the program keeps giving error 1097, and I cannot really spot where it comes from. Could anyone kindly look into the program and spot where I did it wrong? I know I put the CUSPARSE handle into a CUBLAS handle container, since I suppose they're the same datatype. Am I wrong?

0 Kudos
Message 1 of 6
(9,363 Views)

It's not as simple as re-using the CUBLAS interface because your missing support for the CUSPARSE datatype(s).

If you're not using the online documentation for creating a custom interface - Customizing GPU Computing Using the LabVIEW GPU Analysis Toolkit, it is likely you will miss one ore more requirements. Here's a link to it:

http://digital.ni.com/public.nsf/allkb/82D5EDC19AF79F0786257A4C007417B1

It is possible to re-use the current VI interfaces if the data types are the same. This is because the underlying types that ship w/ the toolkit know how to clean up the resources allocated for those data types. This is necessary to avoid leaking resources when, for example, a VI is stopped in the middle of processing.

Although the CUBLAS and CUSPARSE handles may be stored using the same atomic type (e.g. 32-bit integer), the CUBLAS library and function interface define how this handle interacts w/ a CUDA context. This may or may not be the same for CUSPARSE. I can tell you that clean up is special for a CUBLAS handle and a specific cublas function is registered to properly clean it up.

If you did use the document to make your edits but did not create your own external library w/ entry points to cleanup a CUSPARSE handle, I would start there. Once you can create a handle and dispose of it from G. then problems with calling a specific CUSPARSE math function will be easier to debug.

As for the error message you getting, I can't find it in any of the CUDA headers files. I don't believe this is being generated by my toolkit or LabVIEW as it corresponds to an undefined error code.

Hope this helps!

Darren

0 Kudos
Message 2 of 6
(7,450 Views)

Hi, Darren,

I've read the documentation of customizing GPU function before I started. I think I did follow the required structure since I modified the vis from one of the CUBLAS vi in the package.

I managed to find where the CUBLAS handle was generated and replaced it with the CUSPARSE handle generator, but I didn't find where the CUBLAS handle was cleaned up. I looked into the release library vi for cublas but there's only some generic vis in it. Maybe I should add a cusparseDestroy function somewhere. I'll follow your advice and start from the handle.

I'll let you know about the results. Thank you for the help!

Zhihao

0 Kudos
Message 3 of 6
(7,450 Views)

The information you are looking for is in section Building a Custom GPU Data Type. That covers the construction of the LVClass which wraps your handle type and Step 4 covers defining the cleanup step. I believe you will have to define an external cleanup interface. See Code Sample 1 for the interface and Code Sample 2 for the how to define the function(s).

Just so you know, defining a custom data type is the most complicated item to add. This is because any GPU computing involves two runtime engines (LabVIEW & NVIDIA's CUDA) and neither are aware of each other's allocated resources.

You won't be able to find where I define the CUBLAS cleanup function because it's source code used to build the support library is not supplied with the toolkit. Instead, I've included example files & projects with this documentation that show how these functions are constructed/coded. It's easier to understand than the original source for the toolkit.

When you create your new data type, it will need to be built into it's own shared library (i.e. Windows DLL). I did not see any source code or binary for that in the ZIP file you attached.

Darren

0 Kudos
Message 4 of 6
(7,450 Views)

Do you mean all I need to use the package is to build a custom GPU datatype for the CUSPARSE handle? I went through the documentation again but honestly I don't understand Step 4. I'm a labview guy and I don't have much experience with C (what a shame!). Does that part mean that I have to write some codes and compile and link them with VC? I guess the functions like 'GPUDeviceData1CleanupProc' in the code samples should be replaced by some specific functions, but what are they? Where and how should these cleanup dlls be used?

I know these questions sound stupid and I'm start feeling desprate about this now. Do you think someone like me can make this work at last? Shall I be installing Visual Studio now?

Sorry for being such a noob, and thank you again for the all patience.

Zhihao

0 Kudos
Message 5 of 6
(7,450 Views)

If you aren't familiar w/ C/C++ or building shared libraries then you are missing some of the prerequisites you need to add a custom data type. This doesn't mean you can't learn those skills but the GPU Analysis Toolkit isn't the best educational platform for you in this regard. Despite the example code that ships w/ the online document, it isn't designed to teach you how to code outside LabVIEW.

NVIDIA's CUDA Toolkit ships with several C-based examples. You may find them helpful and better suited to learning the C code requirements. NVIDIA's developer forums may also give you information on how to build shared libraries (called DLLs on Windows) but libraries aren't specific to GPU computing with CUDA. You may need to find a more general Windows programming source to help with those.

Although it sounds like you took the correct approach for building the G-based functional interfaces to CUSPARSE functions, getting them to work properly is going to require more knowledge of C and external libraries. You'll also need to know how the CUSPARSE data types are supposed to be used from a C API.

Here's a link to NVIDIA's online documentation: http://docs.nvidia.com/cuda/index.html. I would start there and see if their introductory material helps.

Good luck!

Darren

0 Kudos
Message 6 of 6
(7,450 Views)