Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HANDLE_ERROR not found error in Cuda

Tags:

cuda

__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 );
}

This is the code. HANDLE_ERROR not found error is being generated. i dont know how to solve it. Tried to grab some header files but can't figure it out...

Any Help Please!!!

like image 383
SunnyChattha Avatar asked Nov 06 '12 06:11

SunnyChattha


2 Answers

If I had to guess, I'd say you're using the book CUDA By Example, which defines the HANDLE_ERROR macro as follows:

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 );
    }
}
#define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))

Make sure that this code appears somewhere in your source, or somewhere in a header you #include.

like image 94
kevintodisco Avatar answered Oct 17 '22 17:10

kevintodisco


You can download the source code for the book here.

The source code also contains the header files (in the common folder), where the missing macros are defined, and which the book quotes in the source codes as (for example)

#include "../common/book.h"

If the links become unavailable, search the books title on the Nvidia Developer site, or the site of the CUDA, you will find the direct link to the book's page, where the source code can be found.

like image 29
Klára Nagy-Szabó Avatar answered Oct 17 '22 18:10

Klára Nagy-Szabó