Skip to content

Commit

Permalink
[L0 v2] make umf error handling less verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
igchor committed Dec 17, 2024
1 parent b01b4a2 commit 230d19e
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions source/adapters/level_zero/v2/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
#include <umf/pools/pool_proxy.h>
#include <umf/providers/provider_level_zero.h>

static inline void UMF_CALL_THROWS(umf_result_t res) {
if (res != UMF_RESULT_SUCCESS) {
throw res;
}
}

namespace umf {
ur_result_t getProviderNativeError(const char *providerName,
int32_t nativeError) {
Expand Down Expand Up @@ -85,31 +91,18 @@ static umf::pool_unique_handle_t
makePool(usm::umf_disjoint_pool_config_t *poolParams,
usm::pool_descriptor poolDescriptor) {
umf_level_zero_memory_provider_params_handle_t params = NULL;
umf_result_t umf_ret = umfLevelZeroMemoryProviderParamsCreate(&params);
if (umf_ret != UMF_RESULT_SUCCESS) {
throw umf::umf2urResult(umf_ret);
}

umf_ret = umfLevelZeroMemoryProviderParamsSetContext(
params, poolDescriptor.hContext->getZeHandle());
if (umf_ret != UMF_RESULT_SUCCESS) {
throw umf::umf2urResult(umf_ret);
};
UMF_CALL_THROWS(umfLevelZeroMemoryProviderParamsCreate(&params));
UMF_CALL_THROWS(umfLevelZeroMemoryProviderParamsSetContext(
params, poolDescriptor.hContext->getZeHandle()));

ze_device_handle_t level_zero_device_handle =
poolDescriptor.hDevice ? poolDescriptor.hDevice->ZeDevice : nullptr;

umf_ret = umfLevelZeroMemoryProviderParamsSetDevice(params,
level_zero_device_handle);
if (umf_ret != UMF_RESULT_SUCCESS) {
throw umf::umf2urResult(umf_ret);
}
UMF_CALL_THROWS(umfLevelZeroMemoryProviderParamsSetDevice(
params, level_zero_device_handle));

umf_ret = umfLevelZeroMemoryProviderParamsSetMemoryType(
params, urToUmfMemoryType(poolDescriptor.type));
if (umf_ret != UMF_RESULT_SUCCESS) {
throw umf::umf2urResult(umf_ret);
}
UMF_CALL_THROWS(umfLevelZeroMemoryProviderParamsSetMemoryType(
params, urToUmfMemoryType(poolDescriptor.type)));

std::vector<ze_device_handle_t> residentZeHandles;

Expand All @@ -122,11 +115,8 @@ makePool(usm::umf_disjoint_pool_config_t *poolParams,
residentZeHandles.push_back(device->ZeDevice);
}

umf_ret = umfLevelZeroMemoryProviderParamsSetResidentDevices(
params, residentZeHandles.data(), residentZeHandles.size());
if (umf_ret != UMF_RESULT_SUCCESS) {
throw umf::umf2urResult(umf_ret);
}
UMF_CALL_THROWS(umfLevelZeroMemoryProviderParamsSetResidentDevices(
params, residentZeHandles.data(), residentZeHandles.size()));
}

auto [ret, provider] =
Expand Down

0 comments on commit 230d19e

Please sign in to comment.