From 360a2c4ec75ef33283cbcf0ec10dbed830cd0701 Mon Sep 17 00:00:00 2001 From: clsferguson <48876201+clsferguson@users.noreply.github.com> Date: Mon, 22 Sep 2025 14:56:43 -0600 Subject: [PATCH] fix(docker): patch CUDA 12.9 math headers for glibc 2.41 compatibility in Debian Trixie MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add runtime patching of CUDA math_functions.h to resolve compilation conflicts between CUDA 12.9 and glibc 2.41 used in Debian Trixie, enabling successful Sage Attention builds. Root Cause: CUDA 12.9 was compiled with older glibc and lacks noexcept(true) specifications for math functions (sinpi, cospi, sinpif, cospif) that glibc 2.41 requires, causing "exception specification is incompatible" compilation errors. Math Function Conflicts Fixed: - sinpi(double x): Add noexcept(true) specification - sinpif(float x): Add noexcept(true) specification - cospi(double x): Add noexcept(true) specification - cospif(float x): Add noexcept(true) specification Patch Implementation: - Use sed to modify /usr/local/cuda-12.9/include/crt/math_functions.h at build time - Add noexcept(true) to the four conflicting function declarations - Maintains compatibility with both CUDA 12.9 and glibc 2.41 This resolves the compilation errors: "error: exception specification is incompatible with that of previous function" GPU detection and system setup already working perfectly: - 5x RTX 3060 GPUs detected correctly ✅ - PyTorch CUDA compatibility confirmed ✅ - Triton 3.4.0 installation successful ✅ - RTX 30/40 optimization strategy selected ✅ With this fix, Sage Attention should compile successfully on Debian Trixie while maintaining the slim image approach and all current functionality. References: - NVIDIA Developer Forums: https://forums.developer.nvidia.com/t/323591 - Known issue with CUDA 12.9 + glibc 2.41 in multiple projects --- Dockerfile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Dockerfile b/Dockerfile index eccfd4d6c..4839dc946 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,6 +28,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ gnupg2 \ ca-certificates \ ninja-build \ + patch \ && echo "deb http://deb.debian.org/debian trixie main contrib non-free non-free-firmware" > /etc/apt/sources.list.d/non-free.list \ && wget https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/cuda-keyring_1.1-1_all.deb \ && dpkg -i cuda-keyring_1.1-1_all.deb \ @@ -44,6 +45,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && rm -rf /var/lib/apt/lists/* \ && rm cuda-keyring_1.1-1_all.deb +# Patch CUDA math_functions.h for glibc 2.41 compatibility +RUN sed -i 's/extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double sinpi(double x);/extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double sinpi(double x) noexcept (true);/' /usr/local/cuda-12.9/include/crt/math_functions.h && \ + sed -i 's/extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float sinpif(float x);/extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float sinpif(float x) noexcept (true);/' /usr/local/cuda-12.9/include/crt/math_functions.h && \ + sed -i 's/extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double cospi(double x);/extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double cospi(double x) noexcept (true);/' /usr/local/cuda-12.9/include/crt/math_functions.h && \ + sed -i 's/extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float cospif(float x);/extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float cospif(float x) noexcept (true);/' /usr/local/cuda-12.9/include/crt/math_functions.h + # Set CUDA paths for entrypoint compilation ENV CUDA_HOME=/usr/local/cuda-12.9 \ PATH=/usr/local/cuda-12.9/bin:${PATH} \