Skip to content

Commit

Permalink
feature: add physical system memory tests 1/n
Browse files Browse the repository at this point in the history
Related-To: NEO-11981

Signed-off-by: Wenbin Lu <[email protected]>
  • Loading branch information
lyu committed Nov 22, 2024
1 parent 0f06586 commit 0b58b49
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 100 deletions.
6 changes: 3 additions & 3 deletions conformance_tests/core/test_ipc/src/test_ipc_memory.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -63,8 +63,8 @@ static void run_ipc_mem_access_test(ipc_mem_access_test_t test_type, int size,
ze_physical_mem_handle_t reservedPhysicalMemory = {};
void *memory = nullptr;
if (reserved) {
memory = lzt::reserve_allocate_and_map_memory(context, device, allocSize,
&reservedPhysicalMemory);
memory = lzt::reserve_allocate_and_map_device_memory(
context, device, allocSize, &reservedPhysicalMemory);
} else {
memory = lzt::allocate_device_memory(size, 1, 0, context);
}
Expand Down
6 changes: 3 additions & 3 deletions conformance_tests/core/test_ipc/src/test_ipc_multidevice.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -70,8 +70,8 @@ void multi_device_sender(size_t size, bool reserved, bool is_immediate) {
ze_physical_mem_handle_t reservedPhysicalMemory = {};
void *memory = nullptr;
if (reserved) {
memory = lzt::reserve_allocate_and_map_memory(context, device, allocSize,
&reservedPhysicalMemory);
memory = lzt::reserve_allocate_and_map_device_memory(
context, device, allocSize, &reservedPhysicalMemory);
} else {
memory = lzt::allocate_device_memory(size, 1, flags, device, context);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -85,8 +85,8 @@ void multi_sub_device_sender(size_t size, bool reserved, bool is_immediate) {
ze_physical_mem_handle_t reservedPhysicalMemory = {};
void *memory = nullptr;
if (reserved) {
memory = lzt::reserve_allocate_and_map_memory(context, device, allocSize,
&reservedPhysicalMemory);
memory = lzt::reserve_allocate_and_map_device_memory(
context, device, allocSize, &reservedPhysicalMemory);
} else {
memory = lzt::allocate_device_memory(size, 1, flags, device, context);
}
Expand Down
4 changes: 2 additions & 2 deletions conformance_tests/core/test_ipc/src/test_ipc_put_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ static void run_ipc_put_handle_test(ipc_put_mem_access_test_t test_type,
ze_physical_mem_handle_t reservedPhysicalMemory = {};
void *memory = nullptr;
if (reserved) {
memory = lzt::reserve_allocate_and_map_memory(context, device, allocSize,
&reservedPhysicalMemory);
memory = lzt::reserve_allocate_and_map_device_memory(
context, device, allocSize, &reservedPhysicalMemory);
} else {
memory = lzt::allocate_device_memory(size, 1, 0, context);
}
Expand Down
121 changes: 89 additions & 32 deletions conformance_tests/core/test_memory/src/test_virtual_memory.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2022-2023 Intel Corporation
* Copyright (C) 2022-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -35,7 +35,8 @@ class zeVirtualMemoryTests : public ::testing::Test {
size_t pageSize = 0;
size_t allocationSize = (1024 * 1024);
void *reservedVirtualMemory = nullptr;
ze_physical_mem_handle_t reservedPhysicalMemory;
ze_physical_mem_handle_t reservedPhysicalDeviceMemory = nullptr;
ze_physical_mem_handle_t reservedPhysicalHostMemory = nullptr;
};

TEST_F(zeVirtualMemoryTests,
Expand Down Expand Up @@ -134,18 +135,30 @@ TEST_F(zeVirtualMemoryTests,
GivenPageAlignedSizeThenVirtualAndPhysicalMemoryReservedSuccessfully) {
lzt::query_page_size(context, device, allocationSize, &pageSize);
allocationSize = lzt::create_page_aligned_size(allocationSize, pageSize);
lzt::physical_memory_allocation(context, device, allocationSize,
&reservedPhysicalMemory);
lzt::physical_memory_destroy(context, reservedPhysicalMemory);
lzt::physical_device_memory_allocation(context, device, allocationSize,
&reservedPhysicalDeviceMemory);
lzt::physical_memory_destroy(context, reservedPhysicalDeviceMemory);
}

TEST_F(
zeVirtualMemoryTests,
GivenPageAlignedSizeThenVirtualAndPhysicalHostMemoryReservedSuccessfully) {
lzt::query_page_size(context, device, allocationSize, &pageSize);
allocationSize = lzt::create_page_aligned_size(allocationSize, pageSize);
lzt::physical_host_memory_allocation(context, allocationSize,
&reservedPhysicalHostMemory);
lzt::physical_memory_destroy(context, reservedPhysicalHostMemory);
}

TEST_F(
zeVirtualMemoryTests,
GivenPageAlignedSizeThenPhysicalMemoryisSuccessfullyReservedForAllAccessTypes) {
lzt::query_page_size(context, device, allocationSize, &pageSize);
allocationSize = lzt::create_page_aligned_size(allocationSize, pageSize);
lzt::physical_memory_allocation(context, device, allocationSize,
&reservedPhysicalMemory);
lzt::physical_device_memory_allocation(context, device, allocationSize,
&reservedPhysicalDeviceMemory);
lzt::physical_host_memory_allocation(context, allocationSize,
&reservedPhysicalHostMemory);
lzt::virtual_memory_reservation(context, nullptr, allocationSize,
&reservedVirtualMemory);
EXPECT_NE(nullptr, reservedVirtualMemory);
Expand All @@ -156,33 +169,58 @@ TEST_F(

for (auto accessFlags : memoryAccessFlags) {
lzt::virtual_memory_map(context, reservedVirtualMemory, allocationSize,
reservedPhysicalMemory, 0, accessFlags);
reservedPhysicalDeviceMemory, 0, accessFlags);
lzt::virtual_memory_unmap(context, reservedVirtualMemory, allocationSize);
}
for (auto accessFlags : memoryAccessFlags) {
lzt::virtual_memory_map(context, reservedVirtualMemory, allocationSize,
reservedPhysicalHostMemory, 0, accessFlags);
lzt::virtual_memory_unmap(context, reservedVirtualMemory, allocationSize);
}

lzt::physical_memory_destroy(context, reservedPhysicalMemory);
lzt::physical_memory_destroy(context, reservedPhysicalHostMemory);
lzt::physical_memory_destroy(context, reservedPhysicalDeviceMemory);
lzt::virtual_memory_free(context, reservedVirtualMemory, allocationSize);
}

void RunGivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualMemory(
zeVirtualMemoryTests &test, bool is_immediate) {
zeVirtualMemoryTests &test, bool is_host_memory, bool is_immediate) {
auto bundle = lzt::create_command_bundle(test.device, is_immediate);

lzt::query_page_size(test.context, test.device, test.allocationSize,
&test.pageSize);
if (is_host_memory) {
test.pageSize = 1UL << 21;
} else {
lzt::query_page_size(test.context, test.device, test.allocationSize,
&test.pageSize);
}

test.allocationSize =
lzt::create_page_aligned_size(test.allocationSize, test.pageSize);
lzt::physical_memory_allocation(test.context, test.device,
test.allocationSize,
&test.reservedPhysicalMemory);
lzt::virtual_memory_reservation(test.context, nullptr, test.allocationSize,
&test.reservedVirtualMemory);

EXPECT_NE(nullptr, test.reservedVirtualMemory);
if (is_host_memory) {
lzt::physical_host_memory_allocation(test.context, test.allocationSize,
&test.reservedPhysicalHostMemory);
EXPECT_NE(nullptr, test.reservedPhysicalHostMemory);
ASSERT_EQ(zeVirtualMemMap(test.context, test.reservedVirtualMemory,
test.allocationSize,
test.reservedPhysicalHostMemory, 0,
ZE_MEMORY_ACCESS_ATTRIBUTE_READWRITE),
ZE_RESULT_SUCCESS);
} else {
lzt::physical_device_memory_allocation(test.context, test.device,
test.allocationSize,
&test.reservedPhysicalDeviceMemory);
EXPECT_NE(nullptr, test.reservedPhysicalDeviceMemory);
ASSERT_EQ(zeVirtualMemMap(test.context, test.reservedVirtualMemory,
test.allocationSize,
test.reservedPhysicalDeviceMemory, 0,
ZE_MEMORY_ACCESS_ATTRIBUTE_READWRITE),
ZE_RESULT_SUCCESS);
}

ASSERT_EQ(zeVirtualMemMap(test.context, test.reservedVirtualMemory,
test.allocationSize, test.reservedPhysicalMemory, 0,
ZE_MEMORY_ACCESS_ATTRIBUTE_READWRITE),
ZE_RESULT_SUCCESS);
int8_t pattern = 9;
void *memory =
lzt::allocate_shared_memory(test.allocationSize, test.pageSize);
Expand All @@ -200,7 +238,12 @@ void RunGivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualMemory(

lzt::virtual_memory_unmap(test.context, test.reservedVirtualMemory,
test.allocationSize);
lzt::physical_memory_destroy(test.context, test.reservedPhysicalMemory);
if (is_host_memory) {
lzt::physical_memory_destroy(test.context, test.reservedPhysicalHostMemory);
} else {
lzt::physical_memory_destroy(test.context,
test.reservedPhysicalDeviceMemory);
}
lzt::virtual_memory_free(test.context, test.reservedVirtualMemory,
test.allocationSize);
lzt::free_memory(memory);
Expand All @@ -210,15 +253,29 @@ void RunGivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualMemory(
TEST_F(
zeVirtualMemoryTests,
GivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualMemorySucceeds) {
RunGivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualMemory(*this,
false);
RunGivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualMemory(
*this, false, false);
}

TEST_F(
zeVirtualMemoryTests,
GivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualMemoryOnImmediateCommandListSucceeds) {
RunGivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualMemory(*this,
true);
RunGivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualMemory(
*this, false, true);
}

TEST_F(
zeVirtualMemoryTests,
GivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualHostMemorySucceeds) {
RunGivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualMemory(
*this, true, false);
}

TEST_F(
zeVirtualMemoryTests,
GivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualHostMemoryOnImmediateCommandListSucceeds) {
RunGivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualMemory(
*this, true, true);
}

void RunGivenMappedMultiplePhysicalMemoryAcrossAvailableDevicesWhenFillAndCopyWithSingleMappedVirtualMemory(
Expand All @@ -242,9 +299,9 @@ void RunGivenMappedMultiplePhysicalMemoryAcrossAvailableDevicesWhenFillAndCopyWi
test.allocationSize =
lzt::create_page_aligned_size(test.allocationSize, test.pageSize);
for (int i = 0; i < devices.size(); i++) {
lzt::physical_memory_allocation(test.context, devices[i],
test.allocationSize,
&reservedPhysicalMemoryArray[i]);
lzt::physical_device_memory_allocation(test.context, devices[i],
test.allocationSize,
&reservedPhysicalMemoryArray[i]);
}

size_t totalAllocationSize = test.allocationSize * devices.size();
Expand Down Expand Up @@ -330,9 +387,9 @@ void RunGivenVirtualMemoryMappedToMultipleAllocationsWhenFullAddressUsageInKerne
test.allocationSize =
lzt::create_page_aligned_size(test.allocationSize, test.pageSize);
for (int i = 0; i < devices.size(); i++) {
lzt::physical_memory_allocation(test.context, devices[i],
test.allocationSize,
&reservedPhysicalMemoryArray[i]);
lzt::physical_device_memory_allocation(test.context, devices[i],
test.allocationSize,
&reservedPhysicalMemoryArray[i]);
}
size_t totalAllocationSize = test.allocationSize * devices.size();
size_t virtualReservationSize = lzt::nextPowerOfTwo(totalAllocationSize);
Expand Down Expand Up @@ -498,8 +555,8 @@ void dataCheckMemoryReservations(enum MemoryReservationTestType type,
lzt::query_page_size(context, rootDevice, allocationSize, &pageSize);
allocationSize = lzt::create_page_aligned_size(allocationSize, pageSize);
for (int i = 0; i < devices.size(); i++) {
lzt::physical_memory_allocation(context, devices[i], allocationSize,
&reservedPhysicalMemory[i]);
lzt::physical_device_memory_allocation(context, devices[i], allocationSize,
&reservedPhysicalMemory[i]);
}
size_t virtualReservationSize =
lzt::nextPowerOfTwo(allocationSize * devices.size());
Expand Down
14 changes: 7 additions & 7 deletions conformance_tests/core/test_p2p/src/test_p2p.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2019-2023 Intel Corporation
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -56,10 +56,10 @@ class zeP2PTests : public ::testing::Test,
mem_size_ =
lzt::create_page_aligned_size(mem_size_ + offset_, pageSize);
offset_ = 0;
lzt::physical_memory_allocation(context, device, mem_size_,
&instance.src_physical_region);
lzt::physical_memory_allocation(context, device, mem_size_,
&instance.dst_physical_region);
lzt::physical_device_memory_allocation(context, device, mem_size_,
&instance.src_physical_region);
lzt::physical_device_memory_allocation(context, device, mem_size_,
&instance.dst_physical_region);
lzt::virtual_memory_reservation(context, nullptr, mem_size_,
&instance.src_region);
EXPECT_NE(nullptr, instance.src_region);
Expand Down Expand Up @@ -103,10 +103,10 @@ class zeP2PTests : public ::testing::Test,
mem_size_ =
lzt::create_page_aligned_size(mem_size_ + offset_, pageSize);
offset_ = 0;
lzt::physical_memory_allocation(
lzt::physical_device_memory_allocation(
context, sub_device, mem_size_,
&sub_device_instance.src_physical_region);
lzt::physical_memory_allocation(
lzt::physical_device_memory_allocation(
context, sub_device, mem_size_,
&sub_device_instance.dst_physical_region);
lzt::virtual_memory_reservation(context, nullptr, mem_size_,
Expand Down
4 changes: 2 additions & 2 deletions conformance_tests/core/test_p2p/src/test_p2p_mem_access.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2019 Intel Corporation
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -249,7 +249,7 @@ class zeP2PMemAccessTests
dev_access_[std::max(static_cast<uint32_t>(1), (num - 1))].dev,
mem_size_, &pageSize);
mem_size_ = lzt::create_page_aligned_size(mem_size_, pageSize);
lzt::physical_memory_allocation(
lzt::physical_device_memory_allocation(
lzt::get_default_context(),
dev_access_[std::max(static_cast<uint32_t>(1), (num - 1))].dev,
mem_size_, &dev_access_[0].device_mem_remote_physical);
Expand Down
Loading

0 comments on commit 0b58b49

Please sign in to comment.