From f2be82325d4c1ccde957899f3d3635bca274396b Mon Sep 17 00:00:00 2001 From: Michael Aziz Date: Thu, 26 Oct 2023 12:27:39 -0700 Subject: [PATCH 1/4] [UR][L0] Propagate errors from `USMAllocationMakeResident` This change ensures that USM allocation APIs don't return `UR_RESULT_SUCCESS` when an error occurs within `USMAllocationMakeResident`. Signed-off-by: Michael Aziz --- source/adapters/level_zero/usm.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/source/adapters/level_zero/usm.cpp b/source/adapters/level_zero/usm.cpp index d06a0353e4..d75f3872b1 100644 --- a/source/adapters/level_zero/usm.cpp +++ b/source/adapters/level_zero/usm.cpp @@ -192,9 +192,8 @@ static ur_result_t USMDeviceAllocImpl(void **ResultPtr, reinterpret_cast(*ResultPtr) % Alignment == 0, UR_RESULT_ERROR_INVALID_VALUE); - USMAllocationMakeResident(USMDeviceAllocationForceResidency, Context, Device, - *ResultPtr, Size); - return UR_RESULT_SUCCESS; + return USMAllocationMakeResident(USMDeviceAllocationForceResidency, Context, + Device, *ResultPtr, Size); } static ur_result_t USMSharedAllocImpl(void **ResultPtr, @@ -225,11 +224,9 @@ static ur_result_t USMSharedAllocImpl(void **ResultPtr, reinterpret_cast(*ResultPtr) % Alignment == 0, UR_RESULT_ERROR_INVALID_VALUE); - USMAllocationMakeResident(USMSharedAllocationForceResidency, Context, Device, - *ResultPtr, Size); - // TODO: Handle PI_MEM_ALLOC_DEVICE_READ_ONLY. - return UR_RESULT_SUCCESS; + return USMAllocationMakeResident(USMSharedAllocationForceResidency, Context, + Device, *ResultPtr, Size); } static ur_result_t USMHostAllocImpl(void **ResultPtr, @@ -247,9 +244,8 @@ static ur_result_t USMHostAllocImpl(void **ResultPtr, reinterpret_cast(*ResultPtr) % Alignment == 0, UR_RESULT_ERROR_INVALID_VALUE); - USMAllocationMakeResident(USMHostAllocationForceResidency, Context, nullptr, - *ResultPtr, Size); - return UR_RESULT_SUCCESS; + return USMAllocationMakeResident(USMHostAllocationForceResidency, Context, + nullptr, *ResultPtr, Size); } UR_APIEXPORT ur_result_t UR_APICALL urUSMHostAlloc( From f056f97fde9cbe501ea703b1112110c8fa4ed768 Mon Sep 17 00:00:00 2001 From: Michael Aziz Date: Mon, 30 Oct 2023 14:29:20 -0700 Subject: [PATCH 2/4] Fix error propagation Signed-off-by: Michael Aziz --- source/adapters/level_zero/usm.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/source/adapters/level_zero/usm.cpp b/source/adapters/level_zero/usm.cpp index d75f3872b1..51e86bb65f 100644 --- a/source/adapters/level_zero/usm.cpp +++ b/source/adapters/level_zero/usm.cpp @@ -192,8 +192,13 @@ static ur_result_t USMDeviceAllocImpl(void **ResultPtr, reinterpret_cast(*ResultPtr) % Alignment == 0, UR_RESULT_ERROR_INVALID_VALUE); - return USMAllocationMakeResident(USMDeviceAllocationForceResidency, Context, - Device, *ResultPtr, Size); + auto Result = USMAllocationMakeResident(USMDeviceAllocationForceResidency, + Context, Device, *ResultPtr, Size); + if (Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY || + Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY) { + return Result; + } + return UR_RESULT_SUCCESS; } static ur_result_t USMSharedAllocImpl(void **ResultPtr, @@ -224,9 +229,15 @@ static ur_result_t USMSharedAllocImpl(void **ResultPtr, reinterpret_cast(*ResultPtr) % Alignment == 0, UR_RESULT_ERROR_INVALID_VALUE); + auto Result = USMAllocationMakeResident(USMSharedAllocationForceResidency, + Context, Device, *ResultPtr, Size); + if (Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY || + Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY) { + return Result; + } + // TODO: Handle PI_MEM_ALLOC_DEVICE_READ_ONLY. - return USMAllocationMakeResident(USMSharedAllocationForceResidency, Context, - Device, *ResultPtr, Size); + return UR_RESULT_SUCCESS; } static ur_result_t USMHostAllocImpl(void **ResultPtr, @@ -244,8 +255,13 @@ static ur_result_t USMHostAllocImpl(void **ResultPtr, reinterpret_cast(*ResultPtr) % Alignment == 0, UR_RESULT_ERROR_INVALID_VALUE); - return USMAllocationMakeResident(USMHostAllocationForceResidency, Context, - nullptr, *ResultPtr, Size); + auto Result = USMAllocationMakeResident(USMHostAllocationForceResidency, + Context, nullptr, *ResultPtr, Size); + if (Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY || + Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY) { + return Result; + } + return UR_RESULT_SUCCESS; } UR_APIEXPORT ur_result_t UR_APICALL urUSMHostAlloc( From bc7c0f4926393c464ab4893b9b2ea8ba9c09bcdd Mon Sep 17 00:00:00 2001 From: Michael Aziz Date: Wed, 1 Nov 2023 08:02:04 -0700 Subject: [PATCH 3/4] Fix result checks Signed-off-by: Michael Aziz --- source/adapters/level_zero/usm.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/adapters/level_zero/usm.cpp b/source/adapters/level_zero/usm.cpp index 51e86bb65f..5c4e44930b 100644 --- a/source/adapters/level_zero/usm.cpp +++ b/source/adapters/level_zero/usm.cpp @@ -195,7 +195,7 @@ static ur_result_t USMDeviceAllocImpl(void **ResultPtr, auto Result = USMAllocationMakeResident(USMDeviceAllocationForceResidency, Context, Device, *ResultPtr, Size); if (Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY || - Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY) { + Result == UR_RESULT_ERROR_OUT_OF_HOST_MEMORY) { return Result; } return UR_RESULT_SUCCESS; @@ -232,7 +232,7 @@ static ur_result_t USMSharedAllocImpl(void **ResultPtr, auto Result = USMAllocationMakeResident(USMSharedAllocationForceResidency, Context, Device, *ResultPtr, Size); if (Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY || - Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY) { + Result == UR_RESULT_ERROR_OUT_OF_HOST_MEMORY) { return Result; } @@ -258,7 +258,7 @@ static ur_result_t USMHostAllocImpl(void **ResultPtr, auto Result = USMAllocationMakeResident(USMHostAllocationForceResidency, Context, nullptr, *ResultPtr, Size); if (Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY || - Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY) { + Result == UR_RESULT_ERROR_OUT_OF_HOST_MEMORY) { return Result; } return UR_RESULT_SUCCESS; From fe469d7fb77d2ebdd70b0713483ed61846a43881 Mon Sep 17 00:00:00 2001 From: Michael Aziz Date: Thu, 2 Nov 2023 08:43:33 -0700 Subject: [PATCH 4/4] Add TODO for handling other error results Signed-off-by: Michael Aziz --- source/adapters/level_zero/usm.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/adapters/level_zero/usm.cpp b/source/adapters/level_zero/usm.cpp index 5c4e44930b..daec0408fb 100644 --- a/source/adapters/level_zero/usm.cpp +++ b/source/adapters/level_zero/usm.cpp @@ -192,6 +192,8 @@ static ur_result_t USMDeviceAllocImpl(void **ResultPtr, reinterpret_cast(*ResultPtr) % Alignment == 0, UR_RESULT_ERROR_INVALID_VALUE); + // TODO: Return any non-success result from USMAllocationMakeResident once + // oneapi-src/level-zero-spec#240 is resolved. auto Result = USMAllocationMakeResident(USMDeviceAllocationForceResidency, Context, Device, *ResultPtr, Size); if (Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY || @@ -229,6 +231,8 @@ static ur_result_t USMSharedAllocImpl(void **ResultPtr, reinterpret_cast(*ResultPtr) % Alignment == 0, UR_RESULT_ERROR_INVALID_VALUE); + // TODO: Return any non-success result from USMAllocationMakeResident once + // oneapi-src/level-zero-spec#240 is resolved. auto Result = USMAllocationMakeResident(USMSharedAllocationForceResidency, Context, Device, *ResultPtr, Size); if (Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY || @@ -255,6 +259,8 @@ static ur_result_t USMHostAllocImpl(void **ResultPtr, reinterpret_cast(*ResultPtr) % Alignment == 0, UR_RESULT_ERROR_INVALID_VALUE); + // TODO: Return any non-success result from USMAllocationMakeResident once + // oneapi-src/level-zero-spec#240 is resolved. auto Result = USMAllocationMakeResident(USMHostAllocationForceResidency, Context, nullptr, *ResultPtr, Size); if (Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY ||