Skip to content
Draft
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
130 changes: 130 additions & 0 deletions conformance_tests/core/test_p2p/src/test_p2p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,4 +1316,134 @@ INSTANTIATE_TEST_SUITE_P(
1021, 2043),
::testing::Bool()));

struct SharedSystemP2PTests
: public ::testing::TestWithParam<bool> {
void SetUp() override {
auto driver = lzt::get_default_driver();
auto context = lzt::get_default_context();
auto devices = lzt::get_ze_devices(driver);

LOG_INFO << "num_devices: " << devices.size();
for (auto dev : devices) {
LOG_INFO << "dev supports alloc: " << lzt::supports_shared_system_alloc(dev);
}

if (devices.size() < 2) {
GTEST_SKIP() << "Test requires at least two devices";
}

device = devices[0];
remote_device = devices[1];

ASSERT_TRUE(lzt::can_access_peer(device, remote_device));

bool is_immediate = GetParam();
cmd_bundle = lzt::create_command_bundle(device, is_immediate);

EXPECT_TRUE(lzt::supports_shared_system_alloc(device));
EXPECT_TRUE(lzt::supports_shared_system_alloc(remote_device));
}

void TearDown() override { lzt::destroy_command_bundle(cmd_bundle); }

void run_append_memory_fill_test(void *memory, bool use_madvise) {
if (use_madvise) {
lzt::append_memory_advise(cmd_bundle.list, remote_device, memory, size,
ZE_MEMORY_ADVICE_SET_PREFERRED_LOCATION);
}
uint8_t pattern = 0xAB;
lzt::append_memory_fill(cmd_bundle.list, memory, &pattern, sizeof(pattern),
size, nullptr);

lzt::close_command_list(cmd_bundle.list);
execute_and_sync_command_bundle(cmd_bundle, UINT64_MAX);

uint8_t* memory_as_byte = static_cast<uint8_t*>(memory);
for (size_t i = 0; i < size; i++) {
ASSERT_EQ(memory_as_byte[i], pattern) << "Memory fill did not match.";
}
}

void run_append_memory_copy_test(void* src_memory, void* dst_memory, bool use_madvise_for_src, bool use_madvise_for_dst) {
if (use_madvise_for_src) {
lzt::append_memory_advise(cmd_bundle.list, remote_device, src_memory, size,
ZE_MEMORY_ADVICE_SET_PREFERRED_LOCATION);
}
if (use_madvise_for_dst) {
lzt::append_memory_advise(cmd_bundle.list, remote_device, dst_memory, size,
ZE_MEMORY_ADVICE_SET_PREFERRED_LOCATION);
}
lzt::append_memory_copy(cmd_bundle.list, dst_memory, src_memory, size);

lzt::close_command_list(cmd_bundle.list);
execute_and_sync_command_bundle(cmd_bundle, UINT64_MAX);

uint8_t* src_memory_as_byte = static_cast<uint8_t*>(src_memory);
uint8_t* dst_memory_as_byte = static_cast<uint8_t*>(dst_memory);
for (size_t i = 0; i < size; i++) {
ASSERT_EQ(src_memory_as_byte[i], dst_memory_as_byte[i]) << "Memory copy did not match.";
}
}

void run_append_memory_copy_region_test() {}

void run_append_memory_image_copy_test() {}

static constexpr size_t size = 1024;
ze_device_handle_t device, remote_device;
lzt::zeCommandBundle cmd_bundle;
};

LZT_TEST_P(
SharedSystemP2PTests,
GivenMultipleDevicesAndSharedSystemMemoryWhenAppendingMemoryFillThenIsSuccessAndValuesAreCorrect) {
void *memory = lzt::aligned_malloc(size, 1);
run_append_memory_fill_test(memory, false);
lzt::aligned_free(memory);
}

LZT_TEST_P(
SharedSystemP2PTests,
GivenMultipleDevicesAndSharedSystemMemoryAdvisedToRemoteDeviceWhenAppendingMemoryFillThenIsSuccessAndValuesAreCorrect) {
void *memory = lzt::aligned_malloc(size, 1);
run_append_memory_fill_test(memory, true);
lzt::aligned_free(memory);
}

LZT_TEST_P(
SharedSystemP2PTests,
GivenMultipleDevicesAndSrcSharedSystemMemoryAdvisedToRemoteDeviceWhenAppendingMemoryCopyThenIsSuccessAndValuesAreCorrect) {
void *src_memory = lzt::aligned_malloc(size, 1);
void *dst_memory = lzt::aligned_malloc(size, 1);
memset(src_memory, 0xAB, size);
run_append_memory_copy_test(src_memory, dst_memory, true, false);
lzt::aligned_free(src_memory);
lzt::aligned_free(dst_memory);
}

LZT_TEST_P(
SharedSystemP2PTests,
GivenMultipleDevicesAndDstSharedSystemMemoryAdvisedToRemoteDeviceWhenAppendingMemoryCopyThenIsSuccessAndValuesAreCorrect) {
void *src_memory = lzt::aligned_malloc(size, 1);
void *dst_memory = lzt::aligned_malloc(size, 1);
memset(src_memory, 0xAB, size);
run_append_memory_copy_test(src_memory, dst_memory, false, true);
lzt::aligned_free(src_memory);
lzt::aligned_free(dst_memory);
}

LZT_TEST_P(
SharedSystemP2PTests,
GivenMultipleDevicesAndSrcAndDstSharedSystemMemoryAdvisedToRemoteDeviceWhenAppendingMemoryCopyThenIsSuccessAndValuesAreCorrect) {
void *src_memory = lzt::aligned_malloc(size, 1);
void *dst_memory = lzt::aligned_malloc(size, 1);
memset(src_memory, 0xAB, size);
run_append_memory_copy_test(src_memory, dst_memory, true, true);
lzt::aligned_free(src_memory);
lzt::aligned_free(dst_memory);
}

INSTANTIATE_TEST_SUITE_P(
SharedSystemP2PTestParam, SharedSystemP2PTests, ::testing::Bool());

} // namespace