Introduce debug flag ForceExtendedUSMBufferSize usage for L0

Forces extended buffer size by adding pageSize specify by number when
debug flag is >=1 in L0 USM calls

Usage:
ForceExtendedUSMBufferSize=2
size += (2 * pageSize)

Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com>
This commit is contained in:
Krzysztof Gibala
2022-02-07 16:10:45 +00:00
committed by Compute-Runtime-Automation
parent a95198521e
commit f7a5d29085
3 changed files with 68 additions and 1 deletions

View File

@@ -57,6 +57,9 @@ ze_result_t ContextImp::allocHostMem(const ze_host_mem_alloc_desc_t *hostDesc,
size_t size,
size_t alignment,
void **ptr) {
if (NEO::DebugManager.flags.ForceExtendedUSMBufferSize.get() >= 1) {
size += (MemoryConstants::pageSize * NEO::DebugManager.flags.ForceExtendedUSMBufferSize.get());
}
bool relaxedSizeAllowed = NEO::DebugManager.flags.AllowUnrestrictedSize.get();
if (hostDesc->pNext) {
@@ -104,6 +107,9 @@ ze_result_t ContextImp::allocDeviceMem(ze_device_handle_t hDevice,
const ze_device_mem_alloc_desc_t *deviceDesc,
size_t size,
size_t alignment, void **ptr) {
if (NEO::DebugManager.flags.ForceExtendedUSMBufferSize.get() >= 1) {
size += (MemoryConstants::pageSize * NEO::DebugManager.flags.ForceExtendedUSMBufferSize.get());
}
auto device = Device::fromHandle(hDevice);
if (isDeviceDefinedForThisContext(device) == false) {
@@ -185,6 +191,9 @@ ze_result_t ContextImp::allocSharedMem(ze_device_handle_t hDevice,
size_t size,
size_t alignment,
void **ptr) {
if (NEO::DebugManager.flags.ForceExtendedUSMBufferSize.get() >= 1) {
size += (MemoryConstants::pageSize * NEO::DebugManager.flags.ForceExtendedUSMBufferSize.get());
}
auto device = this->devices.begin()->second;
if (hDevice != nullptr) {

View File

@@ -277,6 +277,64 @@ TEST_F(MemoryTest, givenSharedPointerThenDriverGetAllocPropertiesReturnsExpected
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
}
TEST_F(MemoryTest, givenForceExtendedUSMBufferSizeDebugFlagWhenUSMAllocationIsCreatedThenSizeIsProperlyExtended) {
DebugManagerStateRestore restorer;
constexpr auto bufferSize = 16;
auto pageSizeNumber = 2;
NEO::DebugManager.flags.ForceExtendedUSMBufferSize.set(pageSizeNumber);
auto extendedBufferSize = bufferSize + MemoryConstants::pageSize * pageSizeNumber;
size_t alignment = 1u;
void *ptr = nullptr;
ze_device_mem_alloc_desc_t deviceDesc = {};
ze_host_mem_alloc_desc_t hostDesc = {};
ze_result_t result = context->allocSharedMem(device->toHandle(), &deviceDesc,
&hostDesc, bufferSize, alignment, &ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_NE(nullptr, ptr);
auto alloc = context->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr);
EXPECT_NE(alloc, nullptr);
EXPECT_EQ(alloc->size, extendedBufferSize);
result = context->freeMem(ptr);
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
pageSizeNumber = 4;
NEO::DebugManager.flags.ForceExtendedUSMBufferSize.set(pageSizeNumber);
extendedBufferSize = bufferSize + MemoryConstants::pageSize * pageSizeNumber;
hostDesc = {};
result = context->allocHostMem(&hostDesc, bufferSize, alignment, &ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_NE(nullptr, ptr);
alloc = context->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr);
EXPECT_NE(alloc, nullptr);
EXPECT_EQ(alloc->size, extendedBufferSize);
result = context->freeMem(ptr);
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
pageSizeNumber = 8;
NEO::DebugManager.flags.ForceExtendedUSMBufferSize.set(pageSizeNumber);
extendedBufferSize = bufferSize + MemoryConstants::pageSize * pageSizeNumber;
deviceDesc = {};
result = context->allocDeviceMem(device->toHandle(), &deviceDesc, bufferSize, alignment, &ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_NE(nullptr, ptr);
alloc = context->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr);
EXPECT_NE(alloc, nullptr);
EXPECT_EQ(alloc->size, extendedBufferSize);
result = context->freeMem(ptr);
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
}
TEST_F(MemoryTest, givenHostPointerThenDriverGetAllocPropertiesReturnsMemoryId) {
size_t size = 10;
size_t alignment = 1u;