Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions unified-runtime/source/adapters/level_zero/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ usm::DisjointPoolAllConfigs DisjointPoolConfigInstance =
InitializeDisjointPoolConfig();

usm::DisjointPoolAllConfigs InitializeDisjointPoolConfig() {
const char *PoolUrTraceVal = std::getenv("UR_L0_USM_ALLOCATOR_TRACE");
const char *PoolPiTraceVal =
std::getenv("SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR_TRACE");
const char *PoolTraceVal = PoolUrTraceVal
? PoolUrTraceVal
: (PoolPiTraceVal ? PoolPiTraceVal : nullptr);
// Prefer the UR-specific env var, fall back to the PI-specific one.
const char *PoolTraceVal = std::getenv("UR_L0_USM_ALLOCATOR_TRACE");
if (!PoolTraceVal) {
PoolTraceVal = std::getenv("SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR_TRACE");
}

// Parse integer value, defaulting to 0 on missing/invalid input.
int PoolTrace = 0;
if (PoolTraceVal != nullptr) {
if (PoolTraceVal) {
PoolTrace = std::atoi(PoolTraceVal);
}

const char *PoolUrConfigVal = std::getenv("SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR");
const char *PoolPiConfigVal = std::getenv("UR_L0_USM_ALLOCATOR");
const char *PoolConfigVal =
PoolUrConfigVal ? PoolUrConfigVal : PoolPiConfigVal;
if (PoolConfigVal == nullptr) {
const char *PoolConfigVal = std::getenv("UR_L0_USM_ALLOCATOR");
if (!PoolConfigVal) {
PoolConfigVal = std::getenv("SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR");
}
if (!PoolConfigVal) {
return usm::DisjointPoolAllConfigs(PoolTrace);
}

Expand Down
2 changes: 0 additions & 2 deletions unified-runtime/source/adapters/level_zero/usm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
//===----------------------------------------------------------------------===//
#pragma once

#include <set>

#include "common.hpp"
#include "common/ur_ref_count.hpp"
#include "enqueued_pool.hpp"
Expand Down
21 changes: 4 additions & 17 deletions unified-runtime/source/adapters/level_zero/v2/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,13 @@ ur_result_t getProviderNativeError(const char *providerName,

static std::optional<usm::DisjointPoolAllConfigs>
initializeDisjointPoolConfig() {
const char *UrRetDisable = std::getenv("UR_L0_DISABLE_USM_ALLOCATOR");
const char *PiRetDisable =
std::getenv("SYCL_PI_LEVEL_ZERO_DISABLE_USM_ALLOCATOR");
const char *Disable =
UrRetDisable ? UrRetDisable : (PiRetDisable ? PiRetDisable : nullptr);
if (Disable != nullptr && Disable != std::string("")) {
if (getenv_tobool("UR_L0_DISABLE_USM_ALLOCATOR") ||
getenv_tobool("SYCL_PI_LEVEL_ZERO_DISABLE_USM_ALLOCATOR")) {
return std::nullopt;
}

const char *PoolUrTraceVal = std::getenv("UR_L0_USM_ALLOCATOR_TRACE");

int PoolTrace = 0;
if (PoolUrTraceVal != nullptr) {
if (auto PoolUrTraceVal = std::getenv("UR_L0_USM_ALLOCATOR_TRACE")) {
PoolTrace = std::atoi(PoolUrTraceVal);
}

Expand All @@ -64,14 +58,7 @@ initializeDisjointPoolConfig() {
return usm::DisjointPoolAllConfigs(PoolTrace);
}

// TODO: rework parseDisjointPoolConfig to return optional,
// once EnableBuffers is no longer used (by legacy L0)
auto configs = usm::parseDisjointPoolConfig(PoolUrConfigVal, PoolTrace);
if (configs.EnableBuffers) {
return configs;
}

return std::nullopt;
return usm::parseDisjointPoolConfigOptional(PoolUrConfigVal, PoolTrace);
}

inline umf_usm_memory_type_t urToUmfMemoryType(ur_usm_type_t type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,13 @@ DisjointPoolAllConfigs parseDisjointPoolConfig(const std::string &config,

return AllConfigs;
}

std::optional<DisjointPoolAllConfigs>
parseDisjointPoolConfigOptional(const std::string &config, int trace) {
auto configs = parseDisjointPoolConfig(config, trace);
if (configs.EnableBuffers == 0) {
return std::nullopt;
}
return configs;
}
} // namespace usm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <umf/pools/pool_disjoint.h>

#include <memory>
#include <optional>
#include <string>
#include <unordered_map>

Expand Down Expand Up @@ -71,6 +72,13 @@ class DisjointPoolAllConfigs {
DisjointPoolAllConfigs parseDisjointPoolConfig(const std::string &config,
int trace = 1);

// Parse optional config parameters with optional return.
// Returns std::nullopt when EnableBuffers is 0, indicating pooling is disabled.
// This is for use cases where EnableBuffers flag controls pool creation,
// particularly in the v2 Level Zero adapter.
std::optional<DisjointPoolAllConfigs>
parseDisjointPoolConfigOptional(const std::string &config, int trace = 1);

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