[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.