From fdaa7141af580188695d3c2fe36a30602c94e8a9 Mon Sep 17 00:00:00 2001 From: Vladana Stojiljkovic Date: Fri, 12 Apr 2024 16:59:57 +0200 Subject: [PATCH] SWDEV-452364 - Check if no GPUs are available when hsa_init fails * When no GPUs are available, hsa_init fails with HSA_STATUS_ERROR_OUT_OF_RESOURCES, and device and runtime initialization fails. In order for NoGpu tests to pass, true needs to be returned which will cause HIP_INIT_API to return proper error hipErrorNoDevice instead of hipErrorInvalidDevice. Change-Id: I982d4416c92ed1b36893354d8b10d73df34f2478 --- rocclr/device/rocm/rocdevice.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rocclr/device/rocm/rocdevice.cpp b/rocclr/device/rocm/rocdevice.cpp index a2b77c8d0b..e229094138 100644 --- a/rocclr/device/rocm/rocdevice.cpp +++ b/rocclr/device/rocm/rocdevice.cpp @@ -475,6 +475,15 @@ bool Device::init() { } status = hsa_init(); + + // If there are no GPUs available, hsa_init will fail with HSA_STATUS_ERROR_OUT_OF_RESOURCES + // but for NoGpu tests to pass, true needs to be returned + constexpr bool kNoOfflineDevices = false; + std::vector devices = getDevices(CL_DEVICE_TYPE_GPU, kNoOfflineDevices); + if (status == HSA_STATUS_ERROR_OUT_OF_RESOURCES && devices.size() == 0) { + return true; + } + if (status != HSA_STATUS_SUCCESS) { LogPrintfError("hsa_init failed with %x", status); return false; @@ -577,8 +586,7 @@ bool Device::init() { } // Query active devices only - constexpr bool kNoOfflineDevices = false; - std::vector devices = getDevices(CL_DEVICE_TYPE_GPU, kNoOfflineDevices); + devices = getDevices(CL_DEVICE_TYPE_GPU, kNoOfflineDevices); if (devices.size() > 0) { bool p2p_available = false; // Loop through all available devices