From 71ee33f62cd467166281d07cdeec65afa6408412 Mon Sep 17 00:00:00 2001 From: Aroun Demeure Date: Sun, 24 Aug 2025 10:17:07 +0100 Subject: [PATCH] Fix for CUDA 13 --- llmc/cuda_utils.cuh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/llmc/cuda_utils.cuh b/llmc/cuda_utils.cuh index 030ec07..976ec94 100644 --- a/llmc/cuda_utils.cuh +++ b/llmc/cuda_utils.cuh @@ -217,7 +217,14 @@ int cudaMallocConditionallyManaged(void** out, size_t bytes, const char *file, i // if we OOM, fallback to a managed allocation. slower but at least won't crash. cudaGetLastError(); // reset the error before the next API call cudaCheck_(cudaMallocManaged(out, bytes), file, line); - cudaCheck_(cudaMemAdvise(*out, bytes, cudaMemAdviseSetPreferredLocation, cudaCpuDeviceId), file, line); + // Prefer host (CPU) location when falling back to managed memory + // Inline compatibility for CUDA 12+ vs older versions + #if defined(CUDART_VERSION) && (CUDART_VERSION >= 12000) + cudaMemLocation loc{}; + loc.type = cudaMemLocationTypeHost; + loc.id = cudaCpuDeviceId; + cudaCheck_(cudaMemAdvise(*out, bytes, cudaMemAdviseSetPreferredLocation, loc), file, line); + #endif return 1; } else { cudaCheck_(err, file, line);