Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should a very simple Makefile look like for Cuda compiling under linux

I want to compile a very basic hello world level Cuda program under Linux. I have three files:

  • the kernel: helloWorld.cu
  • main method: helloWorld.cpp
  • common header: helloWorld.h

Could you write me a simple Makefile to compile this with nvcc and g++?

Thanks,
Gabor

like image 907
Vereb Avatar asked Oct 22 '09 12:10

Vereb


1 Answers

I've never heard of Cuda before, but from the online documentation it looks as if X.cu is supposed to be compiled into X.o, so having helloWorld.cu and helloWorld.cpp is not a good idea. With your permission I'll rename the "kernel" helloKernel.cu, then this should work:

NVCC = nvcc

helloWorld.o: helloWorld.cpp helloWorld.h
    $(NVCC) -c %&lt -o $@

helloKernel.o: helloKernel.cu
    $(NVCC) -c %&lt -o $@

helloWorld: helloWorld.o helloKernel.o
    $(NVCC) %^ -o $@

(Note that those leading spaces are tabs.)

If that works, try a slicker version:

NVCC = nvcc

helloWorld.o: %.o : %.cpp %.h
helloKernel.o: %.o : %.cu

%.o:
    $(NVCC) -c %&lt -o $@

helloWorld: helloWorld.o helloKernel.o
    $(NVCC) %^ -o $@
like image 113
Beta Avatar answered Nov 03 '22 09:11

Beta