1# Native SHTNS benchmarks, to compare against the WGSL transforms in ../../src/sht.
2#
3# ./bootstrap.sh # fetch and build upstream SHTNS, write shtns.mk
4# make # shtbench, plus shtbench_gpu if SHTNS has CUDA support
5#
6# -ffast-math is deliberately NOT used: the fp32 GPU run is compared element by
7# element against the WebGPU one, and reassociation would make that a comparison
8# of two different computations. -O3 without it is what SHTNS' own codelets use.
10-include shtns.mk
12ifeq ($(SHTNS_LIB),)
13$(error run ./bootstrap.sh first — it fetches SHTNS and writes shtns.mk)
14endif
16CXX ?= g++
17NVCC ?= nvcc
18# Compile for the GPUs in this machine, which is both the fastest build and the
19# right answer for a benchmark that only ever runs here. Needs CUDA 11.5+; on an
20# older toolkit, or to build elsewhere and run here, say
21# `make NVCC_ARCH=-arch=sm_80`.
22NVCC_ARCH ?= -arch=native
24CXXFLAGS ?= -O3 -march=native -std=c++14 -fopenmp -Wall -Wextra -Wno-unused-parameter
25NVCCFLAGS ?= -O3 -std=c++14 -lineinfo
26INCLUDES = -I$(SHTNS_DIR)
27LDLIBS = $(SHTNS_LIB) $(SHTNS_LDLIBS)
29TARGETS = shtbench
30ifeq ($(SHTNS_HAS_GPU),1)
31TARGETS += shtbench_gpu
32endif
34all: $(TARGETS)
35 @echo
36 @echo "built: $(TARGETS)"
37ifeq ($(SHTNS_HAS_GPU),1)
38 @echo "SHTNS GPU Fourier stage: $(SHTNS_GPU_FFT)$(if $(filter cufft,$(SHTNS_GPU_FFT)), — theta-contiguous only; --layout phi needs VkFFT,)"
39else
40 @echo "note: SHTNS was built without GPU support, so there is no shtbench_gpu."
41 @echo " Re-run ./bootstrap.sh on a machine with nvcc to get it."
42endif
44shtbench: shtbench.cpp spec.h
45 $(CXX) $(CXXFLAGS) $(INCLUDES) $< -o $@ $(LDLIBS)
47# nvcc drives the link so the CUDA runtime and the C++ standard library (which
48# SHTNS' .cu objects need) come along without naming them by hand.
49shtbench_gpu: shtbench_gpu.cu spec.h
50 $(NVCC) $(NVCCFLAGS) $(NVCC_ARCH) $(INCLUDES) $< -o $@ \
51 -Xcompiler -fopenmp $(LDLIBS)
53clean:
54 rm -f shtbench shtbench_gpu
56# Also throws away the SHTNS checkout and shtns.mk; ./bootstrap.sh rebuilds them.
57distclean: clean
58 rm -rf $(SHTNS_DIR) shtns.mk