Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a makefile for CUDA programs

Tags:

makefile

nvcc

I want to automate the compilation of a toy library using CUDA and C++. Then I write a Makefile as follows

CC=g++
NVCC=nvcc
CXXFLAGS= -fopenmp -O3 -Wextra -std=c++11
CUDAFLAGS= -std=c++11 -c -arch=sm_20
LIBS= -lopenblas -lpthread -lcudart -lcublas
LIBDIRS=-L/usr/local/cuda-7.5/lib64
INCDIRS=-I/usr/local/cuda-7.5/include
matrix_cuda.o: marix_cuda.cu
     $(NVCC) $(CUDAFLAGS)   matrix_cuda.cu
all: matrix_cuda.o
        $(CC) -o test matrix_blas.cpp alg.cpp test.cpp matrix_cuda.o $(LIBDIRS) $(INCDIRS) $(LIBS) $(CXXFLAGS)
clean:
    rm -rf test *.o

Typing make I get

make: *** No rule to make target `marix_cuda.cu', needed by `matrix_cuda.o'.  Stop.

I never wrote a Makefile before. Where did I go wrong?

like image 280
pateheo Avatar asked Oct 20 '25 03:10

pateheo


2 Answers

I think you have a typo in the CUDA file name

matrix_cuda.o: marix_cuda.cu
     $(NVCC) $(CUDAFLAGS)   matrix_cuda.cu

IMHO it should be

matrix_cuda.o: matrix_cuda.cu
     $(NVCC) $(CUDAFLAGS)   matrix_cuda.cu
like image 77
Quicky Avatar answered Oct 22 '25 15:10

Quicky


This may take a couple of iterations.

1) First try this:

nvcc -std=c++11 -c -arch=sm_20 matrix_cuda.cu

If that works (and produces matrix_cuda.o, I presume), remove matrix_cuda.o and

2) try this makefile:

matrix_cuda.o: matrix_cuda.cu
    nvcc -std=c++11 -c -arch=sm_20 matrix_cuda.cu

If that works,

3) try this:

g++ -o test matrix_blas.cpp alg.cpp test.cpp matrix_cuda.o -L/usr/local/cuda-7.5/lib64 -I/usr/local/cuda-7.5/include -lopenblas -lpthread -lcudart -lcublas -fopenmp -O3 -Wextra -std=c++11

If that works, remove test and

4) try this makefile:

test: matrix_cuda.o
    g++ -o test matrix_blas.cpp alg.cpp test.cpp matrix_cuda.o -L/usr/local/cuda-7.5/lib64 -I/usr/local/cuda-7.5/include -lopenblas -lpthread -lcudart -lcublas -fopenmp -O3 -Wextra -std=c++11

matrix_cuda.o: matrix_cuda.cu
    nvcc -std=c++11 -c -arch=sm_20 matrix_cuda.cu

If that works, remove test and matrix_cuda.o and

5) try that makefile again.

If that works, there are further refinements we can make.

like image 30
Beta Avatar answered Oct 22 '25 15:10

Beta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!