Problem with HANDLE_ERROR?

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!

Well I just needed to get rid of that “HANDLE_ERROR” nonsense. Must of been in the books cd of headers…

working version

#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;

	cudaMalloc( (void**)&dev_c, sizeof(int) );

	add<<<1,1>>>( 2, 7, dev_c );

	cudaMemcpy( &c,dev_c,sizeof(int),cudaMemcpyDeviceToHost );

	printf( "2 + 7 = %d\n", c );

	cudaFree( dev_c );

	getchar();

	return 0;

}

I’m also having the same problem :(
Have you solved this problem?

G.

Here is a link to all the examples in the book. http://developer.nvidia.com/sites/default/files/akamai/cuda/files/cuda_by_example.zip

You don’t have to type anything and the header files are already in there. Just compile with nvcc and run.

I have bought this book from google play. is there any CD with book? the book.h is not defined as header. So, I have to type all program manually for learning. any idea?

google “cuda by example”

take the first hit (nvidia developer)

read on that page until you find the link to download the source code

I am facing the same problem with the same book.

Problem Solved! You need to put this patch into your code directly after the header files. Then it will work. I is working for me now.

#define HANDLE_ERROR( err ) ( HandleError( err, FILE, LINE ) )
static void HandleError(cudaError_t err, const char *file, int line)
{if (err != cudaSuccess)
{printf(“%s in %s at line %d\n”, cudaGetErrorString(err),file, line);
exit(EXIT_FAILURE);
}
}