Skip to content

Commit 9ba4d62

Browse files
committed
Always use relaxed allocation limits for L0 host mem
1 parent 5d093ed commit 9ba4d62

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

src/provider/provider_level_zero.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ static void store_last_native_error(int32_t native_error) {
143143
struct ctl ze_memory_ctl_root;
144144
static UTIL_ONCE_FLAG ctl_initialized = UTIL_ONCE_FLAG_INIT;
145145

146-
static ze_relaxed_allocation_limits_exp_desc_t relaxed_device_allocation_desc =
147-
{.stype = ZE_STRUCTURE_TYPE_RELAXED_ALLOCATION_LIMITS_EXP_DESC,
148-
.pNext = NULL,
149-
.flags = ZE_RELAXED_ALLOCATION_LIMITS_EXP_FLAG_MAX_SIZE};
146+
static ze_relaxed_allocation_limits_exp_desc_t relaxed_allocation_desc = {
147+
.stype = ZE_STRUCTURE_TYPE_RELAXED_ALLOCATION_LIMITS_EXP_DESC,
148+
.pNext = NULL,
149+
.flags = ZE_RELAXED_ALLOCATION_LIMITS_EXP_FLAG_MAX_SIZE};
150150

151151
static ze_external_memory_export_desc_t memory_export_desc = {
152152
.stype = ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_DESC,
@@ -530,6 +530,13 @@ static umf_result_t ze_memory_provider_alloc_helper(void *provider, size_t size,
530530
.stype = ZE_STRUCTURE_TYPE_HOST_MEM_ALLOC_DESC,
531531
.pNext = NULL,
532532
.flags = 0};
533+
void *lastNext = &host_desc.pNext;
534+
535+
// add relaxed allocation desc to the pNext chain
536+
ze_relaxed_allocation_limits_exp_desc_t relaxed_allocation_desc_copy =
537+
relaxed_allocation_desc;
538+
*(void **)lastNext = &relaxed_allocation_desc_copy;
539+
533540
ze_result = g_ze_ops.zeMemAllocHost(ze_provider->context, &host_desc,
534541
size, alignment, resultPtr);
535542
break;
@@ -542,13 +549,12 @@ static umf_result_t ze_memory_provider_alloc_helper(void *provider, size_t size,
542549
.ordinal = ze_provider->device_ordinal};
543550
void *lastNext = &dev_desc.pNext;
544551

545-
ze_relaxed_allocation_limits_exp_desc_t
546-
relaxed_device_allocation_desc_copy =
547-
relaxed_device_allocation_desc;
552+
ze_relaxed_allocation_limits_exp_desc_t relaxed_allocation_desc_copy =
553+
relaxed_allocation_desc;
548554
if (use_relaxed_allocation(ze_provider, size)) {
549555
// add relaxed allocation desc to the pNext chain
550-
*(void **)lastNext = &relaxed_device_allocation_desc_copy;
551-
lastNext = &relaxed_device_allocation_desc_copy.pNext;
556+
*(void **)lastNext = &relaxed_allocation_desc_copy;
557+
lastNext = &relaxed_allocation_desc_copy.pNext;
552558
}
553559

554560
// check if the allocation should use import / export mechanism
@@ -573,7 +579,7 @@ static umf_result_t ze_memory_provider_alloc_helper(void *provider, size_t size,
573579
ze_device_mem_alloc_desc_t dev_desc = {
574580
.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC,
575581
.pNext = use_relaxed_allocation(ze_provider, size)
576-
? &relaxed_device_allocation_desc
582+
? &relaxed_allocation_desc
577583
: NULL,
578584
.flags = 0,
579585
.ordinal = ze_provider->device_ordinal};

test/providers/provider_level_zero.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,13 @@ TEST(umfLevelZeroProviderOps, default_name_null_handle) {
538538
}
539539

540540
TEST_P(umfLevelZeroProviderTest, allocInvalidSize) {
541+
if (GetParam() == UMF_MEMORY_TYPE_HOST) {
542+
// For host memory, even with relaxed limits, the allocation may
543+
// succeed or fail depending on the system's available memory,
544+
// so we skip this test for host memory type.
545+
GTEST_SKIP() << "Skipping test for host memory type.";
546+
}
547+
541548
umf_memory_provider_handle_t provider = nullptr;
542549
umf_result_t umf_result = umfMemoryProviderCreate(
543550
umfLevelZeroMemoryProviderOps(), params, &provider);
@@ -547,6 +554,7 @@ TEST_P(umfLevelZeroProviderTest, allocInvalidSize) {
547554
void *ptr = nullptr;
548555
umf_result = umfMemoryProviderAlloc(
549556
provider, std::numeric_limits<size_t>::max(), 0, &ptr);
557+
550558
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC);
551559
const char *message;
552560
int32_t error;

0 commit comments

Comments
 (0)