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

前端 未结 4 1976
天命终不由人
天命终不由人 2021-02-04 12:38

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
4条回答
  •  自闭症患者
    2021-02-04 13:16

    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 %< -o $@
    
    helloKernel.o: helloKernel.cu
        $(NVCC) -c %< -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 %< -o $@
    
    helloWorld: helloWorld.o helloKernel.o
        $(NVCC) %^ -o $@
    

提交回复
热议问题