Start with CUDA Start with CUDA programming

Hi All,

I’m new with CUDA programming. I have tried to write a simple program of multiply two matrices (e.g. M and N) but no success so far.

The main error that I have obtained is:

error C2065: ‘threadIdx’: undeclared identifier error C2228: left of ‘.x’ must have class/struct/union

I have did the following to build my program:

I have installed CUDA toolkit 3.0 and then CUDA SDK

I have tested the installation by running some CUDA example and it is work.

Im trying to write simple program to multiple two matrices (M and N).

  1. Using Microsoft Visual Studio C\C++, I have created new project—> Win32 Console Application.
  2. Identify the path of CUDA toolkit and CUDA SDK libraries (include and lib) files in the VC++ directory as the following VC++ -->Tools—>Options—>project and solutions–>VC++ directories 3. Write a program for two matrices multiplication. The structure of the program as the following

Main program (cpp extension) consists from:

(1) matrix parameters identification ( for example width= height=8)
(2) input the matrices element values
(3) Allocate host memories for the needed matrices (i.e. M, N and P)
(4) Call the multiplication function
(5)Free host Matrices (M and N).

Multiplication function (cu extension) consists from:

(1) Allocate device memory for the needed matrices(Md, Nd and Pd)
(2) Copy the two matrices that want to be multiplied from host to device
(3) Setup the execution configuration
(4) invoke the (the kernal) that would multiply the two matrices in parallel. The Kernel in cu extension.
(5) Copy the result matrix from device to host
(6) Free device matrices

Kernel consists from

(1) Identify the thread
(2) Do the multiplication condition

The errors that I got are:

Error
Fatal error C1083: cannot open include file: ‘shrUtils.h’: No such file or directory when I remove #include <shrUtils.h> from the program, I get:

Error
error C2065: ‘threadIdx’: undeclared identifier error C2228: left of ‘.x’ must have class/struct/union

the same error for threadIdx.y

error C2059: syntax error: ‘<’

Any Help would be appreciated.

Thanks
Hus

Hi Again;

The program has been solved by copying one of SDK examples and paste it on the same folder. Then delet it and insert my codes and it is working!!

I think my problem is how to create a proper template contains CPP and CU extensions…Any Help about this issue?

How to create a new project or template that suitable with CUDA programing?

What I usually do is opening Microsoft Visual Studio C++: File—>New---->project---->Win32 console application.
Then add cu file to the source code list and write my kernel function on it? Obviously this doesn’t work with me…

any comments or adivses?
Thanks
Hus

CUDA code has to be compiled using NVCC. The SDK samples do this using a custom build rule in Visual Studio - right click on the .cu file and select properties - in Configuration Properties -> General select “CUDA Build Rule” for “Tool”. Hope this helps.

Thanks Simon,

I’ve done your advise and it is working but just inside SDK samples program.

How can I create a template of CUDA vs wizard?

There are some websites recommend to download such a program to integrate CUDA template with visual studio wizard?

any advise regarding this issue?

Hi Hus,

Please see the post for adding the cuda build rules to visual studio
[post=“0”]http://forums.nvidia.com/index.php?showtopic=167890[/post]

Then add the cuda build rules to the project you have created. Also you have to add the CUDA include and lib path to the visual studio or project. Alos you have to include the inc and lib in the GPU Computing SDK folder to Visual Studio or Project.

Thanks Sijo, it was helpful.