diff --git a/conformance_tests/core/test_ipc/src/test_ipc_memory.cpp b/conformance_tests/core/test_ipc/src/test_ipc_memory.cpp index c1777294..9218b38b 100644 --- a/conformance_tests/core/test_ipc/src/test_ipc_memory.cpp +++ b/conformance_tests/core/test_ipc/src/test_ipc_memory.cpp @@ -111,10 +111,10 @@ static void run_ipc_mem_access_test(ipc_mem_access_test_t test_type, } #endif // __linux__ -static void run_ipc_mem_access_test_opaque(ipc_mem_access_test_t test_type, - size_t size, bool reserved, - ze_ipc_memory_flags_t flags, - bool is_immediate) { +static void run_ipc_dev_mem_access_test_opaque(ipc_mem_access_test_t test_type, + size_t size, bool reserved, + ze_ipc_memory_flags_t flags, + bool is_immediate) { ze_result_t result = zeInit(0); if (result != ZE_RESULT_SUCCESS) { throw std::runtime_error("Parent zeInit failed: " + @@ -196,6 +196,71 @@ static void run_ipc_mem_access_test_opaque(ipc_mem_access_test_t test_type, lzt::destroy_context(context); } +static void run_ipc_host_mem_access_test_opaque(size_t size, + ze_ipc_memory_flags_t flags) { + ze_result_t result = zeInit(0); + if (result != ZE_RESULT_SUCCESS) { + throw std::runtime_error("Parent zeInit failed: " + + level_zero_tests::to_string(result)); + } + LOG_DEBUG << "[Parent] Driver initialized\n"; + lzt::print_platform_overview(); + + // Ensure shared memory object is removed in case it already exists + // -- can happen if previous test exited abnormally + bipc::shared_memory_object::remove("ipc_memory_test"); + + ze_ipc_mem_handle_t ipc_handle = {}; + + auto driver = lzt::get_default_driver(); + auto context = lzt::create_context(driver); + auto device = lzt::zeDevice::get_instance()->get_device(); + + void *buffer = lzt::allocate_host_memory(size, 1, context); + memset(buffer, 0, size); + lzt::write_data_pattern(buffer, size, 1); + + ASSERT_ZE_RESULT_SUCCESS(zeMemGetIpcHandle(context, buffer, &ipc_handle)); + + ze_ipc_mem_handle_t ipc_handle_zero{}; + ASSERT_NE(0, memcmp((void *)&ipc_handle, (void *)&ipc_handle_zero, + sizeof(ipc_handle))); + + // Launch child +#ifdef _WIN32 + std::string helper_path = ".\\ipc\\test_ipc_memory_helper.exe"; +#else + std::string helper_path = "./ipc/test_ipc_memory_helper"; +#endif + boost::process::child c; + try { + c = boost::process::child(helper_path); + } catch (const boost::process::process_error &e) { + std::cerr << "Failed to launch child process: " << e.what() << std::endl; + throw; + } + + bipc::shared_memory_object shm(bipc::create_only, "ipc_memory_test", + bipc::read_write); + shm.truncate(sizeof(shared_data_t)); + bipc::mapped_region region(shm, bipc::read_write); + + // Copy ipc handle data to shm + shared_data_t test_data = { + TEST_HOST_ACCESS, TEST_NONSOCK, to_u32(size), flags, false, ipc_handle}; + std::memcpy(region.get_address(), &test_data, sizeof(shared_data_t)); + + // Free device memory once receiver is done + c.wait(); + EXPECT_EQ(c.exit_code(), 0); + + ASSERT_ZE_RESULT_SUCCESS(zeMemPutIpcHandle(context, ipc_handle)); + bipc::shared_memory_object::remove("ipc_memory_test"); + + lzt::free_memory(context, buffer); + lzt::destroy_context(context); +} + #ifdef __linux__ LZT_TEST( IpcMemoryAccessTest, @@ -271,71 +336,83 @@ LZT_TEST( LZT_TEST( IpcMemoryAccessTestOpaqueIpcHandle, GivenL0MemoryAllocatedInChildProcessWhenUsingL0IPCThenParentProcessReadsMemoryCorrectly) { - run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, false, - ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, false); + run_ipc_dev_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, false, + ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, false); } LZT_TEST( IpcMemoryAccessTestOpaqueIpcHandle, GivenL0MemoryAllocatedInChildProcessWhenUsingL0IPCOnImmediateCmdListThenParentProcessReadsMemoryCorrectly) { - run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, false, - ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true); + run_ipc_dev_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, false, + ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true); } LZT_TEST( IpcMemoryAccessTestOpaqueIpcHandle, GivenL0MemoryAllocatedInChildProcessBiasCachedWhenUsingL0IPCThenParentProcessReadsMemoryCorrectly) { - run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, false, - ZE_IPC_MEMORY_FLAG_BIAS_CACHED, false); + run_ipc_dev_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, false, + ZE_IPC_MEMORY_FLAG_BIAS_CACHED, false); } LZT_TEST( IpcMemoryAccessTestOpaqueIpcHandle, GivenL0MemoryAllocatedInChildProcessBiasCachedWhenUsingL0IPCOnImmediateCmdListThenParentProcessReadsMemoryCorrectly) { - run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, false, - ZE_IPC_MEMORY_FLAG_BIAS_CACHED, true); + run_ipc_dev_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, false, + ZE_IPC_MEMORY_FLAG_BIAS_CACHED, true); } LZT_TEST( IpcMemoryAccessTestOpaqueIpcHandle, GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessWhenUsingL0IPCThenChildProcessReadsMemoryCorrectly) { - run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, true, - ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, false); + run_ipc_dev_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, true, + ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, false); } LZT_TEST( IpcMemoryAccessTestOpaqueIpcHandle, GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectly) { - run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, true, - ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true); + run_ipc_dev_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, true, + ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true); } LZT_TEST( IpcMemoryAccessTestOpaqueIpcHandle, GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessBiasCachedWhenUsingL0IPCThenChildProcessReadsMemoryCorrectly) { - run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, true, - ZE_IPC_MEMORY_FLAG_BIAS_CACHED, false); + run_ipc_dev_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, true, + ZE_IPC_MEMORY_FLAG_BIAS_CACHED, false); } LZT_TEST( IpcMemoryAccessTestOpaqueIpcHandle, GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessBiasCachedWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectly) { - run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, true, - ZE_IPC_MEMORY_FLAG_BIAS_CACHED, true); + run_ipc_dev_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, true, + ZE_IPC_MEMORY_FLAG_BIAS_CACHED, true); } LZT_TEST( IpcMemoryAccessTestOpaqueIpcHandleSubDevice, GivenL0PhysicalMemoryAllocatedReservedInParentProcessWhenUsingL0IPCThenChildProcessReadsMemoryCorrectlyUsingSubDeviceQueue) { - run_ipc_mem_access_test_opaque(TEST_SUBDEVICE_ACCESS, 4096, true, - ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, false); + run_ipc_dev_mem_access_test_opaque(TEST_SUBDEVICE_ACCESS, 4096, true, + ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, false); } LZT_TEST( IpcMemoryAccessTestOpaqueIpcHandleSubDevice, GivenL0PhysicalMemoryAllocatedReservedInParentProcessWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectlyUsingSubDeviceQueue) { - run_ipc_mem_access_test_opaque(TEST_SUBDEVICE_ACCESS, 4096, true, - ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true); + run_ipc_dev_mem_access_test_opaque(TEST_SUBDEVICE_ACCESS, 4096, true, + ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true); +} + +LZT_TEST( + IpcMemoryAccessTestOpaqueIpcHandle, + GivenUncachedHostMemoryAllocatedInParentProcessThenChildProcessReadsMemoryCorrectly) { + run_ipc_host_mem_access_test_opaque(4096, ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED); +} + +LZT_TEST( + IpcMemoryAccessTestOpaqueIpcHandle, + GivenCachedHostMemoryAllocatedInParentProcessThenChildProcessReadsMemoryCorrectly) { + run_ipc_host_mem_access_test_opaque(4096, ZE_IPC_MEMORY_FLAG_BIAS_CACHED); } } // namespace diff --git a/conformance_tests/core/test_ipc/src/test_ipc_memory.hpp b/conformance_tests/core/test_ipc/src/test_ipc_memory.hpp index b656cc5c..3bfdef9f 100644 --- a/conformance_tests/core/test_ipc/src/test_ipc_memory.hpp +++ b/conformance_tests/core/test_ipc/src/test_ipc_memory.hpp @@ -11,7 +11,8 @@ typedef enum { TEST_DEVICE_ACCESS, - TEST_SUBDEVICE_ACCESS + TEST_SUBDEVICE_ACCESS, + TEST_HOST_ACCESS } ipc_mem_access_test_t; typedef enum { TEST_SOCK, TEST_NONSOCK } ipc_mem_access_test_sock_t; diff --git a/conformance_tests/core/test_ipc/src/test_ipc_memory_helper.cpp b/conformance_tests/core/test_ipc/src/test_ipc_memory_helper.cpp index 651eedd3..d6571ccf 100644 --- a/conformance_tests/core/test_ipc/src/test_ipc_memory_helper.cpp +++ b/conformance_tests/core/test_ipc/src/test_ipc_memory_helper.cpp @@ -198,6 +198,30 @@ static void child_subdevice_access_test_opaque(size_t size, } } +static void child_host_access_test_opaque(size_t size, + ze_ipc_memory_flags_t flags, + ze_ipc_mem_handle_t ipc_handle) { + auto driver = lzt::get_default_driver(); + auto context = lzt::create_context(driver); + auto device = lzt::zeDevice::get_instance()->get_device(); + void *buffer = nullptr; + + EXPECT_ZE_RESULT_SUCCESS( + zeMemOpenIpcHandle(context, device, ipc_handle, flags, &buffer)); + + LOG_DEBUG << "[Child] Validating buffer received correctly"; + lzt::validate_data_pattern(buffer, size, 1); + + EXPECT_ZE_RESULT_SUCCESS(zeMemCloseIpcHandle(context, buffer)); + lzt::destroy_context(context); + + if (::testing::Test::HasFailure()) { + exit(1); + } else { + exit(0); + } +} + int main() { ze_result_t result = zeInit(0); if (result != ZE_RESULT_SUCCESS) { @@ -233,8 +257,8 @@ int main() { child_device_access_test_opaque(shared_data.size, shared_data.flags, shared_data.is_immediate, shared_data.ipc_handle); - } else { #ifdef __linux__ + } else { child_device_access_test(shared_data.size, shared_data.flags, shared_data.is_immediate); #endif @@ -249,6 +273,10 @@ int main() { break; // Currently supporting only device access test scenario } break; + case TEST_HOST_ACCESS: + child_host_access_test_opaque(shared_data.size, shared_data.flags, + shared_data.ipc_handle); + break; default: LOG_DEBUG << "Unrecognized test case"; exit(1); diff --git a/scripts/level_zero_report_utils.py b/scripts/level_zero_report_utils.py index 162a026c..3a688110 100644 --- a/scripts/level_zero_report_utils.py +++ b/scripts/level_zero_report_utils.py @@ -290,6 +290,8 @@ def assign_test_feature_tag(test_feature: str, test_name: str, test_section: str (re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandle_GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessBiasCachedWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \ (re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandleSubDevice_GivenL0PhysicalMemoryAllocatedReservedInParentProcessWhenUsingL0IPCThenChildProcessReadsMemoryCorrectlyUsingSubDeviceQueue', test_name, re.IGNORECASE)) or \ (re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandleSubDevice_GivenL0PhysicalMemoryAllocatedReservedInParentProcessWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectlyUsingSubDeviceQueue', test_name, re.IGNORECASE)) or \ + (re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandle_GivenUncachedHostMemoryAllocatedInParentProcessThenChildProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \ + (re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandle_GivenCachedHostMemoryAllocatedInParentProcessThenChildProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \ (re.search('L0_CTS_zeDeviceGetMemoryPropertiesTests_GivenValidDeviceWhenRetrievingMemoryPropertiesThenValidExtPropertiesAreReturned', test_name, re.IGNORECASE)) or \ (re.search('L0_CTS_zeKernelCreateTests_GivenValidFunctionWhenGettingSourceAttributeThenReturnAttributeString', test_name, re.IGNORECASE)) or \ (re.search('L0_CTS_zeKernelGetNameTests_GivenKernelGetNameCorrectNameIsReturned', test_name, re.IGNORECASE)) or \