# # sample Makefile for nvcc (CUDA compiler) with OpenCL (CUDA implementation) # # usage examples: # "make hello" to compile "hello.c" to "hello" # # note that you must first set up to include CUDA files # (command "module load cuda-latest") # # note also that nvcc (the CUDA compiler) seems to work better with .cpp # files than with .c files (even if the .cpp file is straight C) so # this makefile makes a temporary copy of source. OPT = -O3 CC = nvcc EXTRAS = # can be used to add additional user-specified options, e.g. -fopenmp #WNO_FLAGS=-Wno-long-long #IGNORE_HEADER_WARNINGS=-isystem $(CUDA_HOME)/include #IGNORE_WARN=$(IGNORE_HEADER_WARNINGS) $(WNO_FLAGS) CUDA_CFLAGS=-Xcompiler "$(CFLAGS) $(IGNORE_WARN)" CFLAGS=$(OPT) $(IGNORE_WARN) $(EXTRAS) OPENCL_LDFLAGS= -lOpenCL -L$(CUDA_HOME)/lib64 -L/usr/lib64/nvidia/ LDFLAGS = $(OPENCL_LDFLAGS) -lm %: %.c cp $< temp-$<.cpp $(CC) -o $@ -Xcompiler "$(CFLAGS)" temp-$<.cpp $(LDFLAGS) rm temp-$<.cpp %.o: %.c $(CC) -c -Xcompiler "$(CFLAGS)" $(LDFLAGS) $< $(LDFLAGS)