CXX ?= g++
NVCC ?= nvcc
CXXFLAGS ?= -O3 -std=c++17 -march=native -pthread -Wall -Wextra -Wpedantic
NVCCFLAGS ?= -O3 -std=c++17 -arch=sm_86
RESEARCH_HEADERS = ../research/slime_solver_core.hpp ../include/slime/solver_core.hpp

.PHONY: all test test-cpu benchmark clean
all: bin/01_cpu bin/cuda_steps bin/07_residue bin/08_seed_cpu bin/08_seed_cuda bin/08_upper_compare bin/seed_brute_cpu bin/seed_brute_cuda

bin:
	mkdir -p bin
bin/01_cpu: 01_cpu.cpp common.hpp | bin
	$(CXX) $(CXXFLAGS) $< -o $@
bin/cuda_steps: cuda_steps.cu common.hpp 02_cuda_seed.cuh 03_cuda_position.cuh 04_cuda_outer_sum.cuh | bin
	$(NVCC) $(NVCCFLAGS) $< -o $@
bin/08_upper_compare: 08_upper_compare.cu common.hpp $(RESEARCH_HEADERS) | bin
	$(NVCC) $(NVCCFLAGS) $< -o $@
bin/07_residue: 07_residue.cu $(RESEARCH_HEADERS) | bin
	$(NVCC) $(NVCCFLAGS) -I../research $< -o $@
bin/08_seed_cpu: 08_seed_cpu.cpp $(RESEARCH_HEADERS) | bin
	$(CXX) $(CXXFLAGS) -I../research $< -o $@
bin/08_seed_cuda: 08_seed_cuda.cu $(RESEARCH_HEADERS) | bin
	$(NVCC) $(NVCCFLAGS) -I../research $< -o $@
bin/seed_brute_cpu: ../research/slime_bruteforce_cpp_bench.cpp $(RESEARCH_HEADERS) | bin
	$(CXX) $(CXXFLAGS) -I../research $< -o $@
bin/seed_brute_cuda: ../research/slime_bruteforce_cuda_bench.cu $(RESEARCH_HEADERS) | bin
	$(NVCC) $(NVCCFLAGS) -I../research $< -o $@
test-cpu: bin/01_cpu
	python3 test_steps.py
test: all
	python3 test_steps.py --gpu
benchmark: all
	python3 benchmark.py
clean:
	rm -rf bin
