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

前端 未结 4 1929
天命终不由人
天命终不由人 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 12:55

    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 $<
    

提交回复
热议问题