I’m trying out examples in the book “CUDA by exmaple”. The first two printf examples compiled and worked, but now i came up with a problem with this code which is as given.
It seems to be a problem with HANDLE_ERROR, I’m not used to Visual Studio (i use code blocks) and trying NVIDIA Parallel Nsight 2.1 with it, it is the only way I found to easily program CUDA.
Here is the debug:
1>------ Build started: Project: Hello World, Configuration: Debug Win32 ------
1>Compiling with CUDA Build Rule...
1>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.1\bin\nvcc.exe" -G0 -gencode=arch=compute_10,code=\"sm_10,compute_10\" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --machine 32 -ccbin "c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin" -Xcompiler "/EHsc /W3 /nologo /O2 /Zi /MT " -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.1\include" -maxrregcount=0 --compile -o "Debug/kernel.cu.obj" kernel.cu
1>kernel.cu
1>c:/Users/Jonathan/Documents/Visual Studio 2008/Projects/Hello World/Hello World/kernel.cu(17): error: identifier "HANDLE_ERROR" is undefined
1>1 error detected in the compilation of "C:/Users/Jonathan/AppData/Local/Temp/tmpxft_00001d1c_00000000-8_kernel.compute_20.cpp1.ii".
1>Project : error PRJ0019: A tool returned an error code from "Compiling with CUDA Build Rule..."
1>Build log was saved at "file://c:\Users\Jonathan\Documents\Visual Studio 2008\Projects\Hello World\Hello World\Debug\BuildLog.htm"
1>Hello World - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Here is the code:
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <iostream>
__global__ void add( int a, int b, int *c )
{
*c = a + b;
}
int main( void )
{
int c;
int *dev_c;
HANDLE_ERROR( cudaMalloc( (void**)&dev_c, sizeof(int) ) );
add<<<1,1>>>( 2, 7, dev_c );
HANDLE_ERROR( cudaMemcpy( &c,
dev_c,
sizeof(int),
cudaMemcpyDeviceToHost ) );
printf( "2 + 7 = %d\n", c );
cudaFree( dev_c );
return 0;
}
Thanks a bunch!