|
|
@@ -96,31 +96,32 @@ int ggml_cuda_get_device() {
|
|
|
|
|
|
static cudaError_t ggml_cuda_device_malloc(void ** ptr, size_t size, int device) {
|
|
|
ggml_cuda_set_device(device);
|
|
|
-#if defined(GGML_USE_HIP) && defined(GGML_HIP_UMA)
|
|
|
- auto res = hipMallocManaged(ptr, size);
|
|
|
- if (res == hipSuccess) {
|
|
|
- // if error we "need" to know why...
|
|
|
- CUDA_CHECK(hipMemAdvise(*ptr, size, hipMemAdviseSetCoarseGrain, device));
|
|
|
- }
|
|
|
- return res;
|
|
|
-#else
|
|
|
-
|
|
|
-#if !defined(GGML_USE_HIP)
|
|
|
cudaError_t err;
|
|
|
if (getenv("GGML_CUDA_ENABLE_UNIFIED_MEMORY") != nullptr)
|
|
|
{
|
|
|
err = cudaMallocManaged(ptr, size);
|
|
|
+#if defined(GGML_USE_HIP)
|
|
|
+ if (err == hipSuccess) {
|
|
|
+ CUDA_CHECK(cudaMemAdvise(*ptr, size, hipMemAdviseSetCoarseGrain, device));
|
|
|
+ }
|
|
|
+
|
|
|
+ // fall back to cudaMalloc if not supported (e.g. on Windows)
|
|
|
+ if (err == hipErrorNotSupported) {
|
|
|
+ static bool warned_unsupported = false;
|
|
|
+ if (!warned_unsupported) {
|
|
|
+ GGML_LOG_WARN("hipMallocManaged unsupported, falling back to hipMalloc.\n");
|
|
|
+ warned_unsupported = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ err = cudaMalloc(ptr, size);
|
|
|
+ }
|
|
|
+#endif // defined(GGML_USE_HIP)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
err = cudaMalloc(ptr, size);
|
|
|
}
|
|
|
return err;
|
|
|
-#else
|
|
|
- return cudaMalloc(ptr, size);
|
|
|
-#endif // !defined(GGML_USE_HIP)
|
|
|
-
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
#if defined(GGML_USE_HIP) && defined(__HIP_PLATFORM_AMD__)
|