Skip to content

Commit f6ab42a

Browse files
authored
Add opaque host memory allocation IPC test (#306)
Feat: add tests for IPC opaque host memory handles Related-To: NEO-15836 Signed-off-by: Eric Mortensen <[email protected]>
1 parent d38e68a commit f6ab42a

File tree

4 files changed

+134
-26
lines changed

4 files changed

+134
-26
lines changed

conformance_tests/core/test_ipc/src/test_ipc_memory.cpp

Lines changed: 101 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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__
200265
LZT_TEST(
201266
IpcMemoryAccessTest,
@@ -271,71 +336,83 @@ LZT_TEST(
271336
LZT_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

278343
LZT_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

285350
LZT_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

292357
LZT_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

299364
LZT_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

306371
LZT_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

313378
LZT_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

320385
LZT_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

327392
LZT_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

334399
LZT_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

conformance_tests/core/test_ipc/src/test_ipc_memory.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
typedef enum {
1313
TEST_DEVICE_ACCESS,
14-
TEST_SUBDEVICE_ACCESS
14+
TEST_SUBDEVICE_ACCESS,
15+
TEST_HOST_ACCESS
1516
} ipc_mem_access_test_t;
1617

1718
typedef enum { TEST_SOCK, TEST_NONSOCK } ipc_mem_access_test_sock_t;

conformance_tests/core/test_ipc/src/test_ipc_memory_helper.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,30 @@ static void child_subdevice_access_test_opaque(size_t size,
198198
}
199199
}
200200

201+
static void child_host_access_test_opaque(size_t size,
202+
ze_ipc_memory_flags_t flags,
203+
ze_ipc_mem_handle_t ipc_handle) {
204+
auto driver = lzt::get_default_driver();
205+
auto context = lzt::create_context(driver);
206+
auto device = lzt::zeDevice::get_instance()->get_device();
207+
void *buffer = nullptr;
208+
209+
EXPECT_ZE_RESULT_SUCCESS(
210+
zeMemOpenIpcHandle(context, device, ipc_handle, flags, &buffer));
211+
212+
LOG_DEBUG << "[Child] Validating buffer received correctly";
213+
lzt::validate_data_pattern(buffer, size, 1);
214+
215+
EXPECT_ZE_RESULT_SUCCESS(zeMemCloseIpcHandle(context, buffer));
216+
lzt::destroy_context(context);
217+
218+
if (::testing::Test::HasFailure()) {
219+
exit(1);
220+
} else {
221+
exit(0);
222+
}
223+
}
224+
201225
int main() {
202226
ze_result_t result = zeInit(0);
203227
if (result != ZE_RESULT_SUCCESS) {
@@ -233,8 +257,8 @@ int main() {
233257
child_device_access_test_opaque(shared_data.size, shared_data.flags,
234258
shared_data.is_immediate,
235259
shared_data.ipc_handle);
236-
} else {
237260
#ifdef __linux__
261+
} else {
238262
child_device_access_test(shared_data.size, shared_data.flags,
239263
shared_data.is_immediate);
240264
#endif
@@ -249,6 +273,10 @@ int main() {
249273
break; // Currently supporting only device access test scenario
250274
}
251275
break;
276+
case TEST_HOST_ACCESS:
277+
child_host_access_test_opaque(shared_data.size, shared_data.flags,
278+
shared_data.ipc_handle);
279+
break;
252280
default:
253281
LOG_DEBUG << "Unrecognized test case";
254282
exit(1);

scripts/level_zero_report_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ def assign_test_feature_tag(test_feature: str, test_name: str, test_section: str
290290
(re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandle_GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessBiasCachedWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
291291
(re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandleSubDevice_GivenL0PhysicalMemoryAllocatedReservedInParentProcessWhenUsingL0IPCThenChildProcessReadsMemoryCorrectlyUsingSubDeviceQueue', test_name, re.IGNORECASE)) or \
292292
(re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandleSubDevice_GivenL0PhysicalMemoryAllocatedReservedInParentProcessWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectlyUsingSubDeviceQueue', test_name, re.IGNORECASE)) or \
293+
(re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandle_GivenUncachedHostMemoryAllocatedInParentProcessThenChildProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
294+
(re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandle_GivenCachedHostMemoryAllocatedInParentProcessThenChildProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
293295
(re.search('L0_CTS_zeDeviceGetMemoryPropertiesTests_GivenValidDeviceWhenRetrievingMemoryPropertiesThenValidExtPropertiesAreReturned', test_name, re.IGNORECASE)) or \
294296
(re.search('L0_CTS_zeKernelCreateTests_GivenValidFunctionWhenGettingSourceAttributeThenReturnAttributeString', test_name, re.IGNORECASE)) or \
295297
(re.search('L0_CTS_zeKernelGetNameTests_GivenKernelGetNameCorrectNameIsReturned', test_name, re.IGNORECASE)) or \

0 commit comments

Comments
 (0)