-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
211 lines (172 loc) · 6.31 KB
/
Copy pathMakefile
File metadata and controls
211 lines (172 loc) · 6.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# Makefile -- Moa Monte Carlo neutron transport
#
# Build with MinGW GCC on Windows (Git Bash).
# No autoconf, no drama. Just make. The install rule drops a cmake package
# config beside the binary, for other people's builds to find.
CC = gcc
WARNS = -Wall -Wextra -Wpedantic -Wshadow -Wconversion \
-Wdouble-promotion -Wformat=2 -Wundef \
-Wstrict-prototypes -Wmissing-prototypes \
-Wno-sign-conversion
CFLAGS = -std=c99 $(WARNS) -O2 -I.
TFLAGS = -std=c99 $(WARNS) -O0 -g -I.
LDFLAGS = -lm
FC = gfortran
FFLAGS = -std=f2008 -Wall -Wextra -O2 -Jmod
# Kauri path. Override on the command line for a non-Windows build, e.g.
# a CI runner with the repo checked out elsewhere: make KAURI=../kauri
KAURI = C:/dev/kauri
CFLAGS += -I$(KAURI)
TFLAGS += -I$(KAURI)
# OpenMP (set OMP=1 to enable: make OMP=1)
OMP ?= 0
ifeq ($(OMP),1)
CFLAGS += -fopenmp
TFLAGS += -fopenmp
LDFLAGS += -fopenmp
endif
# GPU via Booth
# GPU=1 — AMD HSA backend (Linux/ROCm only, bc_runtime)
# GPU=NV — NVIDIA CUDA Driver API backend (Windows/Linux, nv_rt)
# GPU=CPU — Booth --cpu backend: the GPU kernel, run on the CPU, no
# card and no driver. The whole point is CI, where there is no
# GPU but there is still a k_eff that had better come back near 1
# after the kernel has been through the compiler.
GPU ?= 0
BCSRC = C:/dev/compilers/barracuda
# Booth's binary is kath. The source tree kept the old directory name.
BOOTH = $(BCSRC)/kath
ifeq ($(GPU),1)
CFLAGS += -DMOA_GPU -I$(BCSRC)/src/runtime
TFLAGS += -DMOA_GPU -I$(BCSRC)/src/runtime
GPU_OBJ = gpu/gp_host.o gpu/bc_runtime.o gpu/bc_abend.o
LDFLAGS += -ldl
endif
ifeq ($(GPU),NV)
CFLAGS += -DMOA_GPU -DMOA_GPU_NV -I$(BCSRC)/src/nvidia
TFLAGS += -DMOA_GPU -DMOA_GPU_NV -I$(BCSRC)/src/nvidia
GPU_OBJ = gpu/gp_nv.o gpu/nv_rt.o
endif
ifeq ($(GPU),CPU)
CFLAGS += -DMOA_GPU -DMOA_GPU_CPU
TFLAGS += -DMOA_GPU -DMOA_GPU_CPU
GPU_OBJ = gpu/gp_cpu.o gpu/tp_kern.o
# tp_kern.o lands position-dependent out of Booth, so the executable
# goes non-PIE rather than fighting the linker about it.
LDFLAGS += -no-pie
endif
# Sources
SRC = src/rng.c src/nd_parse.c src/nd_xs.c src/nd_res.c src/nd_rmat.c \
src/nd_urr.c src/nd_dopl.c src/nd_thrm.c src/nd_sab.c \
src/csg.c src/cg_lat.c \
src/tl_score.c src/tl_ebin.c src/tl_mesh.c \
src/tp_loop.c src/tp_crit.c src/tp_fixd.c src/io_input.c
FSRC = src/dm_dpa.f90
MAIN_SRC = src/main.c
TEST_SRC = tests/tmain.c tests/trng.c tests/tparse.c tests/txs.c \
tests/tgeom.c tests/ttrans.c tests/tnew.c tests/tdpa.c
# Objects (release)
OBJ = $(SRC:.c=.o)
FOBJ = $(FSRC:.f90=.o)
MAIN_OBJ = $(MAIN_SRC:.c=.o)
# Objects (test — built in tests/obj/ to avoid clobbering release .o)
TEST_SOBJ = $(patsubst src/%.c, tests/obj/%.o, $(SRC))
TEST_TOBJ = $(patsubst tests/%.c, tests/obj/%.o, $(TEST_SRC))
# Targets
BIN = moa.exe
TEST_BIN = moa_test.exe
# Install layout. The cmake package config goes in so that find_package(Moa)
# works for anyone wanting to run decks as part of their own build.
PREFIX ?= /usr/local
BINDIR = $(DESTDIR)$(PREFIX)/bin
SHAREDIR = $(DESTDIR)$(PREFIX)/share/moa
CMAKEDIR = $(DESTDIR)$(PREFIX)/lib/cmake/Moa
VER_MAJOR := $(shell awk '$$2 == "MO_VER_MAJOR" {print $$3}' moa.h)
VER_MINOR := $(shell awk '$$2 == "MO_VER_MINOR" {print $$3}' moa.h)
VER_PATCH := $(shell awk '$$2 == "MO_VER_PATCH" {print $$3}' moa.h)
VERSION := $(VER_MAJOR).$(VER_MINOR).$(VER_PATCH)
VSED = sed -e 's/@MOA_VERSION@/$(VERSION)/g' \
-e 's/@MOA_VERSION_MAJOR@/$(VER_MAJOR)/g' \
-e 's/@MOA_VERSION_MINOR@/$(VER_MINOR)/g'
.PHONY: all test install uninstall version clean
all: $(BIN)
ifneq ($(GPU_OBJ),)
$(BIN): $(OBJ) $(FOBJ) $(MAIN_OBJ) $(GPU_OBJ)
$(FC) -o $@ $^ $(LDFLAGS)
else
$(BIN): $(OBJ) $(FOBJ) $(MAIN_OBJ)
$(FC) -o $@ $^ $(LDFLAGS)
endif
tests/obj:
mkdir -p tests/obj
# Test objects: src/*.c compiled with TFLAGS (no optimisation, debug)
tests/obj/%.o: src/%.c moa.h | tests/obj
$(CC) $(TFLAGS) -c -o $@ $<
# Test objects: tests/*.c compiled with TFLAGS
tests/obj/%.o: tests/%.c moa.h tests/tharns.h | tests/obj
$(CC) $(TFLAGS) -c -o $@ $<
$(TEST_BIN): $(TEST_SOBJ) $(TEST_TOBJ) $(FOBJ)
$(FC) -o $@ $^ $(LDFLAGS)
test: $(TEST_BIN)
./$(TEST_BIN)
# Compile rules (release)
src/%.o: src/%.c moa.h
$(CC) $(CFLAGS) -c -o $@ $<
mod:
mkdir -p mod
src/%.o: src/%.f90 | mod
$(FC) $(FFLAGS) -c -o $@ $<
# GPU compile rules (GPU=1 only)
ifeq ($(GPU),1)
gpu/gp_host.o: gpu/gp_host.c gpu/gp_host.h moa.h
$(CC) $(CFLAGS) -c -o $@ $<
gpu/bc_runtime.o: $(BCSRC)/src/runtime/bc_runtime.c $(BCSRC)/src/runtime/bc_runtime.h
$(CC) $(CFLAGS) -Wno-switch-enum -c -o $@ $<
gpu/bc_abend.o: $(BCSRC)/src/runtime/bc_abend.c $(BCSRC)/src/runtime/bc_abend.h
$(CC) $(CFLAGS) -c -o $@ $<
gpu/tp_kern.hsaco: gpu/tp_kern.cu
$(BOOTH) --amdgpu-bin $< -o $@
.PHONY: gpu
gpu: gpu/tp_kern.hsaco
endif
# GPU compile rules (GPU=NV only)
ifeq ($(GPU),NV)
gpu/gp_nv.o: gpu/gp_nv.c gpu/gp_nv.h moa.h
$(CC) $(CFLAGS) -c -o $@ $<
gpu/nv_rt.o: $(BCSRC)/src/nvidia/nv_rt.c $(BCSRC)/src/nvidia/nv_rt.h
$(CC) $(CFLAGS) -c -o $@ $<
gpu/tp_kern.ptx: gpu/tp_kern.cu
$(BOOTH) --nvidia-ptx $< -o $@
.PHONY: gpu
gpu: gpu/tp_kern.ptx
endif
# GPU compile rules (GPU=CPU only)
ifeq ($(GPU),CPU)
gpu/gp_cpu.o: gpu/gp_cpu.c gpu/gp_host.h moa.h
$(CC) $(CFLAGS) -c -o $@ $<
# The kernel itself, run through Booth's CPU backend into a plain
# x86-64 object with gp_kern in it. This is the line the whole guard hangs
# on: if the compiler ever stops turning the kernel into honest code, this
# is where it shows.
gpu/tp_kern.o: gpu/tp_kern.cu
$(BOOTH) --cpu $< -o $@
.PHONY: gpu
gpu: gpu/tp_kern.o
endif
version:
@echo $(VERSION)
# The decks go in beside the binary, but the ENDF data does not: it is
# user-supplied and a good deal larger than everything else here combined.
install: $(BIN)
install -d $(BINDIR) $(SHAREDIR)/bench $(CMAKEDIR)
install -m 755 $(BIN) $(BINDIR)/moa
install -m 644 bench/*.inp $(SHAREDIR)/bench/
install -m 644 cmake/MoaRun.cmake $(CMAKEDIR)/MoaRun.cmake
$(VSED) cmake/MoaConfig.cmake.in > $(CMAKEDIR)/MoaConfig.cmake
$(VSED) cmake/MoaConfigVersion.cmake.in > $(CMAKEDIR)/MoaConfigVersion.cmake
uninstall:
rm -f $(BINDIR)/moa
rm -rf $(SHAREDIR) $(CMAKEDIR)
clean:
rm -f src/*.o $(BIN) $(TEST_BIN) gpu/*.o gpu/*.hsaco gpu/*.ptx
rm -rf tests/obj mod