Skip to content

Commit d9facf2

Browse files
committed
[common] fix umf2urResult
In case of UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC the underlying native error was not being translated to UR correctly (it was returned as is). Fix this by adding native error handlers and implement one for LEVEL_ZERO provider
1 parent a1b9fa7 commit d9facf2

File tree

7 files changed

+55
-4
lines changed

7 files changed

+55
-4
lines changed

source/adapters/cuda/usm.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222

2323
#include <cuda.h>
2424

25+
namespace umf {
26+
ur_result_t getProviderNativeError(const char *, int32_t) {
27+
// TODO: implement when UMF supports CUDA
28+
return UR_RESULT_ERROR_UNKNOWN;
29+
}
30+
} // namespace umf
31+
2532
/// USM: Implements USM Host allocations using CUDA Pinned Memory
2633
/// https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#page-locked-host-memory
2734
UR_APIEXPORT ur_result_t UR_APICALL

source/adapters/hip/usm.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
#include "ur_util.hpp"
1919
#include "usm.hpp"
2020

21+
namespace umf {
22+
ur_result_t getProviderNativeError(const char *, int32_t) {
23+
// TODO: implement when UMF supports HIP
24+
return UR_RESULT_ERROR_UNKNOWN;
25+
}
26+
} // namespace umf
27+
2128
/// USM: Implements USM Host allocations using HIP Pinned Memory
2229
UR_APIEXPORT ur_result_t UR_APICALL
2330
urUSMHostAlloc(ur_context_handle_t hContext, const ur_usm_desc_t *pUSMDesc,

source/adapters/level_zero/usm.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@
2323

2424
#include <umf_helpers.hpp>
2525

26+
namespace umf {
27+
ur_result_t getProviderNativeError(const char *providerName,
28+
int32_t nativeError) {
29+
if (strcmp(providerName, "Level Zero") == 0) {
30+
return ze2urResult(static_cast<ze_result_t>(nativeError));
31+
}
32+
33+
return UR_RESULT_ERROR_UNKNOWN;
34+
}
35+
} // namespace umf
36+
2637
usm::DisjointPoolAllConfigs DisjointPoolConfigInstance =
2738
InitializeDisjointPoolConfig();
2839

source/adapters/level_zero/v2/usm.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
#include <umf/pools/pool_proxy.h>
2020
#include <umf/providers/provider_level_zero.h>
2121

22+
namespace umf {
23+
ur_result_t getProviderNativeError(const char *providerName,
24+
int32_t nativeError) {
25+
if (strcmp(providerName, "Level Zero") == 0) {
26+
return ze2urResult(static_cast<ze_result_t>(nativeError));
27+
}
28+
29+
return UR_RESULT_ERROR_UNKNOWN;
30+
}
31+
} // namespace umf
32+
2233
static usm::DisjointPoolAllConfigs initializeDisjointPoolConfig() {
2334
const char *PoolUrTraceVal = std::getenv("UR_L0_USM_ALLOCATOR_TRACE");
2435

source/adapters/native_cpu/usm.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
#include "context.hpp"
1616
#include <cstdlib>
1717

18+
namespace umf {
19+
ur_result_t getProviderNativeError(const char *, int32_t) {
20+
return UR_RESULT_ERROR_UNKNOWN;
21+
}
22+
} // namespace umf
23+
1824
namespace native_cpu {
1925

2026
static ur_result_t alloc_helper(ur_context_handle_t hContext,

source/adapters/opencl/usm.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212

1313
#include "common.hpp"
1414

15+
namespace umf {
16+
ur_result_t getProviderNativeError(const char *, int32_t) {
17+
// TODO: implement when UMF supports OpenCL
18+
return UR_RESULT_ERROR_UNKNOWN;
19+
}
20+
} // namespace umf
21+
1522
inline cl_mem_alloc_flags_intel
1623
hostDescToClFlags(const ur_usm_host_desc_t &desc) {
1724
cl_mem_alloc_flags_intel allocFlags = 0;

source/common/umf_helpers.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ template <typename Type> umf_result_t &getPoolLastStatusRef() {
241241
return last_status;
242242
}
243243

244+
ur_result_t getProviderNativeError(const char *providerName,
245+
int32_t nativeError);
246+
244247
/// @brief translates UMF return values to UR.
245248
/// This function assumes that the native error of
246249
/// the last failed memory provider is ur_result_t.
@@ -256,16 +259,15 @@ inline ur_result_t umf2urResult(umf_result_t umfResult) {
256259
return UR_RESULT_ERROR_UNKNOWN;
257260
}
258261

259-
ur_result_t Err = UR_RESULT_ERROR_UNKNOWN;
262+
int32_t Err = UR_RESULT_ERROR_UNKNOWN;
260263
const char *Msg = nullptr;
261-
umfMemoryProviderGetLastNativeError(hProvider, &Msg,
262-
reinterpret_cast<int32_t *>(&Err));
264+
umfMemoryProviderGetLastNativeError(hProvider, &Msg, &Err);
263265

264266
if (Msg) {
265267
logger::error("UMF failed with: {}", Msg);
266268
}
267269

268-
return Err;
270+
return getProviderNativeError(umfMemoryProviderGetName(hProvider), Err);
269271
}
270272
case UMF_RESULT_ERROR_INVALID_ARGUMENT:
271273
return UR_RESULT_ERROR_INVALID_ARGUMENT;

0 commit comments

Comments
 (0)