diff --git a/.github/workflows/port.yml b/.github/workflows/port.yml index 2215187a..df610cae 100644 --- a/.github/workflows/port.yml +++ b/.github/workflows/port.yml @@ -105,3 +105,6 @@ jobs: - name: Linux test harness if: steps.present.outputs.present == 'true' run: scripts/linux-tests/run.sh + - name: Fake-libcuda mock gates (CPU-only ELF protocol tests of the driver) + if: steps.present.outputs.present == 'true' + run: scripts/linux-tests/run.sh --mocks diff --git a/crates/cuda-driver/tests/mock_cuda.c b/crates/cuda-driver/tests/mock_cuda.c index 71895667..63b7eb4e 100644 --- a/crates/cuda-driver/tests/mock_cuda.c +++ b/crates/cuda-driver/tests/mock_cuda.c @@ -169,6 +169,13 @@ CUresult cuMemsetD8_v2(CUdeviceptr destination,unsigned char value,size_t bytes) return 1; } +/* Driver::load now resolves cuStreamSynchronize eagerly (the stream wait of the chained launches). Same load-only policy as above: + the synthetic harness never creates a stream. */ +CUresult cuStreamSynchronize(void *stream) { + (void)stream; + return 1; +} + /* Independent fixed vector ABI fixture. Arithmetic here is a CPU reference; it neither interprets nor executes PTX. */ static int exact_image(const char *ptx,int matvec) { diff --git a/crates/model-format/src/huge_pages.rs b/crates/model-format/src/huge_pages.rs index 5e323944..3e1c8e05 100644 --- a/crates/model-format/src/huge_pages.rs +++ b/crates/model-format/src/huge_pages.rs @@ -273,11 +273,14 @@ mod linux { let t = std::time::Instant::now(); let ranges: Vec<(usize, usize)> = LIVE.lock().unwrap_or_else(|p| p.into_inner()).iter().filter(|e| !e.2).map(|e| (e.0, e.1 & !(HUGE - 1))).collect(); + // linux/mman-common.h MADV_COLLAPSE = 25 (6.1+). Spelled out because libc 0.2.190 does not define it for the musl targets + // (the static CLI build failed to compile); glibc's libc::MADV_COLLAPSE has the same value. + const MADV_COLLAPSE: libc::c_int = 25; let mut failed = 0usize; let mut last_error = 0i32; for (base, len) in ranges.into_iter().filter(|r| r.1 > 0) { // SAFETY: advice over a live mapping of ours; MADV_COLLAPSE copies pages into a huge page without changing contents. - if unsafe { libc::madvise(base as *mut libc::c_void, len, libc::MADV_COLLAPSE) } != 0 { + if unsafe { libc::madvise(base as *mut libc::c_void, len, MADV_COLLAPSE) } != 0 { failed += 1; last_error = std::io::Error::last_os_error().raw_os_error().unwrap_or(0); } diff --git a/deploy/Dockerfile.static-cli b/deploy/Dockerfile.static-cli index 87a766bf..191c3716 100644 --- a/deploy/Dockerfile.static-cli +++ b/deploy/Dockerfile.static-cli @@ -4,11 +4,12 @@ ARG RUST_TARGET=x86_64-unknown-linux-musl RUN apt-get update \ && apt-get install -y --no-install-recommends musl-tools cmake \ && rm -rf /var/lib/apt/lists/* -RUN rustup target add "${RUST_TARGET}" - WORKDIR /src ENV CARGO_TARGET_DIR=/src/control-plane/target COPY Cargo.toml Cargo.lock rust-toolchain.toml ./ +# After the toolchain file is in place: the floating rust:1.99 tag can carry a newer patch than the pinned 1.99.0, and the target must be +# installed for the toolchain rustup actually selects (adding it before made the build fail with "can't find crate for `core`"). +RUN rustup target add "${RUST_TARGET}" COPY crates/ ./crates/ COPY manifests/ ./manifests/ COPY desktop-core/ ./desktop-core/ diff --git a/scripts/check-local.sh b/scripts/check-local.sh index 5296abdf..3db5b696 100755 --- a/scripts/check-local.sh +++ b/scripts/check-local.sh @@ -210,7 +210,10 @@ if [[ "${host_os}" == Linux ]]; then debt cargo clippy --manifest-path "${repo_root}/Cargo.toml" --locked -p leleka-cuda-driver --all-targets --all-features -- -D warnings # the crate does not compile without its `cuda-driver` feature (lib.rs gates only part of the modules); leleka-runtime always enables it cargo test --manifest-path "${repo_root}/Cargo.toml" --locked -p leleka-cuda-driver --features cuda-driver - "${repo_root}/scripts/test-cuda-driver-bootstrap.sh" + # Stale since leleka-cuda-driver gained path dependencies (leleka-context, -model-format, -experimental-ref): the script builds a + # synthetic workspace of the crate alone (cargo metadata fails) and also runs `cargo fmt --check` / Clippy `-D warnings` on it, which + # carry the debt of finding 9 in docs/ci-audit.md. scripts/linux-tests/run.sh --mocks runs the same mock-ELF gates on the real tree. + debt "${repo_root}/scripts/test-cuda-driver-bootstrap.sh" else echo "== Linux-only crate tests skipped on ${host_os}" fi @@ -220,7 +223,8 @@ if command -v clang++ >/dev/null 2>&1; then if [ "$(uname -s)" = Darwin ]; then python3 "${repo_root}/scripts/cuda-stubs/check-cu.py" else - python3 "${repo_root}/scripts/cuda-stubs/check-cu.py" || echo "warning: cuda stub syntax check failed (advisory off macOS)" >&2 + # glibc/libstdc++ hosts: clang's CUDA frontend needs macOS-only stub overloads, so the C++-only pass (--plain) is the advisory check here + python3 "${repo_root}/scripts/cuda-stubs/check-cu.py" --plain || echo "warning: cuda stub syntax check failed (advisory off macOS)" >&2 fi fi cargo fmt --manifest-path "${repo_root}/control-plane/Cargo.toml" --check diff --git a/scripts/cuda-stubs/check-cu.py b/scripts/cuda-stubs/check-cu.py index f00e40b6..ddc40d30 100755 --- a/scripts/cuda-stubs/check-cu.py +++ b/scripts/cuda-stubs/check-cu.py @@ -17,6 +17,7 @@ SRC = os.path.join(ROOT, 'crates', 'cuda-driver', 'src') INCLUDES = [ STUBS, os.path.join(ROOT, 'engine', 'strata', 'include'), + os.path.join(ROOT, 'engine', 'strata', 'src', 'kernels', 'cuda'), # sm120_iq_prefix.cuh includes "s26_tsum.cuh" from the Original os.path.join(ROOT, 'engine', 'strata', 'third_party', 'ggml'), os.path.join(SRC, 'third_party', 'llamacpp', 'ggml-cuda'), os.path.join(SRC, 'third_party', 'llamacpp', 'ggml-include'), diff --git a/scripts/cuda-stubs/cuda_stub.h b/scripts/cuda-stubs/cuda_stub.h index 8e166c68..7840874d 100644 --- a/scripts/cuda-stubs/cuda_stub.h +++ b/scripts/cuda-stubs/cuda_stub.h @@ -241,22 +241,48 @@ static inline double min(double a, float b) { return fmin(a, (double) b); } static inline double max(float a, double b) { return fmax((double) a, b); } static inline double max(double a, float b) { return fmax(a, (double) b); } +#ifndef __GLIBC__ // glibc (with libstdc++/_GNU_SOURCE) already declares this name; the stub would clash with it static inline int __isnanf(float x) { return std::isnan(x); } +#endif +#ifndef __GLIBC__ // glibc (with libstdc++/_GNU_SOURCE) already declares this name; the stub would clash with it static inline int __isinff(float x) { return std::isinf(x); } +#endif +#ifndef __GLIBC__ // glibc (with libstdc++/_GNU_SOURCE) already declares this name; the stub would clash with it static inline int __finitef(float x) { return std::isfinite(x); } +#endif static inline float rsqrtf(float x) { return 1.0f / sqrtf(x); } static inline double rsqrt(double x) { return 1.0 / sqrt(x); } static inline float rcbrtf(float x) { return 1.0f / cbrtf(x); } +#ifndef __GLIBC__ // glibc (with libstdc++/_GNU_SOURCE) already declares this name; the stub would clash with it static inline float exp10f(float x) { return powf(10.0f, x); } +#endif +#ifndef __GLIBC__ // glibc (with libstdc++/_GNU_SOURCE) already declares this name; the stub would clash with it static inline void sincosf(float x, float* s, float* c) { *s = sinf(x); *c = cosf(x); } +#endif +#ifndef __GLIBC__ // glibc (with libstdc++/_GNU_SOURCE) already declares this name; the stub would clash with it static inline float __expf(float x) { return expf(x); } +#endif +#ifndef __GLIBC__ // glibc (with libstdc++/_GNU_SOURCE) already declares this name; the stub would clash with it static inline float __logf(float x) { return logf(x); } +#endif +#ifndef __GLIBC__ // glibc (with libstdc++/_GNU_SOURCE) already declares this name; the stub would clash with it static inline float __log2f(float x) { return log2f(x); } +#endif +#ifndef __GLIBC__ // glibc (with libstdc++/_GNU_SOURCE) already declares this name; the stub would clash with it static inline float __log10f(float x) { return log10f(x); } +#endif +#ifndef __GLIBC__ // glibc (with libstdc++/_GNU_SOURCE) already declares this name; the stub would clash with it static inline float __sinf(float x) { return sinf(x); } +#endif +#ifndef __GLIBC__ // glibc (with libstdc++/_GNU_SOURCE) already declares this name; the stub would clash with it static inline float __cosf(float x) { return cosf(x); } +#endif +#ifndef __GLIBC__ // glibc (with libstdc++/_GNU_SOURCE) already declares this name; the stub would clash with it static inline float __tanf(float x) { return tanf(x); } +#endif +#ifndef __GLIBC__ // glibc (with libstdc++/_GNU_SOURCE) already declares this name; the stub would clash with it static inline float __powf(float x, float y) { return powf(x, y); } +#endif static inline float __fdividef(float x, float y) { return x / y; } static inline double __ddiv_rn(double x, double y) { return x / y; } static inline float __saturatef(float x) { return x < 0.f ? 0.f : (x > 1.f ? 1.f : x); } diff --git a/scripts/test-cuda-fixed-ptx.sh b/scripts/test-cuda-fixed-ptx.sh index e694e04a..81e20bee 100755 --- a/scripts/test-cuda-fixed-ptx.sh +++ b/scripts/test-cuda-fixed-ptx.sh @@ -20,21 +20,21 @@ import hashlib, json, pathlib, re, sys, tarfile, urllib.request root, work = map(pathlib.Path, sys.argv[1:]) lock = json.loads((root/'deploy/cuda-toolkit.lock.json').read_text()) component = next(row for row in lock['components'] if row['component'] == 'cuda_nvcc') -expected = '48e35be3cfbf4b4fbc16828eaec8a7048ee789403049dc409f7b643d6259cf7a' -assert component['version']=='13.0.88' and component['sha256']==expected -assert component['relative_path']=='cuda_nvcc/linux-x86_64/cuda_nvcc-linux-x86_64-13.0.88-archive.tar.xz' -assert int(component['size'])==26657716 +expected = 'b04e5ca5b41f8b5629ce5f16930920e6af437f32c9777fcb67e0361f732b6f43' +assert component['version']=='13.2.86' and component['sha256']==expected +assert component['relative_path']=='cuda_nvcc/linux-x86_64/cuda_nvcc-linux-x86_64-13.2.86-archive.tar.xz' +assert int(component['size'])==31085360 manifest_url=lock['manifest_url'] with urllib.request.urlopen(manifest_url,timeout=60) as response: manifest=response.read(1_000_000) assert hashlib.sha256(manifest).hexdigest()==lock['manifest_sha256'] entry=json.loads(manifest)['cuda_nvdisasm'];row=entry['linux-x86_64'] -expected_disasm='0541e0230f724a43d67288ef882c63351d0c302bf567591b7620d40f93c2c93c' -assert entry['version']=='13.0.85' and row['sha256']==expected_disasm -assert row['relative_path']=='cuda_nvdisasm/linux-x86_64/cuda_nvdisasm-linux-x86_64-13.0.85-archive.tar.xz' -assert int(row['size'])==4129456 +expected_disasm='a920f95954b031c2437b0888e92e0d52f78ee84bf83ac47cfa9e28cb3de7a69c' +assert entry['version']=='13.2.86' and row['sha256']==expected_disasm +assert row['relative_path']=='cuda_nvdisasm/linux-x86_64/cuda_nvdisasm-linux-x86_64-13.2.86-archive.tar.xz' +assert int(row['size'])==4282328 print('Official manifest URL/SHA256:',manifest_url,lock['manifest_sha256']) -for name,part,size,digest in [('ptxas',component,26657716,expected),('nvdisasm',row,4129456,expected_disasm)]: +for name,part,size,digest in [('ptxas',component,31085360,expected),('nvdisasm',row,4282328,expected_disasm)]: url='https://developer.download.nvidia.com/compute/cuda/redist/'+part['relative_path'] with urllib.request.urlopen(url,timeout=60) as response:data=response.read(size+1) assert len(data)==size and hashlib.sha256(data).hexdigest()==digest