views:

3488

answers:

3

Hi, 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

+3  A: 
Beta
Can you use nvcc on the normal cpp files?
teeks99
I don't have access to nvcc, so I can't be certain, but according to the documentation, yes. For ordinary compiler tasks, nvcc hands the job off to a standard compiler like g++.
Beta
+1  A: 

Just in case, here's my variant. I use it to compile CUDA projects on Mac, but I think it will suit Linux too. It requires CUDA SDK.

BINDIR = ./ # places compiled binary in current directory
EXECUTABLE := helloWorld

CCFILES := helloWorld.cpp
CUFILES := helloWorld.cu

# an ugly part - setting rootdir for CUDA SDK makefile
# look for common.mk - I don't know where SDK installs it on Linux -
# and change ROOTDIR accordingly 
ROOTDIR := /Developer/GPU\ Computing/C/common

include $(ROOTDIR)/../common/common.mk
Manti
Hrmm it looks for the strange cutil.h which I don't use..
Nils
+2  A: 

My version, verbose but transparent:

myapp: myapp.o
    g++ -fPIC -o $@ $< -L /usr/local/cuda/lib -lcudart

myapp.o: myapp.cu
    /usr/local/cuda/bin/nvcc --compiler-options -fno-strict-aliasing \
    -I/usr/local/cuda/include \
    -DUNIX -O2 -o $@ -c $<

matrixMul: matrixMul.o
    g++ -fPIC -o $@ $< -L /usr/local/cuda/lib -lcudart

# It MUST be named .cu or nvcc compiles as regular C !!! (no __global__)
matrixMul.o: matrixMul.cu
    /usr/local/cuda/bin/nvcc --compiler-options -fno-strict-aliasing \
    -I/usr/local/cuda/include \
    -DUNIX -O2 -o $@ -c $<
keraba