Skip to content

Commit

Permalink
Merge pull request #709 from kswiecicki/umf2ur-err
Browse files Browse the repository at this point in the history
[umf] add error translation function to helpers
  • Loading branch information
igchor committed Jul 13, 2023
2 parents 2966d01 + 57d6895 commit 50e8eb0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions source/common/umf_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <umf/memory_pool_ops.h>
#include <umf/memory_provider.h>
#include <umf/memory_provider_ops.h>
#include <ur_api.h>

#include <array>
#include <functional>
Expand Down Expand Up @@ -188,6 +189,37 @@ template <typename Type> umf_result_t &getPoolLastStatusRef() {
return last_status;
}

/// @brief translates UMF return values to UR.
/// This function assumes that the native error of
/// the last failed memory provider is ur_result_t.
inline ur_result_t umf2urResult(umf_result_t umfResult) {
switch (umfResult) {
case UMF_RESULT_SUCCESS:
return UR_RESULT_SUCCESS;
case UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY:
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
case UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC: {
auto hProvider = umfGetLastFailedMemoryProvider();
if (hProvider == nullptr) {
return UR_RESULT_ERROR_UNKNOWN;
}

ur_result_t Err = UR_RESULT_ERROR_UNKNOWN;
umfMemoryProviderGetLastNativeError(hProvider, nullptr,
reinterpret_cast<int32_t *>(&Err));
return Err;
}
case UMF_RESULT_ERROR_INVALID_ARGUMENT:
return UR_RESULT_ERROR_INVALID_ARGUMENT;
case UMF_RESULT_ERROR_INVALID_ALIGNMENT:
return UR_RESULT_ERROR_UNSUPPORTED_ALIGNMENT;
case UMF_RESULT_ERROR_NOT_SUPPORTED:
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
default:
return UR_RESULT_ERROR_UNKNOWN;
};
}

} // namespace umf

#endif /* UMF_HELPERS_H */

0 comments on commit 50e8eb0

Please sign in to comment.