#!/usr/bin/env bash # CPU emulation of the CUDA harness, for checking a pack on a machine WITHOUT nvcc (any clang++ or g++). # It compiles host.cu and packs//kernel.cu as plain C++17 against the shim cuda_runtime.h in this # directory, runs the kernels on host threads (32 threads per warp, a barrier inside __shfl_xor_sync) # and checks the dataset self-test and the vectors. Rates it prints are meaningless; only PASS/FAIL matters. # Usage: emu/emu.sh [host args...] e.g. emu/emu.sh igneum-genesis --batch-log2 13 --batches 1 --block-warps 2 set -euo pipefail HERE="$(cd "$(dirname "$0")" && pwd)" CUDA_DIR="$(cd "$HERE/.." && pwd)" PACK="${1:-igneum-genesis}"; shift || true BUILD="$HERE/build-$PACK" mkdir -p "$BUILD" cp "$CUDA_DIR/host.cu" "$BUILD/host_emu.cpp" # Rewrite only the launch syntax; everything else is the exact generated text. sed -E 's/([A-Za-z_0-9]+)<<<([^,]+), ([^>]+)>>>\(/emu_launch(\1, \2, \3, /' "$CUDA_DIR/packs/$PACK/kernel.cu" > "$BUILD/kernel_emu.cpp" CXX="${CXX:-c++}" "$CXX" -std=c++17 -O2 -Wall -Wextra -I "$HERE" -I "$CUDA_DIR/packs/$PACK" \ -o "$BUILD/igneum-emu" "$BUILD/host_emu.cpp" "$BUILD/kernel_emu.cpp" "$HERE/shim.cpp" -pthread echo "compiled $BUILD/igneum-emu (CPU emulation, not a GPU build)" exec "$BUILD/igneum-emu" "$@"