Skip to content

Commit

Permalink
Merge pull request #2436 from igchor/umf_params_bump
Browse files Browse the repository at this point in the history
[UMF] bump UMF version to v0.10.0 and adjust code
  • Loading branch information
martygrant authored Dec 11, 2024
2 parents e23a750 + bc5d6a6 commit 58e4d76
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 80 deletions.
33 changes: 20 additions & 13 deletions source/adapters/cuda/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,29 +403,32 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
umf::memoryProviderMakeUnique<USMHostMemoryProvider>(Context, nullptr)
.second;

auto UmfHostParamsHandle = getUmfParamsHandle(
DisjointPoolConfigs.Configs[usm::DisjointPoolMemType::Host]);
HostMemPool =
umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs.Configs[usm::DisjointPoolMemType::Host])
umf::poolMakeUniqueFromOps(umfDisjointPoolOps(), std::move(MemProvider),
UmfHostParamsHandle.get())
.second;

for (const auto &Device : Context->getDevices()) {
MemProvider =
umf::memoryProviderMakeUnique<USMDeviceMemoryProvider>(Context, Device)
.second;
DeviceMemPool = umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs
.Configs[usm::DisjointPoolMemType::Device])
.second;
auto UmfDeviceParamsHandle = getUmfParamsHandle(
DisjointPoolConfigs.Configs[usm::DisjointPoolMemType::Device]);
DeviceMemPool =
umf::poolMakeUniqueFromOps(umfDisjointPoolOps(), std::move(MemProvider),
UmfDeviceParamsHandle.get())
.second;
MemProvider =
umf::memoryProviderMakeUnique<USMSharedMemoryProvider>(Context, Device)
.second;
SharedMemPool = umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs
.Configs[usm::DisjointPoolMemType::Shared])
.second;
auto UmfSharedParamsHandle = getUmfParamsHandle(
DisjointPoolConfigs.Configs[usm::DisjointPoolMemType::Shared]);
SharedMemPool =
umf::poolMakeUniqueFromOps(umfDisjointPoolOps(), std::move(MemProvider),
UmfSharedParamsHandle.get())
.second;
Context->addPool(this);
}
}
Expand All @@ -452,6 +455,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolCreate(
new ur_usm_pool_handle_t_(Context, PoolDesc));
} catch (const UsmAllocationException &Ex) {
return Ex.getError();
} catch (umf_result_t e) {
return umf::umf2urResult(e);
} catch (...) {
return UR_RESULT_ERROR_UNKNOWN;
}
return UR_RESULT_SUCCESS;
#else
Expand Down
33 changes: 20 additions & 13 deletions source/adapters/hip/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,30 +345,33 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
umf::memoryProviderMakeUnique<USMHostMemoryProvider>(Context, nullptr)
.second;

auto UmfHostParamsHandle = getUmfParamsHandle(
DisjointPoolConfigs.Configs[usm::DisjointPoolMemType::Host]);
HostMemPool =
umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs.Configs[usm::DisjointPoolMemType::Host])
umf::poolMakeUniqueFromOps(umfDisjointPoolOps(), std::move(MemProvider),
UmfHostParamsHandle.get())
.second;

for (const auto &Device : Context->getDevices()) {
MemProvider =
umf::memoryProviderMakeUnique<USMDeviceMemoryProvider>(Context, Device)
.second;
DeviceMemPool = umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs
.Configs[usm::DisjointPoolMemType::Device])
.second;
auto UmfDeviceParamsHandle = getUmfParamsHandle(
DisjointPoolConfigs.Configs[usm::DisjointPoolMemType::Device]);
DeviceMemPool =
umf::poolMakeUniqueFromOps(umfDisjointPoolOps(), std::move(MemProvider),
UmfDeviceParamsHandle.get())
.second;

MemProvider =
umf::memoryProviderMakeUnique<USMSharedMemoryProvider>(Context, Device)
.second;
SharedMemPool = umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs
.Configs[usm::DisjointPoolMemType::Shared])
.second;
auto UmfSharedParamsHandle = getUmfParamsHandle(
DisjointPoolConfigs.Configs[usm::DisjointPoolMemType::Shared]);
SharedMemPool =
umf::poolMakeUniqueFromOps(umfDisjointPoolOps(), std::move(MemProvider),
UmfSharedParamsHandle.get())
.second;
Context->addPool(this);
}
}
Expand All @@ -395,6 +398,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolCreate(
new ur_usm_pool_handle_t_(Context, PoolDesc));
} catch (const UsmAllocationException &Ex) {
return Ex.getError();
} catch (umf_result_t e) {
return umf::umf2urResult(e);
} catch (...) {
return UR_RESULT_ERROR_UNKNOWN;
}
return UR_RESULT_SUCCESS;
#else
Expand Down
42 changes: 25 additions & 17 deletions source/adapters/level_zero/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ ur_result_t urContextCreate(
}
} catch (const std::bad_alloc &) {
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
} catch (umf_result_t e) {
return umf::umf2urResult(e);
} catch (...) {
return UR_RESULT_ERROR_UNKNOWN;
}
Expand Down Expand Up @@ -196,36 +198,41 @@ ur_result_t ur_context_handle_t_::initialize() {
auto MemProvider = umf::memoryProviderMakeUnique<L0DeviceMemoryProvider>(
reinterpret_cast<ur_context_handle_t>(this), Device)
.second;
auto UmfDeviceParamsHandle = getUmfParamsHandle(
DisjointPoolConfigInstance.Configs[usm::DisjointPoolMemType::Device]);
DeviceMemPools.emplace(
std::piecewise_construct, std::make_tuple(Device->ZeDevice),
std::make_tuple(umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
&DisjointPoolConfigInstance
.Configs[usm::DisjointPoolMemType::Device])
std::make_tuple(umf::poolMakeUniqueFromOps(umfDisjointPoolOps(),
std::move(MemProvider),
UmfDeviceParamsHandle.get())
.second));

MemProvider = umf::memoryProviderMakeUnique<L0SharedMemoryProvider>(
reinterpret_cast<ur_context_handle_t>(this), Device)
.second;

auto UmfSharedParamsHandle = getUmfParamsHandle(
DisjointPoolConfigInstance.Configs[usm::DisjointPoolMemType::Shared]);
SharedMemPools.emplace(
std::piecewise_construct, std::make_tuple(Device->ZeDevice),
std::make_tuple(umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
&DisjointPoolConfigInstance
.Configs[usm::DisjointPoolMemType::Shared])
std::make_tuple(umf::poolMakeUniqueFromOps(umfDisjointPoolOps(),
std::move(MemProvider),
UmfSharedParamsHandle.get())
.second));

MemProvider = umf::memoryProviderMakeUnique<L0SharedReadOnlyMemoryProvider>(
reinterpret_cast<ur_context_handle_t>(this), Device)
.second;

auto UmfSharedROParamsHandle = getUmfParamsHandle(
DisjointPoolConfigInstance
.Configs[usm::DisjointPoolMemType::SharedReadOnly]);
SharedReadOnlyMemPools.emplace(
std::piecewise_construct, std::make_tuple(Device->ZeDevice),
std::make_tuple(
umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
&DisjointPoolConfigInstance
.Configs[usm::DisjointPoolMemType::SharedReadOnly])
.second));
std::make_tuple(umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
UmfSharedROParamsHandle.get())
.second));

MemProvider = umf::memoryProviderMakeUnique<L0DeviceMemoryProvider>(
reinterpret_cast<ur_context_handle_t>(this), Device)
Expand Down Expand Up @@ -273,10 +280,11 @@ ur_result_t ur_context_handle_t_::initialize() {
auto MemProvider = umf::memoryProviderMakeUnique<L0HostMemoryProvider>(
reinterpret_cast<ur_context_handle_t>(this), nullptr)
.second;
auto UmfHostParamsHandle = getUmfParamsHandle(
DisjointPoolConfigInstance.Configs[usm::DisjointPoolMemType::Host]);
HostMemPool =
umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
&DisjointPoolConfigInstance.Configs[usm::DisjointPoolMemType::Host])
umf::poolMakeUniqueFromOps(umfDisjointPoolOps(), std::move(MemProvider),
UmfHostParamsHandle.get())
.second;

MemProvider = umf::memoryProviderMakeUnique<L0HostMemoryProvider>(
Expand Down
42 changes: 25 additions & 17 deletions source/adapters/level_zero/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,10 @@ ur_result_t urUSMPoolCreate(

} catch (const UsmAllocationException &Ex) {
return Ex.getError();
} catch (umf_result_t e) {
return umf2urResult(e);
} catch (...) {
return UR_RESULT_ERROR_UNKNOWN;
}
return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -1051,46 +1055,50 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
umf::memoryProviderMakeUnique<L0HostMemoryProvider>(Context, nullptr)
.second;

auto UmfHostParamsHandle = getUmfParamsHandle(
DisjointPoolConfigInstance.Configs[usm::DisjointPoolMemType::Host]);
HostMemPool =
umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs.Configs[usm::DisjointPoolMemType::Host])
umf::poolMakeUniqueFromOps(umfDisjointPoolOps(), std::move(MemProvider),
UmfHostParamsHandle.get())
.second;

for (auto device : Context->Devices) {
MemProvider =
umf::memoryProviderMakeUnique<L0DeviceMemoryProvider>(Context, device)
.second;
auto UmfDeviceParamsHandle = getUmfParamsHandle(
DisjointPoolConfigInstance.Configs[usm::DisjointPoolMemType::Device]);
DeviceMemPools.emplace(
std::piecewise_construct, std::make_tuple(device),
std::make_tuple(umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs
.Configs[usm::DisjointPoolMemType::Device])
std::make_tuple(umf::poolMakeUniqueFromOps(umfDisjointPoolOps(),
std::move(MemProvider),
UmfDeviceParamsHandle.get())
.second));

MemProvider =
umf::memoryProviderMakeUnique<L0SharedMemoryProvider>(Context, device)
.second;
auto UmfSharedParamsHandle = getUmfParamsHandle(
DisjointPoolConfigInstance.Configs[usm::DisjointPoolMemType::Shared]);
SharedMemPools.emplace(
std::piecewise_construct, std::make_tuple(device),
std::make_tuple(umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs
.Configs[usm::DisjointPoolMemType::Shared])
std::make_tuple(umf::poolMakeUniqueFromOps(umfDisjointPoolOps(),
std::move(MemProvider),
UmfSharedParamsHandle.get())
.second));

MemProvider = umf::memoryProviderMakeUnique<L0SharedReadOnlyMemoryProvider>(
Context, device)
.second;
auto UmfSharedROParamsHandle = getUmfParamsHandle(
DisjointPoolConfigInstance
.Configs[usm::DisjointPoolMemType::SharedReadOnly]);
SharedReadOnlyMemPools.emplace(
std::piecewise_construct, std::make_tuple(device),
std::make_tuple(
umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs
.Configs[usm::DisjointPoolMemType::SharedReadOnly])
.second));
std::make_tuple(umf::poolMakeUniqueFromOps(
umfDisjointPoolOps(), std::move(MemProvider),
UmfSharedROParamsHandle.get())
.second));
}
}

Expand Down
55 changes: 42 additions & 13 deletions source/adapters/level_zero/v2/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,55 @@ descToDisjoinPoolMemType(const usm::pool_descriptor &desc) {
}

static umf::pool_unique_handle_t
makePool(umf_disjoint_pool_params_t *poolParams,
makePool(usm::umf_disjoint_pool_config_t *poolParams,
usm::pool_descriptor poolDescriptor) {
level_zero_memory_provider_params_t params = {};
params.level_zero_context_handle = poolDescriptor.hContext->getZeHandle();
params.level_zero_device_handle =
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);
};

ze_device_handle_t level_zero_device_handle =
poolDescriptor.hDevice ? poolDescriptor.hDevice->ZeDevice : nullptr;
params.memory_type = urToUmfMemoryType(poolDescriptor.type);

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

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

std::vector<ze_device_handle_t> residentZeHandles;

if (poolDescriptor.type == UR_USM_TYPE_DEVICE) {
assert(params.level_zero_device_handle);
assert(level_zero_device_handle);
auto residentHandles =
poolDescriptor.hContext->getP2PDevices(poolDescriptor.hDevice);
residentZeHandles.push_back(params.level_zero_device_handle);
residentZeHandles.push_back(level_zero_device_handle);
for (auto &device : residentHandles) {
residentZeHandles.push_back(device->ZeDevice);
}

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

auto [ret, provider] =
umf::providerMakeUniqueFromOps(umfLevelZeroMemoryProviderOps(), &params);
umf::providerMakeUniqueFromOps(umfLevelZeroMemoryProviderOps(), params);
if (ret != UMF_RESULT_SUCCESS) {
throw umf::umf2urResult(ret);
}
Expand All @@ -118,9 +142,11 @@ makePool(umf_disjoint_pool_params_t *poolParams,
throw umf::umf2urResult(ret);
return std::move(poolHandle);
} else {
auto umfParams = getUmfParamsHandle(*poolParams);

auto [ret, poolHandle] =
umf::poolMakeUniqueFromOps(umfDisjointPoolOps(), std::move(provider),
static_cast<void *>(poolParams));
static_cast<void *>(umfParams.get()));
if (ret != UMF_RESULT_SUCCESS)
throw umf::umf2urResult(ret);
return std::move(poolHandle);
Expand Down Expand Up @@ -199,10 +225,13 @@ ur_result_t urUSMPoolCreate(
pPoolDesc, ///< [in] pointer to USM pool descriptor. Can be chained with
///< ::ur_usm_pool_limits_desc_t
ur_usm_pool_handle_t *hPool ///< [out] pointer to USM memory pool
) {

) try {
*hPool = new ur_usm_pool_handle_t_(hContext, pPoolDesc);
return UR_RESULT_SUCCESS;
} catch (umf_result_t e) {
return umf::umf2urResult(e);
} catch (...) {
return exceptionToResult(std::current_exception());
}

ur_result_t
Expand Down
9 changes: 4 additions & 5 deletions source/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ if (NOT DEFINED UMF_REPO)
endif()

if (NOT DEFINED UMF_TAG)
# special branch with cherry-picks for incoming pulldown
# contains UMF PRs: #866, #924, and #930
# branch was based on commit: 3bae087c9a8c0cbed5bde40f0d5a2
# umf-fixes-nov-pulldown: 25.11.2024: Disable libudev in hwloc builds
set(UMF_TAG a7b6152b7b095c88ddf34bc7d442eb4c2b3f74d6)
# tag v0.10.0
# Tagger: Łukasz Stolarczuk <lukasz.stolarczuk@intel.com>
# Date: Mon Dec 9 17:01:43 2024 +0100
set(UMF_TAG v0.10.0)
endif()

message(STATUS "Will fetch Unified Memory Framework from ${UMF_REPO}")
Expand Down
6 changes: 5 additions & 1 deletion source/common/umf_pools/disjoint_pool_config_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ constexpr auto operator""_GB(unsigned long long x) -> size_t {
return x * 1024 * 1024 * 1024;
}

umf_disjoint_pool_config_t::umf_disjoint_pool_config_t()
: SlabMinSize(0), MaxPoolableSize(0), Capacity(0),
MinBucketSize(UMF_DISJOINT_POOL_MIN_BUCKET_DEFAULT_SIZE), PoolTrace(0),
SharedLimits(nullptr), Name("disjoint_pool") {}

DisjointPoolAllConfigs::DisjointPoolAllConfigs(int trace) {
for (auto &Config : Configs) {
Config = umfDisjointPoolParamsDefault();
Config.PoolTrace = trace;
}

Expand Down
Loading

0 comments on commit 58e4d76

Please sign in to comment.