error C2065: 'blockIdx' : undeclared identifier simple Cuda program doesnot run

[codebox]#include

#include <stdio.h>

#include “CUUtil.h”

//#include “device_launch_parameters.h”

#include “cuda_runtime.h”

//#include “crt\device_runtime.h”

//#include “crt\host_runtime.h”

using namespace std;

global void kernel( int *a )

{

int idx = blockIdx.x*blockDim.x + threadIdx.x;

a[idx] = 7;

}

int main()

{

int dimx = 16;

char	a;

int num_bytes = dimx*sizeof(int);

int *d_a=0, *h_a=0; // device and host pointers

h_a = (int*)malloc(num_bytes);

cudaMalloc( (void**)&d_a, num_bytes );

if( 0==h_a || 0==d_a )

	{

		printf("couldn't allocate memory\n");

		return 1;

	}

cudaMemset( d_a, 0, num_bytes );

dim3 grid, block;

block.x = 4;

grid.x = dimx / block.x;

kernel( d_a );

cudaMemcpy( h_a, d_a, num_bytes, cudaMemcpyDeviceToHost );

for(int i=0; i<dimx; i++)

printf("%d ", h_a[i] );

printf("\n");

free( h_a );

cudaFree( d_a );

cin.get(a);

return 0;

}[/codebox]

This is the simple CUDA code which is not getting complied.

I Am getting folowwing errors.

[codebox]1>------ Build started: Project: PaulTest, Configuration: Debug x64 ------

1>Compiling…

1>testThread.cpp

1>.\testThread.cpp(14) : error C2065: ‘blockIdx’ : undeclared identifier

1>.\testThread.cpp(14) : error C2228: left of ‘.x’ must have class/struct/union

1> type is ‘‘unknown-type’’

1>.\testThread.cpp(14) : error C2065: ‘blockDim’ : undeclared identifier

1>.\testThread.cpp(14) : error C2228: left of ‘.x’ must have class/struct/union

1> type is ‘‘unknown-type’’

1>.\testThread.cpp(14) : error C2065: ‘threadIdx’ : undeclared identifier

1>.\testThread.cpp(14) : error C2228: left of ‘.x’ must have class/struct/union

1> type is ‘‘unknown-type’’

1>Build log was saved at “file://c:\Documents and Settings\npp04086\My Documents\Visual Studio 2005\Projects\PaulTest\PaulTest\x64\Debug\BuildLog.htm”

1>PaulTest - 6 error(s), 0 warning(s)

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

[/codebox]

Please let me know how can i compile the code.

when you define global function, you must name it as .cu file, not .cpp file,

then use nvcc to compile .cu file

Ok so how do we start a project for CUda in Visual C++ env.

I was able to comply a cpp file where i was using functions like memset and memcipy.

but how do a compile a .cu file.

i short i mean how to start a Cuda project from scratch?

can you please suggest or else can you please provide me useful link for my purpose.

regards,

Nabarun.

you can use CUDA VS Wizard 2.0 Release

http://forums.nvidia.com/index.php?showtopic=83054

generally speaking, you will have .cu file and .cpp file in your vc project

when you include .cu file into your project, you need a rule

( .rules in C:\Program Files (x86)\Microsoft Visual Studio 8\VC\VCProjectDefaults)

to use nvcc to compile .cu file, then you can use VC compiler or intel C++ compiler

for host code.

.

Thank you Mr. LSChien .

I am giving it a try now.

Ok now,

i was getting 12 errors.

after modifying the properties, now i am getting following 5 errors.

Please let me know how can this errors be done away with .

[codebox]1>------ Build started: Project: csum, Configuration: Debug x64 ------

1>Compiling…

1>cl : Command line warning D9038 : /ZI is not supported on this platform; enabling /Zi instead

1>cl : Command line warning D9007 : ‘/Gm’ requires ‘/Zi’; option ignored

1>csum.cpp

1>Linking…

1>csum.obj : warning LNK4217: locally defined symbol free imported in function main

1>csum.obj : warning LNK4217: locally defined symbol malloc imported in function main

1>csum.obj : error LNK2019: unresolved external symbol “void __cdecl sumcu(int *)” (?sumcu@@YAXPEAH@Z) referenced in function main

1>csum.obj : error LNK2019: unresolved external symbol __imp_printf referenced in function main

1>csum.obj : error LNK2019: unresolved external symbol __imp_rand referenced in function “void __cdecl Util::value(float &,unsigned int,unsigned int,unsigned int,unsigned int,unsigned int,unsigned int,unsigned int,enum Util::BufferValue)” (??$value@M@Util@@YAXAEAMIIIIIIIW4BufferValue@0@@Z)

1>csum.obj : error LNK2019: unresolved external symbol __imp_ceilf referenced in function “float __cdecl ceil(float)” (?ceil@@YAMM@Z)

1>C:\Documents and Settings\hpv04559\My Documents\Visual Studio 2005\Projects\cudasum\x64\Debug\csum.exe : fatal error LNK1120: 4 unresolved externals

1>Build log was saved at “file://c:\Documents and Settings\hpv04559\My Documents\Visual Studio 2005\Projects\cudasum\cudasum\x64\Debug\BuildLog.htm”

1>csum - 5 error(s), 4 warning(s)

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

[/codebox]

regards,

Nabarun.

Hi There,

I have just started with CUDA and have exactly the same problem - how do you create a brand new project for VS 2008. This thread has helped a little but you have got further than me. I downloaded the Wizard, but despite the website saying that it covers both 64 bit and 32 bit I only see a 64 bit wizard in VS 2008 (I am running 32-bit XP SP3 and VS2008 Express edition). When I try creating a 64 bit project I get

Did you get this? Do you know how to solve it?

Thanks

Raffles

After a bit of poking around I found the link for the 32 bit version here.

Thanks

Raffles

Hi There,

I had a different problem.

Though the wizard was doing all necessary settings for by 64 bit machine.

but the problem was with my .cu file.

i did the necessary changes and now the project is running fine.

regards,

Nabarun.