|
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 <functional>
|
20 | 21 | #include <memory>
|
@@ -160,6 +161,37 @@ template <typename Type> umf_result_t &getPoolLastStatusRef() {
|
160 | 161 | return last_status;
|
161 | 162 | }
|
162 | 163 |
|
| 164 | +/// @brief translates UMF return values to UR. |
| 165 | +/// This function assumes that the native error of |
| 166 | +/// the last failed memory provider is ur_result_t. |
| 167 | +inline ur_result_t umf2urResult(umf_result_t umfResult) { |
| 168 | + switch (umfResult) { |
| 169 | + case UMF_RESULT_SUCCESS: |
| 170 | + return UR_RESULT_SUCCESS; |
| 171 | + case UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY: |
| 172 | + return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; |
| 173 | + case UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC: { |
| 174 | + auto hProvider = umfGetLastFailedMemoryProvider(); |
| 175 | + if (hProvider == nullptr) { |
| 176 | + return UR_RESULT_ERROR_UNKNOWN; |
| 177 | + } |
| 178 | + |
| 179 | + ur_result_t Err = UR_RESULT_ERROR_UNKNOWN; |
| 180 | + umfMemoryProviderGetLastNativeError(hProvider, nullptr, |
| 181 | + reinterpret_cast<int32_t *>(&Err)); |
| 182 | + return Err; |
| 183 | + } |
| 184 | + case UMF_RESULT_ERROR_INVALID_ARGUMENT: |
| 185 | + return UR_RESULT_ERROR_INVALID_ARGUMENT; |
| 186 | + case UMF_RESULT_ERROR_INVALID_ALIGNMENT: |
| 187 | + return UR_RESULT_ERROR_UNSUPPORTED_ALIGNMENT; |
| 188 | + case UMF_RESULT_ERROR_NOT_SUPPORTED: |
| 189 | + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 190 | + default: |
| 191 | + return UR_RESULT_ERROR_UNKNOWN; |
| 192 | + }; |
| 193 | +} |
| 194 | + |
163 | 195 | } // namespace umf
|
164 | 196 |
|
165 | 197 | #endif /* UMF_HELPERS_H */
|
0 commit comments