From 087c2994269d493294d28c53170e703bfa39bd66 Mon Sep 17 00:00:00 2001 From: Alessandro Capotondi Date: Tue, 11 May 2021 00:14:33 +0200 Subject: [PATCH] HPC CUDA Lab x86 Makefile --- cuda/lab3/Makefile.x86 | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 cuda/lab3/Makefile.x86 diff --git a/cuda/lab3/Makefile.x86 b/cuda/lab3/Makefile.x86 new file mode 100755 index 0000000..d3179a4 --- /dev/null +++ b/cuda/lab3/Makefile.x86 @@ -0,0 +1,58 @@ +ifndef CUDA_HOME +CUDA_HOME:=/usr/local/cuda +endif + +ifndef EXERCISE +EXERCISE=exercise1.cu +endif + +BUILD_DIR ?= ./build + +NVCC=$(CUDA_HOME)/bin/nvcc +CXX=g++ + +OPT:=-O2 -g +NVOPT:=-Xcompiler -fopenmp -lineinfo --ptxas-options=-v --use_fast_math `pkg-config --cflags --libs opencv4` + +CXXFLAGS:=$(OPT) -I. $(EXT_CXXFLAGS) +LDFLAGS:=-lm -lcudart $(EXT_LDFLAGS) + +NVCFLAGS:=$(CXXFLAGS) $(NVOPT) +NVLDFLAGS:=$(LDFLAGS) -lgomp + +SRCS:= utils.c +OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) $(EXERCISE:%=$(BUILD_DIR)/%.o) +EXE=$(EXERCISE:.cu=.exe) + +$(EXE): $(OBJS) + $(MKDIR_P) $(dir $@) + $(NVCC) $(NVCFLAGS) $(OBJS) -o $@ $(NVLDFLAGS) + +$(BUILD_DIR)/%.cu.o: %.cu + $(MKDIR_P) $(dir $@) + $(NVCC) $(NVCFLAGS) -c $< -o $@ + +$(BUILD_DIR)/%.cpp.o: %.cpp + $(MKDIR_P) $(dir $@) + $(CXX) $(CXXFLAGS) -c $< -o $@ + +$(BUILD_DIR)/%.c.o: %.c + $(MKDIR_P) $(dir $@) + $(CXX) $(CXXFLAGS) -c $< -o $@ + +all: $(EXE) + +.PHONY: run profile clean +run: $(EXE) + ./$(EXE) + +profile: $(EXE) + sudo LD_LIBRARY_PATH=$(CUDA_HOME)/lib:/usr/ext/lib:${LD_LIBRARY_PATH} LIBRARY_PATH=/usr/ext/lib:${LIBRARY_PATH} nvprof --unified-memory-profiling off ./$(EXE) + +metrics: $(EXE) + sudo LD_LIBRARY_PATH=$(CUDA_HOME)/lib:/usr/ext/lib:${LD_LIBRARY_PATH} LIBRARY_PATH=/usr/ext/lib:${LIBRARY_PATH} nvprof --unified-memory-profiling off --print-gpu-trace --metrics "eligible_warps_per_cycle,achieved_occupancy,sm_efficiency,ipc" ./$(EXE) + +clean: + -rm -fr $(BUILD_DIR) *.exe *.out *~ + +MKDIR_P ?= mkdir -p