From Cg to CUDA How to reuse the code developed by Cg??

Hi everyone,
I am a tyro in GPU programming. I have read the documents downloaded from NVIDIA website and the sample code. My job is to “upgrade” the Cg code developed by other team member earilier to CUDA. But after I searched all the discussions on the forum, I still can’t get how to start.

I also read the book “The Cg Tutorial” roughly and after compared the content, our Cg code and the CUDA sample code, I found that in CUDA it seems like to divide into kernel and other part but I didn’t see the same way in the Cg code. I would like to know if there is any relationship between Cg and CUDA when you developed CUDA. I need someone to tell me how to map Cg into CUDA or where can I get documents or resources about this topic.

Thank you for your help!!

ypyp

There isn’t really much of a relationship between Cg and CUDA other than they are both languages for programming the GPU. Cg was designed for shading, CUDA is designed for general purpose processing.

One problem that people often run into is that CUDA doesn’t define mathematical operations such as ±/*/dot/normalize on vector types (float3/float4 etc.) as standard. The CUDA 1.1 SDK now includes a header file that defines many of the most common Cg functions, which can be useful for porting code. I can post it here if you want.

First of all I would translate the Cg shaders to equivalent CUDA kernels. Then it should be fairly simple to convert the graphics API calls that invoke the shaders into equivalent CUDA API calls.

Hi Simon,

Thank you for your reply. I would like to know the header file you mentioned, and if you can also provide any example or detail description for the translation you mentioned will be very appreciated.

Thank you again!!

ypyp

Add some explaintation for your information…
Our goal is using the GPU’s excellent processing ability to do some data calculations. Of course finally we need to display, but the general purpose data processing is that we concerned mainly now. That is why we wish to “upgrade” the original code to CUDA. That is my condition now. Could you give me any comments?

Thank you!!

Where can i find the CUDA 1.1 SDK. I did not see it on NIVIDA website. Thanks

Nowhere. It’s for Registered Developers only at this time.

Hope it’ll go public in few days… Can’t wait to try some of its features =)

Here’s the cutil_math header file I mentioned which provides Cg-like operations on vector types.

We’re planning a CUDA 1.1 public beta release soon, pending some further testing.
cutil_math.h (17.9 KB)

The new math library is very nice for the ppl working with small vectors. How about the ppl that work wil matrices? Is there also a math library for matrices? I thought that in CUDA 1.0 there were some standard matrix functions. but these are only for very small matrices and they always must be an square like 32x32 of 64x64 never 400x132 or something like that. :(

You should use CUBLAS for dealing with large vectors and matrices.