# shake256-fanout — Makefile.
#
# Builds the reference cuda fan-out worker. Each lumbda tier (Python,
# C, asm) spawns this binary via its existing process-spawn primitive
# & talks to it through input + output portal files. No tier links
# against libcudart directly — the CUDA toolchain dependency stays
# isolated to this directory.
#
# Build:
#   make all       — compile shake256-fanout (needs nvcc)
#   make test      — round-trip test (host + device produce identical
#                    SHAKE256 outputs over a small synthetic input set)
#   make bench     — bench device vs host throughput at N = 100k

NVCC      ?= nvcc
NVCCFLAGS ?= -O3 -arch=sm_86 -Xcompiler="-O3 -Wall -Wextra"
NVCC_PATH ?= $(shell which nvcc 2>/dev/null || echo /usr/local/cuda/bin/nvcc)

all: shake256-fanout

shake256-fanout: shake256-fanout.cu
	$(NVCC) $(NVCCFLAGS) -o $@ $<

# round-trip: feed (cuda-shake-fanout (output-bytes 32) (inputs ...))
# through the binary, compare against an external SHAKE256 reference
# (Python hashlib.shake_256).
test: shake256-fanout test_roundtrip.py
	@printf '(cuda-shake-fanout\n  (output-bytes 32)\n  (inputs\n' > /tmp/cf-in.portal
	@printf '    "00"\n    "01"\n    "deadbeef"\n    "%s"\n' \
		"$$(python3 -c 'print("ab" * 100)')" >> /tmp/cf-in.portal
	@printf '))\n' >> /tmp/cf-in.portal
	./shake256-fanout /tmp/cf-in.portal /tmp/cf-out.portal
	python3 test_roundtrip.py /tmp/cf-in.portal /tmp/cf-out.portal

bench: shake256-fanout bench.py
	python3 bench.py ./shake256-fanout

clean:
	rm -f shake256-fanout /tmp/cf-in.portal /tmp/cf-out.portal
