Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add physical system memory tests 1/n #114

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
143 changes: 111 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 All @@ -15,6 +15,10 @@
#include "test_harness/test_harness.hpp"
#include "logging/logging.hpp"

#ifdef __linux__
#include <unistd.h>
#endif

namespace lzt = level_zero_tests;

#include <level_zero/ze_api.h>
Expand All @@ -35,7 +39,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 +139,36 @@ 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) {
#ifdef __linux__
pageSize = sysconf(_SC_PAGE_SIZE);
allocationSize = lzt::create_page_aligned_size(allocationSize, pageSize);
lzt::physical_host_memory_allocation(context, allocationSize,
&reservedPhysicalHostMemory);
lyu marked this conversation as resolved.
Show resolved Hide resolved
lzt::physical_memory_destroy(context, reservedPhysicalHostMemory);
#else
GTEST_SKIP() << "Physical host memory is unsupported on Windows";
#endif
}

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);
#ifdef __linux__
lzt::physical_host_memory_allocation(context, allocationSize,
&reservedPhysicalHostMemory);
#endif
lzt::virtual_memory_reservation(context, nullptr, allocationSize,
&reservedVirtualMemory);
EXPECT_NE(nullptr, reservedVirtualMemory);
Expand All @@ -156,33 +179,62 @@ 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);
}
#ifdef __linux__
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);
#endif
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) {
#ifdef __linux__
test.pageSize = sysconf(_SC_PAGE_SIZE);
#endif
} 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 +252,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 +267,37 @@ 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) {
#ifdef __linux__
RunGivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualMemory(
*this, true, false);
#else
GTEST_SKIP() << "Physical host memory is unsupported on Windows";
#endif
}

TEST_F(
zeVirtualMemoryTests,
GivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualHostMemoryOnImmediateCommandListSucceeds) {
#ifdef __linux__
RunGivenMappedReadWriteMemoryThenFillAndCopyWithMappedVirtualMemory(
*this, true, true);
#else
GTEST_SKIP() << "Physical host memory is unsupported on Windows";
#endif
}

void RunGivenMappedMultiplePhysicalMemoryAcrossAvailableDevicesWhenFillAndCopyWithSingleMappedVirtualMemory(
Expand All @@ -242,9 +321,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 +409,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 +577,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