GPU Computing

cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help on Customizing GPU Computing Using the LabVIEW GPU Analysis Toolkit

Hello,

I downloaded the LabVIEW GPU Analysis Toolkit and I am trying to cusomize and GPU funciton. I read the pdf manual in Calling Custom GPU Functions.zip , however I am totally lost in creating a DLL based on the custom.cpp

I wonder anyone can help me.

My first question is what tool should I use. I installed Visual Studio 2010, Nsight and CUDA driver and toolkit, am I using the right compiler?

My second questoin is how should I add a CUDA function in the file custom.cpp? Should I change the extension to .cu to compile?

I have a simple code here for array transpose, I wonder if anyone can show me with this specific example... Thanks very very much...

#define TILE_DIM 32

#define BLOCK_ROWS 8

__global__ void transposeNaive(float *odata, float* idata,

int width, int height, int nreps)

{

int xIndex = blockIdx.x*TILE_DIM + threadIdx.x;

int yIndex = blockIdx.y*TILE_DIM + threadIdx.y;

int index_in = xIndex + width * yIndex;

int index_out = yIndex + height * xIndex;

for (int r=0; r < nreps; r++) {

for (int i=0; i<TILE_DIM; i+=BLOCK_ROWS) {

odata[index_out+i] = idata[index_in+i*width];

}

}

}

0 Kudos
Message 1 of 7
(12,921 Views)

For those who have already written and compiled their code, the custom.h and custom.cpp should provide enough information to help them figure out how to 'plug' their function in using the SDK. It (nor the SDK documentation) is designed to teach someone how to create a external function written in code outside of LabVIEW.

If you are interested in learning how to write a custom GPU function based on CUDA, you'll want to research the documentation NVIDIA provides on its website at

http://developer.nvidia.com/cuda/nvidia-gpu-computing-documentation. Once you've successfully built a CUDA function using their guidance, then you can turn to this SDK document for the way to call it safely and effectively from LabVIEW.

Good luck!

Message 2 of 7
(9,166 Views)

Thank you so much for you reply. The link you provided is very helpful. Althought I haven't written a GPU function by myself yet, I do successfully compiled and executed several example function NVIDIA provided.

The problem is I still do not know how to use the custom.cpp... I know that the problem results from that I still know too little about CUDA, but I believe there are others in the same situation like me. So a more specific example of compile a simple GPU function like vector add would help rookies like me out. And such examples in further help document or labview examples would make this wonderful toolkit more popular, I think.

0 Kudos
Message 3 of 7
(9,166 Views)

Sorry for the misunderstanding. The custom.cpp source is a file I created for the example data types defined in the document. You will have your own source files (e.g. myCUDAFcts.cpp and myCUDAFcts.h) which you write to define your CUDA functions and build your Windows library.

If you're not familiar with building Windows libraries, my example code will not be sufficient to teach you how to build this library. However, my source codes does show you the files on which the toolkit SDK depends (e.g. header files) and where to find them.

Microsoft has information on how to use Visual Studio to build a DLL. Googling 'building a windows dll' should get you the relevant links.

Good luck!

Message 4 of 7
(9,166 Views)

Thank you so much for reply my stupid question again.

I have been trying my best, based on my current knowledge, to understand the manual and do a simple example here, but still got failed.

I built a dll using the following code in visual studio, and did a innovation, exe setup and build a vi, then called this vi in the test.vi, but got an error 1097. I uploaded my labview vi, I wonder if you might help me about this.

#include "cuda_runtime.h"

#include "device_launch_parameters.h"

#include <stdio.h>

#include <windows.h>

#include <string.h>

#include <ctype.h>

#include <math.h>

/* Define all the functions to use */

extern "C" __declspec (dllexport) void VectorAdd(int *,size_t);

__global__ void addKernel(int *a)

{

    int i = threadIdx.x;

    a = a + 1;

}

BOOL APIENTRY DllMain( HANDLE hModule,

          DWORD  ul_reason_for_call,

          LPVOID lpReserved )

{

          return TRUE;

}

/* Add two integers */

_declspec (dllexport) void VectorAdd(int * dev_a, size_t size){

  addKernel<<<1, size>>>(dev_a);

}

0 Kudos
Message 5 of 7
(9,166 Views)

Error 1097 is a general execution failure for an external function invoked by the CLN (Call Libary Function Node). There are many reasons why this error gets generated. I could not load your example because I do not have the required binaries for your DLL so I couldn't reproduce the error.

I inspected the G code portion of your wrapper and they look good. I noticed that you configured your CLN to call your DLL function using the WinAPI (stdcall) rather than the C calling convention. Since this can be one cause of this error, I would make this declaration explicit in your code (add __cdecl or __stdcall to your function declaration) and use that setting in the VI's CLN.

If you plan to build your example for 32- and 64-bit LabVIEWs, you'll want to use __cdecl to avoid consistency issues. If this doesn't fix the problem, then I suggest you build your example into an EXE and debug any issues you find there first.

Once that succeeds, you can convert the build process back to generating a DLL. Then, you'll know that any problem going forward isdue to calling the external function and not from the function itself.

Message 6 of 7
(9,166 Views)

It did fix the problem after I declared my function using __cdecl and set it as C calling. Thank you so much for your help.

0 Kudos
Message 7 of 7
(9,166 Views)