Skip to content

Commit a12247b

Browse files
authored
Merge pull request #1594 from bratpiorka/rrudnick_ze_relaxed_alloc
Always use relaxed allocation limits for L0 host mem
2 parents 3e3a870 + 770abef commit a12247b

3 files changed

Lines changed: 31 additions & 11 deletions

File tree

.github/workflows/reusable_compatibility.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,22 @@ jobs:
385385
UMF_LOG: level:warning;flush:debug;output:stderr;pid:no
386386
LD_LIBRARY_PATH: ${{github.workspace}}/latest_version/build/lib/
387387
run: |
388-
ctest --verbose -E "test_memoryProvider|test_disjoint_pool"
388+
ctest --verbose -E "test_memoryProvider|test_disjoint_pool|test_provider_level_zero|test_provider_level_zero_dlopen_global|test_provider_level_zero_dlopen_local"
389389
390390
- name: Run disabled tests individually with latest UMF libs (warnings enabled)
391391
working-directory: ${{github.workspace}}/tag_version/build
392392
env:
393393
UMF_LOG: level:warning;flush:debug;output:stderr;pid:no
394394
LD_LIBRARY_PATH: ${{github.workspace}}/latest_version/build/lib/
395+
MATRIX_PROVIDER: ${{matrix.provider}}
395396
run: |
396397
test/test_memoryProvider --gtest_filter="-*Trace"
397398
test/test_disjoint_pool --gtest_filter="-test.internals"
399+
if [[ "$MATRIX_PROVIDER" == "LEVEL_ZERO" ]]; then
400+
test/test_provider_level_zero --gtest_filter="-*allocInvalidSize/2"
401+
test/test_provider_level_zero_dlopen_global --gtest_filter="-*allocInvalidSize/2"
402+
test/test_provider_level_zero_dlopen_local --gtest_filter="-*allocInvalidSize/2"
403+
fi
398404
399405
# Browse all folders in the examples directory, build them using the
400406
# latest UMF version, and run them, excluding those in the exclude list.

src/provider/provider_level_zero.c

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

161-
static ze_relaxed_allocation_limits_exp_desc_t relaxed_device_allocation_desc =
162-
{.stype = ZE_STRUCTURE_TYPE_RELAXED_ALLOCATION_LIMITS_EXP_DESC,
163-
.pNext = NULL,
164-
.flags = ZE_RELAXED_ALLOCATION_LIMITS_EXP_FLAG_MAX_SIZE};
161+
static ze_relaxed_allocation_limits_exp_desc_t relaxed_allocation_desc = {
162+
.stype = ZE_STRUCTURE_TYPE_RELAXED_ALLOCATION_LIMITS_EXP_DESC,
163+
.pNext = NULL,
164+
.flags = ZE_RELAXED_ALLOCATION_LIMITS_EXP_FLAG_MAX_SIZE};
165165

166166
static ze_external_memory_export_desc_t memory_export_desc = {
167167
.stype = ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_DESC,
@@ -691,6 +691,13 @@ static umf_result_t ze_memory_provider_alloc_helper(void *provider, size_t size,
691691
.stype = ZE_STRUCTURE_TYPE_HOST_MEM_ALLOC_DESC,
692692
.pNext = NULL,
693693
.flags = 0};
694+
void *lastNext = &host_desc.pNext;
695+
696+
// add relaxed allocation desc to the pNext chain
697+
ze_relaxed_allocation_limits_exp_desc_t relaxed_allocation_desc_copy =
698+
relaxed_allocation_desc;
699+
*(void **)lastNext = &relaxed_allocation_desc_copy;
700+
694701
ze_result = g_ze_ops.zeMemAllocHost(ze_provider->context, &host_desc,
695702
size, alignment, resultPtr);
696703
break;
@@ -703,13 +710,12 @@ static umf_result_t ze_memory_provider_alloc_helper(void *provider, size_t size,
703710
.ordinal = ze_provider->device_ordinal};
704711
void *lastNext = &dev_desc.pNext;
705712

706-
ze_relaxed_allocation_limits_exp_desc_t
707-
relaxed_device_allocation_desc_copy =
708-
relaxed_device_allocation_desc;
713+
ze_relaxed_allocation_limits_exp_desc_t relaxed_allocation_desc_copy =
714+
relaxed_allocation_desc;
709715
if (use_relaxed_allocation(ze_provider, size)) {
710716
// add relaxed allocation desc to the pNext chain
711-
*(void **)lastNext = &relaxed_device_allocation_desc_copy;
712-
lastNext = &relaxed_device_allocation_desc_copy.pNext;
717+
*(void **)lastNext = &relaxed_allocation_desc_copy;
718+
lastNext = &relaxed_allocation_desc_copy.pNext;
713719
}
714720

715721
// check if the allocation should use import / export mechanism
@@ -734,7 +740,7 @@ static umf_result_t ze_memory_provider_alloc_helper(void *provider, size_t size,
734740
ze_device_mem_alloc_desc_t dev_desc = {
735741
.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC,
736742
.pNext = use_relaxed_allocation(ze_provider, size)
737-
? &relaxed_device_allocation_desc
743+
? &relaxed_allocation_desc
738744
: NULL,
739745
.flags = 0,
740746
.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
@@ -568,6 +568,13 @@ TEST(umfLevelZeroProviderOps, default_name_null_handle) {
568568
}
569569

570570
TEST_P(umfLevelZeroProviderTest, allocInvalidSize) {
571+
if (GetParam() == UMF_MEMORY_TYPE_HOST) {
572+
// For host memory, even with relaxed limits, the allocation may
573+
// succeed or fail depending on the system's available memory,
574+
// so we skip this test for host memory type.
575+
GTEST_SKIP() << "Skipping test for host memory type.";
576+
}
577+
571578
umf_memory_provider_handle_t provider = nullptr;
572579
umf_result_t umf_result = umfMemoryProviderCreate(
573580
umfLevelZeroMemoryProviderOps(), params, &provider);
@@ -577,6 +584,7 @@ TEST_P(umfLevelZeroProviderTest, allocInvalidSize) {
577584
void *ptr = nullptr;
578585
umf_result = umfMemoryProviderAlloc(
579586
provider, std::numeric_limits<size_t>::max(), 0, &ptr);
587+
580588
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC);
581589
const char *message;
582590
int32_t error;

0 commit comments

Comments
 (0)