Fix for CUDA 13

This commit is contained in:
Aroun Demeure 2025-08-24 10:17:07 +01:00
parent f1e2ace651
commit 71ee33f62c

View file

@ -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);