Files
Pavlo RatushnyiandClaude Sonnet 5.5 f334b66215 test(cuda-driver): teach the fake libcuda the eagerly-resolved cuMemsetD8_v2
Driver::load resolves cuMemsetD8_v2 (the `zero` entry point) up front, but the
synthetic mock_cuda.c (also #included by the q5/q6/projection-family mocks)
never defined it, so every isolated CPU ELF gate died in Driver::load with
MissingSymbol("cuMemsetD8_v2") before reaching its protocol assertions. Add a
load-only stub (same policy as the existing cuMemcpyDtoD_v2 stub) and an opt-in
`run.sh --mocks` mode that builds the fake libraries and runs the mock_driver,
q5_mock and q6_mock matrices in the Linux container.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-14 16:43:29 +02:00

37 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Runs INSIDE the linux-tests container (see run.sh --mocks). CPU-only: builds the
# repo's synthetic fake libcuda.so.1 ELFs and runs the #[ignore]d "isolated CPU ELF
# protocol" matrices that exercise the real Driver::load / FFI paths against them.
# This is the only way the dlopen/dlsym/context-stack code runs without a GPU.
set -euo pipefail
root=/src
cd "$root"
work="$(mktemp -d /tmp/leleka-mock.XXXXXX)"
trap 'rm -rf "$work"' EXIT
[[ ! -e /dev/nvidia0 ]] || { echo "GPU device present; refusing mock gate" >&2; exit 1; }
! ldconfig -p | grep -q 'libcuda\.so' || { echo "real libcuda installed; refusing" >&2; exit 1; }
cflags=(-std=c11 -Wall -Wextra -Werror -Wno-misleading-indentation -ffp-contract=off -fno-fast-math -shared -fPIC)
t="$root/crates/cuda-driver/tests"; src="$root/crates/cuda-driver/src"
mkdir -p "$work"/{complete,missing,q5,q6}
cc "${cflags[@]}" "$t/mock_cuda.c" -o "$work/complete/libcuda.so.1"
cc "${cflags[@]}" -DMOCK_MISSING_DTOH "$t/mock_cuda.c" -o "$work/missing/libcuda.so.1"
for symbol in cuInit cuDriverGetVersion cuDeviceGet cuCtxCreate_v2 cuCtxDestroy_v2 \
cuCtxPushCurrent_v2 cuCtxPopCurrent_v2 cuCtxSynchronize cuMemAlloc_v2 cuMemFree_v2 cuMemcpyHtoD_v2 cuModuleLoadData cuModuleGetFunction cuModuleUnload cuLaunchKernel; do
mkdir "$work/missing_$symbol"
cc "${cflags[@]}" "-D${symbol}=mock_replaced_${symbol}" "$t/mock_cuda.c" -o "$work/missing_$symbol/libcuda.so.1"
done
cc "${cflags[@]}" "$t/q5_mock_cuda.c" -lm -o "$work/q5/libcuda.so.1"
cc "${cflags[@]}" "$t/q6_mock_cuda.c" -lm -o "$work/q6/libcuda.so.1"
cargo_test=(cargo test --locked -p leleka-cuda-driver --features cuda-driver)
rc=0
step() { echo "=== mock gate: $1"; shift; "$@" || { echo "!!! FAILED: $*" >&2; rc=1; }; }
export LELEKA_CUDA_MOCK_HARNESS=1
step mock_driver env MOCK_CUDA_ADD_PTX="$src/vector_add.ptx" MOCK_CUDA_MATVEC_PTX="$src/matvec.ptx" \
LELEKA_CUDA_MOCK_ROOT="$work" "${cargo_test[@]}" --test mock_driver -- --exact isolated_cpu_elf_matrix --ignored --test-threads=1
step q5_mock env MOCK_CUDA_Q5_PTX="$src/q5_k_q8_1.ptx" LELEKA_CUDA_Q5_MOCK_ROOT="$work" \
"${cargo_test[@]}" --test q5_mock -- --exact isolated_q5_protocol_matrix --ignored --test-threads=1
step q6_mock env MOCK_CUDA_Q5_PTX="$src/q5_k_q8_1.ptx" MOCK_CUDA_Q6_PTX="$src/q6_k_q8_1.ptx" LELEKA_CUDA_Q6_MOCK_ROOT="$work" \
"${cargo_test[@]}" --test q6_mock -- --exact isolated_q6_protocol_matrix --ignored --test-threads=1
exit $rc