@@ -111,10 +111,10 @@ static void run_ipc_mem_access_test(ipc_mem_access_test_t test_type,
111111}
112112#endif // __linux__
113113
114- static void run_ipc_mem_access_test_opaque (ipc_mem_access_test_t test_type,
115- size_t size, bool reserved,
116- ze_ipc_memory_flags_t flags,
117- bool is_immediate) {
114+ static void run_ipc_dev_mem_access_test_opaque (ipc_mem_access_test_t test_type,
115+ size_t size, bool reserved,
116+ ze_ipc_memory_flags_t flags,
117+ bool is_immediate) {
118118 ze_result_t result = zeInit (0 );
119119 if (result != ZE_RESULT_SUCCESS) {
120120 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,
196196 lzt::destroy_context (context);
197197}
198198
199+ static void run_ipc_host_mem_access_test_opaque (size_t size,
200+ ze_ipc_memory_flags_t flags) {
201+ ze_result_t result = zeInit (0 );
202+ if (result != ZE_RESULT_SUCCESS) {
203+ throw std::runtime_error (" Parent zeInit failed: " +
204+ level_zero_tests::to_string (result));
205+ }
206+ LOG_DEBUG << " [Parent] Driver initialized\n " ;
207+ lzt::print_platform_overview ();
208+
209+ // Ensure shared memory object is removed in case it already exists
210+ // -- can happen if previous test exited abnormally
211+ bipc::shared_memory_object::remove (" ipc_memory_test" );
212+
213+ ze_ipc_mem_handle_t ipc_handle = {};
214+
215+ auto driver = lzt::get_default_driver ();
216+ auto context = lzt::create_context (driver);
217+ auto device = lzt::zeDevice::get_instance ()->get_device ();
218+
219+ void *buffer = lzt::allocate_host_memory (size, 1 , context);
220+ memset (buffer, 0 , size);
221+ lzt::write_data_pattern (buffer, size, 1 );
222+
223+ ASSERT_ZE_RESULT_SUCCESS (zeMemGetIpcHandle (context, buffer, &ipc_handle));
224+
225+ ze_ipc_mem_handle_t ipc_handle_zero{};
226+ ASSERT_NE (0 , memcmp ((void *)&ipc_handle, (void *)&ipc_handle_zero,
227+ sizeof (ipc_handle)));
228+
229+ // Launch child
230+ #ifdef _WIN32
231+ std::string helper_path = " .\\ ipc\\ test_ipc_memory_helper.exe" ;
232+ #else
233+ std::string helper_path = " ./ipc/test_ipc_memory_helper" ;
234+ #endif
235+ boost::process::child c;
236+ try {
237+ c = boost::process::child (helper_path);
238+ } catch (const boost::process::process_error &e) {
239+ std::cerr << " Failed to launch child process: " << e.what () << std::endl;
240+ throw ;
241+ }
242+
243+ bipc::shared_memory_object shm (bipc::create_only, " ipc_memory_test" ,
244+ bipc::read_write);
245+ shm.truncate (sizeof (shared_data_t ));
246+ bipc::mapped_region region (shm, bipc::read_write);
247+
248+ // Copy ipc handle data to shm
249+ shared_data_t test_data = {
250+ TEST_HOST_ACCESS, TEST_NONSOCK, to_u32 (size), flags, false , ipc_handle};
251+ std::memcpy (region.get_address (), &test_data, sizeof (shared_data_t ));
252+
253+ // Free device memory once receiver is done
254+ c.wait ();
255+ EXPECT_EQ (c.exit_code (), 0 );
256+
257+ ASSERT_ZE_RESULT_SUCCESS (zeMemPutIpcHandle (context, ipc_handle));
258+ bipc::shared_memory_object::remove (" ipc_memory_test" );
259+
260+ lzt::free_memory (context, buffer);
261+ lzt::destroy_context (context);
262+ }
263+
199264#ifdef __linux__
200265LZT_TEST (
201266 IpcMemoryAccessTest,
@@ -271,71 +336,83 @@ LZT_TEST(
271336LZT_TEST (
272337 IpcMemoryAccessTestOpaqueIpcHandle,
273338 GivenL0MemoryAllocatedInChildProcessWhenUsingL0IPCThenParentProcessReadsMemoryCorrectly) {
274- run_ipc_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , false ,
275- ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, false );
339+ run_ipc_dev_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , false ,
340+ ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, false );
276341}
277342
278343LZT_TEST (
279344 IpcMemoryAccessTestOpaqueIpcHandle,
280345 GivenL0MemoryAllocatedInChildProcessWhenUsingL0IPCOnImmediateCmdListThenParentProcessReadsMemoryCorrectly) {
281- run_ipc_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , false ,
282- ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true );
346+ run_ipc_dev_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , false ,
347+ ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true );
283348}
284349
285350LZT_TEST (
286351 IpcMemoryAccessTestOpaqueIpcHandle,
287352 GivenL0MemoryAllocatedInChildProcessBiasCachedWhenUsingL0IPCThenParentProcessReadsMemoryCorrectly) {
288- run_ipc_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , false ,
289- ZE_IPC_MEMORY_FLAG_BIAS_CACHED, false );
353+ run_ipc_dev_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , false ,
354+ ZE_IPC_MEMORY_FLAG_BIAS_CACHED, false );
290355}
291356
292357LZT_TEST (
293358 IpcMemoryAccessTestOpaqueIpcHandle,
294359 GivenL0MemoryAllocatedInChildProcessBiasCachedWhenUsingL0IPCOnImmediateCmdListThenParentProcessReadsMemoryCorrectly) {
295- run_ipc_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , false ,
296- ZE_IPC_MEMORY_FLAG_BIAS_CACHED, true );
360+ run_ipc_dev_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , false ,
361+ ZE_IPC_MEMORY_FLAG_BIAS_CACHED, true );
297362}
298363
299364LZT_TEST (
300365 IpcMemoryAccessTestOpaqueIpcHandle,
301366 GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessWhenUsingL0IPCThenChildProcessReadsMemoryCorrectly) {
302- run_ipc_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , true ,
303- ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, false );
367+ run_ipc_dev_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , true ,
368+ ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, false );
304369}
305370
306371LZT_TEST (
307372 IpcMemoryAccessTestOpaqueIpcHandle,
308373 GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectly) {
309- run_ipc_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , true ,
310- ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true );
374+ run_ipc_dev_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , true ,
375+ ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true );
311376}
312377
313378LZT_TEST (
314379 IpcMemoryAccessTestOpaqueIpcHandle,
315380 GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessBiasCachedWhenUsingL0IPCThenChildProcessReadsMemoryCorrectly) {
316- run_ipc_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , true ,
317- ZE_IPC_MEMORY_FLAG_BIAS_CACHED, false );
381+ run_ipc_dev_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , true ,
382+ ZE_IPC_MEMORY_FLAG_BIAS_CACHED, false );
318383}
319384
320385LZT_TEST (
321386 IpcMemoryAccessTestOpaqueIpcHandle,
322387 GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessBiasCachedWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectly) {
323- run_ipc_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , true ,
324- ZE_IPC_MEMORY_FLAG_BIAS_CACHED, true );
388+ run_ipc_dev_mem_access_test_opaque (TEST_DEVICE_ACCESS, 4096 , true ,
389+ ZE_IPC_MEMORY_FLAG_BIAS_CACHED, true );
325390}
326391
327392LZT_TEST (
328393 IpcMemoryAccessTestOpaqueIpcHandleSubDevice,
329394 GivenL0PhysicalMemoryAllocatedReservedInParentProcessWhenUsingL0IPCThenChildProcessReadsMemoryCorrectlyUsingSubDeviceQueue) {
330- run_ipc_mem_access_test_opaque (TEST_SUBDEVICE_ACCESS, 4096 , true ,
331- ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, false );
395+ run_ipc_dev_mem_access_test_opaque (TEST_SUBDEVICE_ACCESS, 4096 , true ,
396+ ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, false );
332397}
333398
334399LZT_TEST (
335400 IpcMemoryAccessTestOpaqueIpcHandleSubDevice,
336401 GivenL0PhysicalMemoryAllocatedReservedInParentProcessWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectlyUsingSubDeviceQueue) {
337- run_ipc_mem_access_test_opaque (TEST_SUBDEVICE_ACCESS, 4096 , true ,
338- ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true );
402+ run_ipc_dev_mem_access_test_opaque (TEST_SUBDEVICE_ACCESS, 4096 , true ,
403+ ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true );
404+ }
405+
406+ LZT_TEST (
407+ IpcMemoryAccessTestOpaqueIpcHandle,
408+ GivenUncachedHostMemoryAllocatedInParentProcessThenChildProcessReadsMemoryCorrectly) {
409+ run_ipc_host_mem_access_test_opaque (4096 , ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED);
410+ }
411+
412+ LZT_TEST (
413+ IpcMemoryAccessTestOpaqueIpcHandle,
414+ GivenCachedHostMemoryAllocatedInParentProcessThenChildProcessReadsMemoryCorrectly) {
415+ run_ipc_host_mem_access_test_opaque (4096 , ZE_IPC_MEMORY_FLAG_BIAS_CACHED);
339416}
340417
341418} // namespace
0 commit comments