Skip to content

Commit 0ac7789

Browse files
authored
Merge branch 'oneapi-src:master' into mem_cts
2 parents 969e3de + 1c6cedf commit 0ac7789

File tree

2 files changed

+67
-56
lines changed

2 files changed

+67
-56
lines changed

conformance_tests/core/test_ipc/src/test_ipc_memory.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*/
88
#ifdef __linux__
99
#include <unistd.h>
10+
#endif
1011
#include <boost/interprocess/shared_memory_object.hpp>
1112
#include <boost/interprocess/sync/named_semaphore.hpp>
1213
#include <boost/interprocess/mapped_region.hpp>
1314
#include <boost/process.hpp>
14-
#endif
1515

1616
#include "gmock/gmock.h"
1717
#include "gtest/gtest.h"
@@ -23,12 +23,11 @@
2323

2424
#include <level_zero/ze_api.h>
2525

26-
#ifdef __linux__
27-
2826
namespace bipc = boost::interprocess;
2927

3028
namespace {
3129

30+
#ifdef __linux__
3231
static void run_ipc_mem_access_test(ipc_mem_access_test_t test_type, int size,
3332
bool reserved, ze_ipc_memory_flags_t flags,
3433
bool is_immediate) {
@@ -105,6 +104,7 @@ static void run_ipc_mem_access_test(ipc_mem_access_test_t test_type, int size,
105104
lzt::destroy_command_bundle(cmd_bundle);
106105
lzt::destroy_context(context);
107106
}
107+
#endif // __linux__
108108

109109
static void run_ipc_mem_access_test_opaque(ipc_mem_access_test_t test_type,
110110
int size, bool reserved,
@@ -120,7 +120,18 @@ static void run_ipc_mem_access_test_opaque(ipc_mem_access_test_t test_type,
120120

121121
bipc::shared_memory_object::remove("ipc_memory_test");
122122
// launch child
123-
boost::process::child c("./ipc/test_ipc_memory_helper");
123+
#ifdef _WIN32
124+
std::string helper_path = ".\\ipc\\test_ipc_memory_helper.exe";
125+
#else
126+
std::string helper_path = "./ipc/test_ipc_memory_helper";
127+
#endif
128+
boost::process::child c;
129+
try {
130+
c = boost::process::child(helper_path);
131+
} catch (const boost::process::process_error &e) {
132+
std::cerr << "Failed to launch child process: " << e.what() << std::endl;
133+
throw;
134+
}
124135

125136
ze_ipc_mem_handle_t ipc_handle = {};
126137
bipc::shared_memory_object shm(bipc::create_only, "ipc_memory_test",
@@ -177,6 +188,7 @@ static void run_ipc_mem_access_test_opaque(ipc_mem_access_test_t test_type,
177188
lzt::destroy_context(context);
178189
}
179190

191+
#ifdef __linux__
180192
TEST(
181193
IpcMemoryAccessTest,
182194
GivenL0MemoryAllocatedInChildProcessWhenUsingL0IPCThenParentProcessReadsMemoryCorrectly) {
@@ -246,6 +258,7 @@ TEST(
246258
run_ipc_mem_access_test(TEST_SUBDEVICE_ACCESS, 4096, true,
247259
ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true);
248260
}
261+
#endif // __linux__
249262

250263
TEST(
251264
IpcMemoryAccessTestOpaqueIpcHandle,
@@ -319,8 +332,6 @@ TEST(
319332

320333
} // namespace
321334

322-
#endif // __linux__
323-
324335
// We put the main here because L0 doesn't currently specify how
325336
// zeInit should be handled with fork(), so each process must call
326337
// zeInit

conformance_tests/core/test_ipc/src/test_ipc_memory_helper.cpp

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)