aien-yardsticks
aien-dev/aien-yardsticks
Brought by drakestapleton
aien-yardsticks / yardsticks / prime-drag-race-cuda / Makefile
| 1 | # Build the CUDA mirror yardstick (host compile only needs nvcc; running needs a quiet GPU). |
| 2 | # Usage: make OMEGA_DIR=/path/to/omega-checkout (needs bench/prime_race/prime_race_impl.{h,c}) |
| 3 | NVCC ?= /usr/local/cuda/bin/nvcc |
| 4 | ARCH ?= sm_121 |
| 5 | CC ?= cc |
| 6 | ifeq ($(OMEGA_DIR),) |
| 7 | $(error OMEGA_DIR is required, e.g. make OMEGA_DIR=$$HOME/workspace/omega) |
| 8 | endif |
| 9 | PRDIR := $(OMEGA_DIR)/bench/prime_race |
| 10 | OMEGA_COMMIT := $(shell git -C $(OMEGA_DIR) rev-parse HEAD) |
| 11 | OMEGA_DIRTY := $(shell git -C $(OMEGA_DIR) status --porcelain -- bench/prime_race | head -c1) |
| 12 | YARD_COMMIT := $(shell git -C $(CURDIR) rev-parse HEAD) |
| 13 | NVCC_VERSION := $(shell $(NVCC) --version | tail -n2 | tr '\n' ' ' | sed 's/ *$$//') |
| 14 | NVCC_FLAGS := -O3 -arch=$(ARCH) -Xcompiler -O3,-mcpu=native |
| 15 | CFLAGS_HOST := -O3 -mcpu=native -Wall -Wextra |
| 16 | |
| 17 | BUILD := build |
| 18 | all: $(BUILD)/prime-race-cuda-mirror |
| 19 | |
| 20 | $(BUILD)/build_info.h: FORCE | $(BUILD) |
| 21 | @printf '#define YS_NVCC_VERSION "%s"\n#define YS_NVCC_FLAGS "%s"\n#define YS_OMEGA_COMMIT "%s%s"\n#define YS_YARD_COMMIT "%s"\n' \ |
| 22 | "$(NVCC_VERSION)" "$(NVCC_FLAGS)" "$(OMEGA_COMMIT)" "$(if $(OMEGA_DIRTY),+dirty)" "$(YARD_COMMIT)" > $@.tmp |
| 23 | @cmp -s $@.tmp $@ && rm $@.tmp || mv $@.tmp $@ |
| 24 | |
| 25 | # build_info.h changes whenever a recorded commit changes, so the baked-in |
| 26 | # PR_SOURCE_COMMIT label can never go stale. |
| 27 | $(BUILD)/prime_race_impl.o: $(PRDIR)/prime_race_impl.c $(PRDIR)/prime_race_impl.h $(BUILD)/build_info.h | $(BUILD) |
| 28 | nice -n 19 $(CC) $(CFLAGS_HOST) -I$(PRDIR) \ |
| 29 | -DPR_SOURCE_COMMIT='"omega=$(OMEGA_COMMIT)$(if $(OMEGA_DIRTY),+dirty);yardsticks=$(YARD_COMMIT)"' \ |
| 30 | -DPR_CC='"$(CC) + nvcc"' -DPR_CFLAGS='"host: $(CFLAGS_HOST); nvcc: $(NVCC_FLAGS)"' -c $< -o $@ |
| 31 | |
| 32 | $(BUILD)/sieve_cuda.o: sieve_cuda.cu $(BUILD)/build_info.h | $(BUILD) |
| 33 | nice -n 19 $(NVCC) $(NVCC_FLAGS) -Xcompiler -Wall,-Wextra -I$(PRDIR) -I$(BUILD) -c $< -o $@ |
| 34 | |
| 35 | $(BUILD)/prime-race-cuda-mirror: $(BUILD)/sieve_cuda.o $(BUILD)/prime_race_impl.o |
| 36 | nice -n 19 $(NVCC) -arch=$(ARCH) $^ -o $@ |
| 37 | |
| 38 | $(BUILD): |
| 39 | mkdir -p $@ |
| 40 | |
| 41 | clean: |
| 42 | rm -rf $(BUILD) |
| 43 | |
| 44 | FORCE: |
| 45 | .PHONY: all clean FORCE |