Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to compile simple CUDA example

test.cu:

#include <iostream> 
#include "book.h"
__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; 
}

I am trying to compile above example test.cu. I tried with nvcc test.cu but compiler gives error

4.cu:2:18: fatal error: book.h: No such file or directory
compilation terminated.

How can I tell compiler where book.h is present? I have installed CUDA in /usr/local/cuda. Do I need to make Makefile? I am new to CUDA and Makefile so question might seem trivial.

like image 619
alekhine Avatar asked Mar 23 '26 02:03

alekhine


1 Answers

Book.h is not CUDA. It is used by "Cuda by Example" for some easy stuff.
In this example it is needed to provide the HANDLE_ERROR, you should write your own code to handle errors.

Here you can find the book.h code: http://code.google.com/p/cuda-examples/source/browse/trunk/common/book.h?r=3

like image 56
Simone-Cu Avatar answered Mar 24 '26 23:03

Simone-Cu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!