@@ -64,31 +64,50 @@ static void child_device_access_test(int size, ze_ipc_memory_flags_t flags,
6464 }
6565}
6666
67- static void child_device_access_test_opaque (int size,
68- ze_ipc_memory_flags_t flags,
69- bool is_immediate,
70- ze_ipc_mem_handle_t ipc_handle) {
67+ static void child_subdevice_access_test (int size, ze_ipc_memory_flags_t flags,
68+ bool is_immediate) {
7169 auto driver = lzt::get_default_driver ();
7270 auto context = lzt::create_context (driver);
7371 auto device = lzt::zeDevice::get_instance ()->get_device ();
74- auto cmd_bundle = lzt::create_command_bundle (context, device, is_immediate);
72+ auto sub_devices = lzt::get_ze_sub_devices (device);
73+
74+ auto sub_device_count = sub_devices.size ();
75+
76+ ze_ipc_mem_handle_t ipc_handle;
7577 void *memory = nullptr ;
7678
79+ bipc::named_semaphore semaphore (bipc::open_only, " ipc_memory_test_semaphore" );
80+ // Signal parent to send IPC handle
81+ semaphore.post ();
82+
83+ int ipc_descriptor =
84+ lzt::receive_ipc_handle<ze_ipc_mem_handle_t >(ipc_handle.data );
85+ memcpy (&ipc_handle, static_cast <void *>(&ipc_descriptor),
86+ sizeof (ipc_descriptor));
87+
88+ // Open IPC buffer with root device
7789 EXPECT_EQ (ZE_RESULT_SUCCESS,
7890 zeMemOpenIpcHandle (context, device, ipc_handle, flags, &memory));
7991
8092 void *buffer = lzt::allocate_host_memory (size, 1 , context);
8193 memset (buffer, 0 , size);
82- lzt::append_memory_copy (cmd_bundle.list , buffer, memory, size);
83- lzt::close_command_list (cmd_bundle.list );
84- lzt::execute_and_sync_command_bundle (cmd_bundle, UINT64_MAX);
8594
86- LOG_DEBUG << " [Child] Validating buffer received correctly" ;
87- lzt::validate_data_pattern (buffer, size, 1 );
95+ // For each sub device found, use IPC buffer in a copy operation and validate
96+ for (auto i = 0 ; i < sub_device_count; i++) {
97+ auto cmd_bundle =
98+ lzt::create_command_bundle (context, sub_devices[i], is_immediate);
99+
100+ lzt::append_memory_copy (cmd_bundle.list , buffer, memory, size);
101+ lzt::close_command_list (cmd_bundle.list );
102+ lzt::execute_and_sync_command_bundle (cmd_bundle, UINT64_MAX);
103+
104+ LOG_DEBUG << " [Child] Validating buffer received correctly" ;
105+ lzt::validate_data_pattern (buffer, size, 1 );
106+ lzt::destroy_command_bundle (cmd_bundle);
107+ }
88108
89109 EXPECT_EQ (ZE_RESULT_SUCCESS, zeMemCloseIpcHandle (context, memory));
90110 lzt::free_memory (context, buffer);
91- lzt::destroy_command_bundle (cmd_bundle);
92111 lzt::destroy_context (context);
93112
94113 if (::testing::Test::HasFailure ()) {
@@ -97,18 +116,15 @@ static void child_device_access_test_opaque(int size,
97116 exit (0 );
98117 }
99118}
119+ #endif
100120
101- static void child_subdevice_access_test_opaque (int size,
102- ze_ipc_memory_flags_t flags,
103- bool is_immediate,
104- ze_ipc_mem_handle_t ipc_handle) {
121+ static void child_device_access_test_opaque (int size,
122+ ze_ipc_memory_flags_t flags,
123+ bool is_immediate,
124+ ze_ipc_mem_handle_t ipc_handle) {
105125 auto driver = lzt::get_default_driver ();
106126 auto context = lzt::create_context (driver);
107127 auto device = lzt::zeDevice::get_instance ()->get_device ();
108- auto sub_devices = lzt::get_ze_sub_devices (device);
109-
110- auto sub_device_count = sub_devices.size ();
111-
112128 auto cmd_bundle = lzt::create_command_bundle (context, device, is_immediate);
113129 void *memory = nullptr ;
114130
@@ -117,19 +133,12 @@ static void child_subdevice_access_test_opaque(int size,
117133
118134 void *buffer = lzt::allocate_host_memory (size, 1 , context);
119135 memset (buffer, 0 , size);
120- // For each sub device found, use IPC buffer in a copy operation and validate
121- for (auto i = 0 ; i < sub_device_count; i++) {
122- auto cmd_bundle =
123- lzt::create_command_bundle (context, sub_devices[i], is_immediate);
124-
125- lzt::append_memory_copy (cmd_bundle.list , buffer, memory, size);
126- lzt::close_command_list (cmd_bundle.list );
127- lzt::execute_and_sync_command_bundle (cmd_bundle, UINT64_MAX);
136+ lzt::append_memory_copy (cmd_bundle.list , buffer, memory, size);
137+ lzt::close_command_list (cmd_bundle.list );
138+ lzt::execute_and_sync_command_bundle (cmd_bundle, UINT64_MAX);
128139
129- LOG_DEBUG << " [Child] Validating buffer received correctly" ;
130- lzt::validate_data_pattern (buffer, size, 1 );
131- lzt::destroy_command_bundle (cmd_bundle);
132- }
140+ LOG_DEBUG << " [Child] Validating buffer received correctly" ;
141+ lzt::validate_data_pattern (buffer, size, 1 );
133142
134143 EXPECT_EQ (ZE_RESULT_SUCCESS, zeMemCloseIpcHandle (context, memory));
135144 lzt::free_memory (context, buffer);
@@ -143,34 +152,25 @@ static void child_subdevice_access_test_opaque(int size,
143152 }
144153}
145154
146- static void child_subdevice_access_test (int size, ze_ipc_memory_flags_t flags,
147- bool is_immediate) {
155+ static void child_subdevice_access_test_opaque (int size,
156+ ze_ipc_memory_flags_t flags,
157+ bool is_immediate,
158+ ze_ipc_mem_handle_t ipc_handle) {
148159 auto driver = lzt::get_default_driver ();
149160 auto context = lzt::create_context (driver);
150161 auto device = lzt::zeDevice::get_instance ()->get_device ();
151162 auto sub_devices = lzt::get_ze_sub_devices (device);
152163
153164 auto sub_device_count = sub_devices.size ();
154165
155- ze_ipc_mem_handle_t ipc_handle ;
166+ auto cmd_bundle = lzt::create_command_bundle (context, device, is_immediate) ;
156167 void *memory = nullptr ;
157168
158- bipc::named_semaphore semaphore (bipc::open_only, " ipc_memory_test_semaphore" );
159- // Signal parent to send IPC handle
160- semaphore.post ();
161-
162- int ipc_descriptor =
163- lzt::receive_ipc_handle<ze_ipc_mem_handle_t >(ipc_handle.data );
164- memcpy (&ipc_handle, static_cast <void *>(&ipc_descriptor),
165- sizeof (ipc_descriptor));
166-
167- // Open IPC buffer with root device
168169 EXPECT_EQ (ZE_RESULT_SUCCESS,
169170 zeMemOpenIpcHandle (context, device, ipc_handle, flags, &memory));
170171
171172 void *buffer = lzt::allocate_host_memory (size, 1 , context);
172173 memset (buffer, 0 , size);
173-
174174 // For each sub device found, use IPC buffer in a copy operation and validate
175175 for (auto i = 0 ; i < sub_device_count; i++) {
176176 auto cmd_bundle =
@@ -187,6 +187,7 @@ static void child_subdevice_access_test(int size, ze_ipc_memory_flags_t flags,
187187
188188 EXPECT_EQ (ZE_RESULT_SUCCESS, zeMemCloseIpcHandle (context, memory));
189189 lzt::free_memory (context, buffer);
190+ lzt::destroy_command_bundle (cmd_bundle);
190191 lzt::destroy_context (context);
191192
192193 if (::testing::Test::HasFailure ()) {
@@ -214,8 +215,8 @@ int main() {
214215 bipc::read_write);
215216 break ;
216217 } catch (const bipc::interprocess_exception &ex) {
217- sched_yield ();
218- sleep ( 1 );
218+ std::this_thread::yield ();
219+ std::this_thread::sleep_for ( std::chrono::seconds ( 1 ) );
219220 if (++count == retries)
220221 throw ex;
221222 }
@@ -232,8 +233,10 @@ int main() {
232233 shared_data.is_immediate ,
233234 shared_data.ipc_handle );
234235 } else {
236+ #ifdef __linux__
235237 child_device_access_test (shared_data.size , shared_data.flags ,
236238 shared_data.is_immediate );
239+ #endif
237240 }
238241 break ;
239242 case TEST_SUBDEVICE_ACCESS:
@@ -256,6 +259,3 @@ int main() {
256259 }
257260 exit (0 );
258261}
259- #else // Windows
260- int main () { exit (0 ); }
261- #endif
0 commit comments