@@ -64,31 +64,50 @@ static void child_device_access_test(int size, ze_ipc_memory_flags_t flags,
64
64
}
65
65
}
66
66
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) {
71
69
auto driver = lzt::get_default_driver ();
72
70
auto context = lzt::create_context (driver);
73
71
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;
75
77
void *memory = nullptr ;
76
78
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
77
89
EXPECT_EQ (ZE_RESULT_SUCCESS,
78
90
zeMemOpenIpcHandle (context, device, ipc_handle, flags, &memory));
79
91
80
92
void *buffer = lzt::allocate_host_memory (size, 1 , context);
81
93
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);
85
94
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
+ }
88
108
89
109
EXPECT_EQ (ZE_RESULT_SUCCESS, zeMemCloseIpcHandle (context, memory));
90
110
lzt::free_memory (context, buffer);
91
- lzt::destroy_command_bundle (cmd_bundle);
92
111
lzt::destroy_context (context);
93
112
94
113
if (::testing::Test::HasFailure ()) {
@@ -97,18 +116,15 @@ static void child_device_access_test_opaque(int size,
97
116
exit (0 );
98
117
}
99
118
}
119
+ #endif
100
120
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) {
105
125
auto driver = lzt::get_default_driver ();
106
126
auto context = lzt::create_context (driver);
107
127
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
-
112
128
auto cmd_bundle = lzt::create_command_bundle (context, device, is_immediate);
113
129
void *memory = nullptr ;
114
130
@@ -117,19 +133,12 @@ static void child_subdevice_access_test_opaque(int size,
117
133
118
134
void *buffer = lzt::allocate_host_memory (size, 1 , context);
119
135
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);
128
139
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 );
133
142
134
143
EXPECT_EQ (ZE_RESULT_SUCCESS, zeMemCloseIpcHandle (context, memory));
135
144
lzt::free_memory (context, buffer);
@@ -143,34 +152,25 @@ static void child_subdevice_access_test_opaque(int size,
143
152
}
144
153
}
145
154
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) {
148
159
auto driver = lzt::get_default_driver ();
149
160
auto context = lzt::create_context (driver);
150
161
auto device = lzt::zeDevice::get_instance ()->get_device ();
151
162
auto sub_devices = lzt::get_ze_sub_devices (device);
152
163
153
164
auto sub_device_count = sub_devices.size ();
154
165
155
- ze_ipc_mem_handle_t ipc_handle ;
166
+ auto cmd_bundle = lzt::create_command_bundle (context, device, is_immediate) ;
156
167
void *memory = nullptr ;
157
168
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
168
169
EXPECT_EQ (ZE_RESULT_SUCCESS,
169
170
zeMemOpenIpcHandle (context, device, ipc_handle, flags, &memory));
170
171
171
172
void *buffer = lzt::allocate_host_memory (size, 1 , context);
172
173
memset (buffer, 0 , size);
173
-
174
174
// For each sub device found, use IPC buffer in a copy operation and validate
175
175
for (auto i = 0 ; i < sub_device_count; i++) {
176
176
auto cmd_bundle =
@@ -187,6 +187,7 @@ static void child_subdevice_access_test(int size, ze_ipc_memory_flags_t flags,
187
187
188
188
EXPECT_EQ (ZE_RESULT_SUCCESS, zeMemCloseIpcHandle (context, memory));
189
189
lzt::free_memory (context, buffer);
190
+ lzt::destroy_command_bundle (cmd_bundle);
190
191
lzt::destroy_context (context);
191
192
192
193
if (::testing::Test::HasFailure ()) {
@@ -214,8 +215,8 @@ int main() {
214
215
bipc::read_write);
215
216
break ;
216
217
} 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 ) );
219
220
if (++count == retries)
220
221
throw ex;
221
222
}
@@ -232,8 +233,10 @@ int main() {
232
233
shared_data.is_immediate ,
233
234
shared_data.ipc_handle );
234
235
} else {
236
+ #ifdef __linux__
235
237
child_device_access_test (shared_data.size , shared_data.flags ,
236
238
shared_data.is_immediate );
239
+ #endif
237
240
}
238
241
break ;
239
242
case TEST_SUBDEVICE_ACCESS:
@@ -256,6 +259,3 @@ int main() {
256
259
}
257
260
exit (0 );
258
261
}
259
- #else // Windows
260
- int main () { exit (0 ); }
261
- #endif
0 commit comments