mirror of
https://github.com/karpathy/llm.c.git
synced 2026-07-28 20:35:09 -04:00
Fix for CUDA 13
This commit is contained in:
parent
f1e2ace651
commit
71ee33f62c
1 changed files with 8 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue