-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
200 lines (161 loc) · 8.63 KB
/
Copy pathMakefile
File metadata and controls
200 lines (161 loc) · 8.63 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
# Transparent Offload — top-level build.
#
# make build the runtime, the emulated backend, and the examples
# make check build, then run the test suite (no GPU, no root needed)
# make demo the headline A/B: same binary, with and without the runtime
# make gpu also build the CUDA backend (needs nvcc)
# make remote also build the remote-signer backend and its server
# make install install into $(PREFIX) (default /usr/local)
#
# Everything lands in build/. Nothing is written into the source tree.
VERSION := 0.1.0
PREFIX ?= /usr/local
DESTDIR ?=
BUILD ?= build
BIN := $(BUILD)/bin
LIB := $(BUILD)/lib
CC ?= cc
# CUDA discovery. The trap this avoids is real and cost the paper a day: a
# distribution `nvcc` is often years older than the CUDA runtime installed
# beside it, and quietly cannot target a recent GPU. Prefer the newest
# /usr/local/cuda-*/bin/nvcc, fall back to whatever is on PATH, and let the
# user override either way.
# sort -V, not make's lexicographic $(sort): with cuda-9 and cuda-12.8 both
# installed, a plain sort picks cuda-9.
#
# Recursively expanded (=, not :=) so these probes run only when a CUDA target
# or print-config actually needs them. A plain `make` on a machine with no GPU
# should not be shelling out to nvidia-smi.
NVCC_FOUND = $(shell ls -1 /usr/local/cuda-*/bin/nvcc 2>/dev/null | sort -V | tail -1)
NVCC ?= $(if $(NVCC_FOUND),$(NVCC_FOUND),nvcc)
# Ask the installed GPU what it is rather than guessing. sm_120 (Blackwell) is
# the fallback because that is what the paper measured on.
DETECTED_ARCH = $(shell nvidia-smi --query-gpu=compute_cap --format=csv,noheader 2>/dev/null \
| head -1 | tr -d '. ')
CUDA_ARCH ?= $(if $(DETECTED_ARCH),sm_$(DETECTED_ARCH),sm_120)
# -Wno-misleading-indentation: the runtime is written in a deliberately dense
# one-statement-per-line style that this warning flags on nearly every guard
# clause. Every other warning is on and the tree builds clean.
WARN := -Wall -Wextra -Wno-misleading-indentation
CFLAGS ?= -O2 -g
LDFLAGS ?=
# Flags the build cannot work without live here rather than in CFLAGS. A
# variable set on the command line (`make CFLAGS="-fsanitize=address"`, or a
# distro's packaging flags) overrides every assignment in the makefile,
# including `+=`, so -Iinclude in CFLAGS would silently vanish and the build
# would fail on a missing toffload/ header. Recipes use ALL_CFLAGS; CFLAGS
# stays the user's to replace.
ALL_CFLAGS = -fPIC $(WARN) -Iinclude -DTOFFLOAD_VERSION=\"$(VERSION)\" $(CFLAGS)
# OpenSSL and zlib back the emulated accelerator (real AES-CTR, real deflate)
# and the verifying client. pkg-config when available, plain -l otherwise.
PKGCONFIG ?= pkg-config
CRYPTO_CFLAGS := $(shell $(PKGCONFIG) --cflags libssl libcrypto zlib 2>/dev/null)
CRYPTO_LIBS := $(shell $(PKGCONFIG) --libs libssl libcrypto zlib 2>/dev/null || echo -lssl -lcrypto -lz)
RUNTIME_SRC := src/libtransparent.c src/detector.c src/config.c src/fw_fiber.c src/fw_switch.S
RUNTIME_LIB := $(LIB)/libtransparent.so
VERSCRIPT := src/transparent.map
EMULATED := $(LIB)/libaccel.so
REMOTE_LIB := $(LIB)/libaccel_remote.so
TLS_LIB := $(LIB)/libtlsoffload.so
CUDA_LIB := $(LIB)/libaccel_gpu.so
CUDA_HEAVY := $(LIB)/libaccel_gpu_heavy.so
SERVERS := conn_server infer_server hostile_server barrier_server echo_backend
CLIENTS := client bclient
SERVER_BINS := $(addprefix $(BIN)/,$(SERVERS))
CLIENT_BINS := $(addprefix $(BIN)/,$(CLIENTS))
TEST_BINS := $(BIN)/test_fiber $(BIN)/test_config
.PHONY: all core examples check test demo gpu remote tls install uninstall \
clean distclean help format print-config
all: core examples
core: $(RUNTIME_LIB) $(EMULATED)
examples: $(SERVER_BINS) $(CLIENT_BINS)
$(BIN) $(LIB):
@mkdir -p $@
# ---- the runtime -----------------------------------------------------------
# One translation unit set, linked with a version script so the interposed
# pthread_cond_* symbols carry the GLIBC_2.3.2 version the loader expects.
$(RUNTIME_LIB): $(RUNTIME_SRC) $(VERSCRIPT) include/toffload/*.h src/*.h | $(LIB)
$(CC) $(ALL_CFLAGS) -shared -Wl,--version-script=$(VERSCRIPT) \
$(RUNTIME_SRC) -ldl $(LDFLAGS) -o $@
# ---- accelerator backends --------------------------------------------------
$(EMULATED): backends/emulated/libaccel.c include/toffload/accel.h | $(LIB)
$(CC) $(ALL_CFLAGS) $(CRYPTO_CFLAGS) -shared $< $(CRYPTO_LIBS) -lpthread $(LDFLAGS) -o $@
$(REMOTE_LIB): backends/remote/libaccel_remote.c include/toffload/accel.h | $(LIB)
$(CC) $(ALL_CFLAGS) -shared $< $(LDFLAGS) -o $@
$(TLS_LIB): backends/tls/libtlsoffload.c | $(LIB)
$(CC) $(ALL_CFLAGS) -shared $< -ldl $(LDFLAGS) -o $@
$(BIN)/remote_hsm: backends/remote/remote_hsm.c | $(BIN)
$(CC) $(ALL_CFLAGS) $(CRYPTO_CFLAGS) $< $(CRYPTO_LIBS) -lpthread $(LDFLAGS) -o $@
remote: $(REMOTE_LIB) $(BIN)/remote_hsm
tls: $(TLS_LIB)
# CUDA is opt-in: most users have no GPU, and a missing nvcc must not break
# `make`. `make gpu` says explicitly that a device build is wanted.
gpu: $(CUDA_LIB) $(CUDA_HEAVY)
$(CUDA_LIB): backends/cuda/libaccel_gpu.cu backends/cuda/aes_dev.cuh | $(LIB)
$(NVCC) -O2 -arch=$(CUDA_ARCH) -Xcompiler -fPIC -Iinclude -shared $< -o $@
$(CUDA_HEAVY): backends/cuda/libaccel_gpu_heavy.cu | $(LIB)
$(NVCC) -O2 -arch=$(CUDA_ARCH) -Xcompiler -fPIC -Iinclude -shared $< -lcublas -o $@
# ---- example servers and clients -------------------------------------------
# Servers call accel_run()/accel_encrypt() and link the emulated backend. Under
# LD_PRELOAD the runtime interposes that call; without it they block, which is
# exactly the stock baseline the demo compares against.
$(BIN)/%: examples/servers/%.c $(EMULATED) | $(BIN)
$(CC) $(ALL_CFLAGS) $< -L$(LIB) -laccel -lpthread $(LDFLAGS) -o $@
$(BIN)/%: examples/clients/%.c | $(BIN)
$(CC) $(ALL_CFLAGS) $(CRYPTO_CFLAGS) $< $(CRYPTO_LIBS) -lpthread $(LDFLAGS) -o $@
# ---- tests -----------------------------------------------------------------
# Unit tests link the sources under test directly rather than the shared
# object: they exercise internals (the context switch, the knob table) that the
# runtime does not export.
$(BIN)/test_fiber: tests/test_fiber.c src/fw_fiber.c src/fw_switch.S include/toffload/fw_fiber.h | $(BIN)
$(CC) $(ALL_CFLAGS) tests/test_fiber.c src/fw_fiber.c src/fw_switch.S $(LDFLAGS) -o $@
$(BIN)/test_config: tests/test_config.c src/config.c src/config.h | $(BIN)
$(CC) $(ALL_CFLAGS) tests/test_config.c $(LDFLAGS) -o $@
check test: all $(TEST_BINS)
@TOFFLOAD_BUILD=$(abspath $(BUILD)) tests/run.sh
demo: all
@TOFFLOAD_BUILD=$(abspath $(BUILD)) bench/scripts/demo.sh
# ---- install ---------------------------------------------------------------
install: core
install -d $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include/toffload \
$(DESTDIR)$(PREFIX)/lib/pkgconfig
install -m 755 $(RUNTIME_LIB) $(EMULATED) $(DESTDIR)$(PREFIX)/lib/
install -m 644 include/toffload/*.h $(DESTDIR)$(PREFIX)/include/toffload/
@sed -e 's|@PREFIX@|$(PREFIX)|g' -e 's|@VERSION@|$(VERSION)|g' \
packaging/toffload.pc.in > $(BUILD)/toffload.pc
install -m 644 $(BUILD)/toffload.pc $(DESTDIR)$(PREFIX)/lib/pkgconfig/
@echo "installed toffload $(VERSION) into $(DESTDIR)$(PREFIX)"
uninstall:
rm -f $(DESTDIR)$(PREFIX)/lib/libtransparent.so \
$(DESTDIR)$(PREFIX)/lib/libaccel.so \
$(DESTDIR)$(PREFIX)/lib/pkgconfig/toffload.pc
rm -rf $(DESTDIR)$(PREFIX)/include/toffload
# ---- housekeeping ----------------------------------------------------------
clean:
rm -rf $(BUILD)
distclean: clean
find examples experiments -name '*.o' -delete 2>/dev/null || true
format:
@command -v clang-format >/dev/null || { echo "clang-format not installed"; exit 1; }
clang-format -i $$(git ls-files '*.c' '*.h' | grep -v '^examples/integrations/redis/redismodule.h$$')
print-config:
@echo "VERSION = $(VERSION)"
@echo "CC = $(CC)"
@echo "CFLAGS = $(CFLAGS)"
@echo "ALL_CFLAGS = $(ALL_CFLAGS)"
@echo "CRYPTO_LIBS= $(CRYPTO_LIBS)"
@echo "NVCC = $(NVCC) (arch $(CUDA_ARCH)$(if $(DETECTED_ARCH), detected, default))"
@echo "PREFIX = $(PREFIX)"
@echo "BUILD = $(BUILD)"
help:
@echo "Transparent Offload $(VERSION)"
@echo
@echo " make runtime + emulated backend + examples"
@echo " make check run the test suite (no GPU, no root)"
@echo " make demo headline A/B, same binary with and without the runtime"
@echo " make gpu CUDA backend (needs nvcc; CUDA_ARCH=$(CUDA_ARCH))"
@echo " make remote remote-signer backend + its server"
@echo " make install install into PREFIX=$(PREFIX)"
@echo " make clean remove build/"
@echo
@echo "Docs: docs/quickstart.md Knobs: docs/configuration.md"