|
15 | 15 | #include <umf/memory_pool_ops.h>
|
16 | 16 | #include <umf/memory_provider.h>
|
17 | 17 | #include <umf/memory_provider_ops.h>
|
| 18 | +#include <ur_api.h> |
18 | 19 |
|
19 | 20 | #include <array>
|
20 | 21 | #include <functional>
|
@@ -188,6 +189,37 @@ template <typename Type> umf_result_t &getPoolLastStatusRef() {
|
188 | 189 | return last_status;
|
189 | 190 | }
|
190 | 191 |
|
| 192 | +/// @brief translates UMF return values to UR. |
| 193 | +/// This function assumes that the native error of |
| 194 | +/// the last failed memory provider is ur_result_t. |
| 195 | +inline ur_result_t umf2urResult(umf_result_t umfResult) { |
| 196 | + switch (umfResult) { |
| 197 | + case UMF_RESULT_SUCCESS: |
| 198 | + return UR_RESULT_SUCCESS; |
| 199 | + case UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY: |
| 200 | + return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; |
| 201 | + case UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC: { |
| 202 | + auto hProvider = umfGetLastFailedMemoryProvider(); |
| 203 | + if (hProvider == nullptr) { |
| 204 | + return UR_RESULT_ERROR_UNKNOWN; |
| 205 | + } |
| 206 | + |
| 207 | + ur_result_t Err = UR_RESULT_ERROR_UNKNOWN; |
| 208 | + umfMemoryProviderGetLastNativeError(hProvider, nullptr, |
| 209 | + reinterpret_cast<int32_t *>(&Err)); |
| 210 | + return Err; |
| 211 | + } |
| 212 | + case UMF_RESULT_ERROR_INVALID_ARGUMENT: |
| 213 | + return UR_RESULT_ERROR_INVALID_ARGUMENT; |
| 214 | + case UMF_RESULT_ERROR_INVALID_ALIGNMENT: |
| 215 | + return UR_RESULT_ERROR_UNSUPPORTED_ALIGNMENT; |
| 216 | + case UMF_RESULT_ERROR_NOT_SUPPORTED: |
| 217 | + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 218 | + default: |
| 219 | + return UR_RESULT_ERROR_UNKNOWN; |
| 220 | + }; |
| 221 | +} |
| 222 | + |
191 | 223 | } // namespace umf
|
192 | 224 |
|
193 | 225 | #endif /* UMF_HELPERS_H */
|
0 commit comments