如何在Linux下使用Cuda编译一个非常简单的Makefile

Ver*_*reb 10 cuda gpgpu makefile compilation

我想在Linux下编译一个非常基本的hello世界级Cuda程序.我有三个文件:

  • 内核:helloWorld.cu
  • 主要方法:helloWorld.cpp
  • common header:helloWorld.h

你能给我写一个简单的Makefile来用nvcc和g ++编译吗?

谢谢,
Gabor

Bet*_*eta 8

我之前从未听说过Cuda,但是从在线文档看起来好像X.cu应该被编译成Xo,所以拥有helloWorld.cu和helloWorld.cpp并不是一个好主意.在您允许的情况下,我将重命名"内核"helloKernel.cu,然后这应该工作:

NVCC = nvcc

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

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

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

(请注意,那些前导空格是制表符.)

如果可行,请尝试使用更光滑的版本:

NVCC = nvcc

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

%.o:
    $(NVCC) -c %< -o $@

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


fja*_*rri 4

以防万一,这是我的变体。我用它在 Mac 上编译 CUDA 项目,但我认为它也适合 Linux。它需要 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
Run Code Online (Sandbox Code Playgroud)