Skip to content

Commit f182259

Browse files
Jaime ArteagaCompute-Runtime-Automation
authored andcommitted
Return user size on zeMemGetAddressRange
Signed-off-by: Jaime Arteaga <[email protected]>
1 parent 8030b70 commit f182259

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

level_zero/core/source/context/context_imp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -393,7 +393,7 @@ ze_result_t ContextImp::getMemAddressRange(const void *ptr,
393393
}
394394

395395
if (pSize) {
396-
*pSize = alloc->getUnderlyingBufferSize();
396+
*pSize = allocData->size;
397397
}
398398

399399
return ZE_RESULT_SUCCESS;

level_zero/core/test/unit_tests/sources/memory/test_memory.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,6 +3111,30 @@ TEST_F(ContextMemoryTest, whenRetrievingAddressRangeForDeviceAllocationThenRange
31113111
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
31123112
}
31133113

3114+
TEST_F(ContextMemoryTest, whenRetrievingSizeForDeviceAllocationThenUserSizeIsReturned) {
3115+
size_t allocSize = 100;
3116+
size_t alignment = 1u;
3117+
void *allocPtr = nullptr;
3118+
3119+
ze_device_mem_alloc_desc_t deviceDesc = {};
3120+
ze_result_t result = context->allocDeviceMem(device->toHandle(),
3121+
&deviceDesc,
3122+
allocSize, alignment, &allocPtr);
3123+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
3124+
EXPECT_NE(nullptr, allocPtr);
3125+
3126+
void *base = nullptr;
3127+
size_t size = 0u;
3128+
void *pPtr = reinterpret_cast<void *>(reinterpret_cast<uint64_t>(allocPtr) + 77);
3129+
result = context->getMemAddressRange(pPtr, &base, &size);
3130+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
3131+
EXPECT_EQ(base, allocPtr);
3132+
EXPECT_EQ(size, allocSize);
3133+
3134+
result = context->freeMem(allocPtr);
3135+
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
3136+
}
3137+
31143138
TEST_F(ContextMemoryTest, whenRetrievingAddressRangeForDeviceAllocationWithNoBaseArgumentThenSizeIsCorrectAndSuccessIsReturned) {
31153139
size_t allocSize = 4096u;
31163140
size_t alignment = 1u;

0 commit comments

Comments
 (0)