Skip to content

Commit 69511e2

Browse files
authored
test: Add new IPC scenario for opaque handle (#179)
- exchange IPC handle using shm between processes Signed-off-by: Aravind Gopalakrishnan <[email protected]>
1 parent fedf7b3 commit 69511e2

File tree

4 files changed

+252
-6
lines changed

4 files changed

+252
-6
lines changed

conformance_tests/core/test_ipc/src/test_ipc_memory.cpp

Lines changed: 144 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ static void run_ipc_mem_access_test(ipc_mem_access_test_t test_type, int size,
4848
// launch child
4949
boost::process::child c("./ipc/test_ipc_memory_helper");
5050

51-
shared_data_t test_data = {test_type, size, flags, is_immediate};
51+
ze_ipc_mem_handle_t ipc_handle = {};
52+
shared_data_t test_data = {test_type, TEST_SOCK, size,
53+
flags, is_immediate, ipc_handle};
5254
bipc::shared_memory_object shm(bipc::create_only, "ipc_memory_test",
5355
bipc::read_write);
5456
shm.truncate(sizeof(shared_data_t));
@@ -59,7 +61,6 @@ static void run_ipc_mem_access_test(ipc_mem_access_test_t test_type, int size,
5961
auto context = lzt::create_context(driver);
6062
auto device = lzt::zeDevice::get_instance()->get_device();
6163
auto cmd_bundle = lzt::create_command_bundle(context, device, is_immediate);
62-
ze_ipc_mem_handle_t ipc_handle = {};
6364

6465
void *buffer = lzt::allocate_host_memory(size, 1, context);
6566
memset(buffer, 0, size);
@@ -105,6 +106,77 @@ static void run_ipc_mem_access_test(ipc_mem_access_test_t test_type, int size,
105106
lzt::destroy_context(context);
106107
}
107108

109+
static void run_ipc_mem_access_test_opaque(ipc_mem_access_test_t test_type,
110+
int size, bool reserved,
111+
ze_ipc_memory_flags_t flags,
112+
bool is_immediate) {
113+
ze_result_t result = zeInit(0);
114+
if (result != ZE_RESULT_SUCCESS) {
115+
throw std::runtime_error("Parent zeInit failed: " +
116+
level_zero_tests::to_string(result));
117+
}
118+
LOG_DEBUG << "[Parent] Driver initialized\n";
119+
lzt::print_platform_overview();
120+
121+
bipc::shared_memory_object::remove("ipc_memory_test");
122+
// launch child
123+
boost::process::child c("./ipc/test_ipc_memory_helper");
124+
125+
ze_ipc_mem_handle_t ipc_handle = {};
126+
bipc::shared_memory_object shm(bipc::create_only, "ipc_memory_test",
127+
bipc::read_write);
128+
shm.truncate(sizeof(shared_data_t));
129+
bipc::mapped_region region(shm, bipc::read_write);
130+
131+
auto driver = lzt::get_default_driver();
132+
auto context = lzt::create_context(driver);
133+
auto device = lzt::zeDevice::get_instance()->get_device();
134+
auto cmd_bundle = lzt::create_command_bundle(context, device, is_immediate);
135+
136+
void *buffer = lzt::allocate_host_memory(size, 1, context);
137+
memset(buffer, 0, size);
138+
lzt::write_data_pattern(buffer, size, 1);
139+
size_t allocSize = size;
140+
ze_physical_mem_handle_t reservedPhysicalMemory = {};
141+
void *memory = nullptr;
142+
if (reserved) {
143+
memory = lzt::reserve_allocate_and_map_device_memory(
144+
context, device, allocSize, &reservedPhysicalMemory);
145+
} else {
146+
memory = lzt::allocate_device_memory(size, 1, 0, context);
147+
}
148+
lzt::append_memory_copy(cmd_bundle.list, memory, buffer, size);
149+
lzt::close_command_list(cmd_bundle.list);
150+
lzt::execute_and_sync_command_bundle(cmd_bundle, UINT64_MAX);
151+
152+
ASSERT_EQ(ZE_RESULT_SUCCESS, zeMemGetIpcHandle(context, memory, &ipc_handle));
153+
// copy ipc handle data to shm
154+
shared_data_t test_data = {test_type, TEST_NONSOCK, size,
155+
flags, is_immediate, ipc_handle};
156+
std::memcpy(region.get_address(), &test_data, sizeof(shared_data_t));
157+
158+
ze_ipc_mem_handle_t ipc_handle_zero{};
159+
ASSERT_NE(0, memcmp((void *)&ipc_handle, (void *)&ipc_handle_zero,
160+
sizeof(ipc_handle)));
161+
162+
// Free device memory once receiver is done
163+
c.wait();
164+
EXPECT_EQ(c.exit_code(), 0);
165+
166+
ASSERT_EQ(ZE_RESULT_SUCCESS, zeMemPutIpcHandle(context, ipc_handle));
167+
bipc::shared_memory_object::remove("ipc_memory_test");
168+
169+
if (reserved) {
170+
lzt::unmap_and_free_reserved_memory(context, memory, reservedPhysicalMemory,
171+
allocSize);
172+
} else {
173+
lzt::free_memory(context, memory);
174+
}
175+
lzt::free_memory(context, buffer);
176+
lzt::destroy_command_bundle(cmd_bundle);
177+
lzt::destroy_context(context);
178+
}
179+
108180
TEST(
109181
IpcMemoryAccessTest,
110182
GivenL0MemoryAllocatedInChildProcessWhenUsingL0IPCThenParentProcessReadsMemoryCorrectly) {
@@ -175,6 +247,76 @@ TEST(
175247
ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true);
176248
}
177249

250+
TEST(
251+
IpcMemoryAccessTestOpaqueIpcHandle,
252+
GivenL0MemoryAllocatedInChildProcessWhenUsingL0IPCThenParentProcessReadsMemoryCorrectly) {
253+
run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, false,
254+
ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, false);
255+
}
256+
257+
TEST(
258+
IpcMemoryAccessTestOpaqueIpcHandle,
259+
GivenL0MemoryAllocatedInChildProcessWhenUsingL0IPCOnImmediateCmdListThenParentProcessReadsMemoryCorrectly) {
260+
run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, false,
261+
ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true);
262+
}
263+
264+
TEST(
265+
IpcMemoryAccessTestOpaqueIpcHandle,
266+
GivenL0MemoryAllocatedInChildProcessBiasCachedWhenUsingL0IPCThenParentProcessReadsMemoryCorrectly) {
267+
run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, false,
268+
ZE_IPC_MEMORY_FLAG_BIAS_CACHED, false);
269+
}
270+
271+
TEST(
272+
IpcMemoryAccessTestOpaqueIpcHandle,
273+
GivenL0MemoryAllocatedInChildProcessBiasCachedWhenUsingL0IPCOnImmediateCmdListThenParentProcessReadsMemoryCorrectly) {
274+
run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, false,
275+
ZE_IPC_MEMORY_FLAG_BIAS_CACHED, true);
276+
}
277+
278+
TEST(
279+
IpcMemoryAccessTestOpaqueIpcHandle,
280+
GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessWhenUsingL0IPCThenChildProcessReadsMemoryCorrectly) {
281+
run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, true,
282+
ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, false);
283+
}
284+
285+
TEST(
286+
IpcMemoryAccessTestOpaqueIpcHandle,
287+
GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectly) {
288+
run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, true,
289+
ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true);
290+
}
291+
292+
TEST(
293+
IpcMemoryAccessTestOpaqueIpcHandle,
294+
GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessBiasCachedWhenUsingL0IPCThenChildProcessReadsMemoryCorrectly) {
295+
run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, true,
296+
ZE_IPC_MEMORY_FLAG_BIAS_CACHED, false);
297+
}
298+
299+
TEST(
300+
IpcMemoryAccessTestOpaqueIpcHandle,
301+
GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessBiasCachedWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectly) {
302+
run_ipc_mem_access_test_opaque(TEST_DEVICE_ACCESS, 4096, true,
303+
ZE_IPC_MEMORY_FLAG_BIAS_CACHED, true);
304+
}
305+
306+
TEST(
307+
IpcMemoryAccessTestOpaqueIpcHandleSubDevice,
308+
GivenL0PhysicalMemoryAllocatedReservedInParentProcessWhenUsingL0IPCThenChildProcessReadsMemoryCorrectlyUsingSubDeviceQueue) {
309+
run_ipc_mem_access_test_opaque(TEST_SUBDEVICE_ACCESS, 4096, true,
310+
ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, false);
311+
}
312+
313+
TEST(
314+
IpcMemoryAccessTestOpaqueIpcHandleSubDevice,
315+
GivenL0PhysicalMemoryAllocatedReservedInParentProcessWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectlyUsingSubDeviceQueue) {
316+
run_ipc_mem_access_test_opaque(TEST_SUBDEVICE_ACCESS, 4096, true,
317+
ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, true);
318+
}
319+
178320
} // namespace
179321

180322
#endif // __linux__

conformance_tests/core/test_ipc/src/test_ipc_memory.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ typedef enum {
1414
TEST_SUBDEVICE_ACCESS
1515
} ipc_mem_access_test_t;
1616

17+
typedef enum { TEST_SOCK, TEST_NONSOCK } ipc_mem_access_test_sock_t;
18+
1719
typedef struct {
1820
ipc_mem_access_test_t test_type;
21+
ipc_mem_access_test_sock_t test_sock_type;
1922
int size;
2023
ze_ipc_memory_flags_t flags;
2124
bool is_immediate;
25+
ze_ipc_mem_handle_t ipc_handle;
2226
} shared_data_t;
2327

2428
#endif

conformance_tests/core/test_ipc/src/test_ipc_memory_helper.cpp

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,85 @@ 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) {
71+
auto driver = lzt::get_default_driver();
72+
auto context = lzt::create_context(driver);
73+
auto device = lzt::zeDevice::get_instance()->get_device();
74+
auto cmd_bundle = lzt::create_command_bundle(context, device, is_immediate);
75+
void *memory = nullptr;
76+
77+
EXPECT_EQ(ZE_RESULT_SUCCESS,
78+
zeMemOpenIpcHandle(context, device, ipc_handle, flags, &memory));
79+
80+
void *buffer = lzt::allocate_host_memory(size, 1, context);
81+
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+
86+
LOG_DEBUG << "[Child] Validating buffer received correctly";
87+
lzt::validate_data_pattern(buffer, size, 1);
88+
89+
EXPECT_EQ(ZE_RESULT_SUCCESS, zeMemCloseIpcHandle(context, memory));
90+
lzt::free_memory(context, buffer);
91+
lzt::destroy_command_bundle(cmd_bundle);
92+
lzt::destroy_context(context);
93+
94+
if (::testing::Test::HasFailure()) {
95+
exit(1);
96+
} else {
97+
exit(0);
98+
}
99+
}
100+
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) {
105+
auto driver = lzt::get_default_driver();
106+
auto context = lzt::create_context(driver);
107+
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+
auto cmd_bundle = lzt::create_command_bundle(context, device, is_immediate);
113+
void *memory = nullptr;
114+
115+
EXPECT_EQ(ZE_RESULT_SUCCESS,
116+
zeMemOpenIpcHandle(context, device, ipc_handle, flags, &memory));
117+
118+
void *buffer = lzt::allocate_host_memory(size, 1, context);
119+
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);
128+
129+
LOG_DEBUG << "[Child] Validating buffer received correctly";
130+
lzt::validate_data_pattern(buffer, size, 1);
131+
lzt::destroy_command_bundle(cmd_bundle);
132+
}
133+
134+
EXPECT_EQ(ZE_RESULT_SUCCESS, zeMemCloseIpcHandle(context, memory));
135+
lzt::free_memory(context, buffer);
136+
lzt::destroy_command_bundle(cmd_bundle);
137+
lzt::destroy_context(context);
138+
139+
if (::testing::Test::HasFailure()) {
140+
exit(1);
141+
} else {
142+
exit(0);
143+
}
144+
}
145+
67146
static void child_subdevice_access_test(int size, ze_ipc_memory_flags_t flags,
68147
bool is_immediate) {
69148
auto driver = lzt::get_default_driver();
@@ -148,12 +227,23 @@ int main() {
148227

149228
switch (shared_data.test_type) {
150229
case TEST_DEVICE_ACCESS:
151-
child_device_access_test(shared_data.size, shared_data.flags,
152-
shared_data.is_immediate);
230+
if (shared_data.test_sock_type == TEST_NONSOCK) {
231+
child_device_access_test_opaque(shared_data.size, shared_data.flags,
232+
shared_data.is_immediate,
233+
shared_data.ipc_handle);
234+
} else {
235+
child_device_access_test(shared_data.size, shared_data.flags,
236+
shared_data.is_immediate);
237+
}
153238
break;
154239
case TEST_SUBDEVICE_ACCESS:
155-
child_subdevice_access_test(shared_data.size, shared_data.flags,
156-
shared_data.is_immediate);
240+
if (shared_data.test_sock_type == TEST_NONSOCK) {
241+
child_subdevice_access_test_opaque(shared_data.size, shared_data.flags,
242+
shared_data.is_immediate,
243+
shared_data.ipc_handle);
244+
} else {
245+
break; // Currently supporting only device access test scenario
246+
}
157247
break;
158248
default:
159249
LOG_DEBUG << "Unrecognized test case";

scripts/level_zero_report_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ def assign_test_feature_tag(test_feature: str, test_name: str, test_section: str
146146
(re.search('L0_CTS_IpcMemoryAccessTest_GivenL0MemoryAllocatedInChildProcessBiasCachedWhenUsingL0IPCOnImmediateCmdListThenParentProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
147147
(re.search('L0_CTS_IpcMemoryAccessSubDeviceTest_GivenL0PhysicalMemoryAllocatedReservedInParentProcessWhenUsingL0IPCThenChildProcessReadsMemoryCorrectlyUsingSubDeviceQueue', test_name, re.IGNORECASE)) or \
148148
(re.search('L0_CTS_IpcMemoryAccessSubDeviceTest_GivenL0PhysicalMemoryAllocatedReservedInParentProcessWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectlyUsingSubDeviceQueue', test_name, re.IGNORECASE)) or \
149+
(re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandle_GivenL0MemoryAllocatedInChildProcessWhenUsingL0IPCThenParentProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
150+
(re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandle_GivenL0MemoryAllocatedInChildProcessWhenUsingL0IPCOnImmediateCmdListThenParentProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
151+
(re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandle_GivenL0MemoryAllocatedInChildProcessBiasCachedWhenUsingL0IPCThenParentProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
152+
(re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandle_GivenL0MemoryAllocatedInChildProcessBiasCachedWhenUsingL0IPCOnImmediateCmdListThenParentProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
153+
(re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandle_GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessWhenUsingL0IPCThenChildProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
154+
(re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandle_GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
155+
(re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandle_GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessBiasCachedWhenUsingL0IPCThenChildProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
156+
(re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandle_GivenL0PhysicalMemoryAllocatedAndReservedInParentProcessBiasCachedWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectly', test_name, re.IGNORECASE)) or \
157+
(re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandleSubDevice_GivenL0PhysicalMemoryAllocatedReservedInParentProcessWhenUsingL0IPCThenChildProcessReadsMemoryCorrectlyUsingSubDeviceQueue', test_name, re.IGNORECASE)) or \
158+
(re.search('L0_CTS_IpcMemoryAccessTestOpaqueIpcHandleSubDevice_GivenL0PhysicalMemoryAllocatedReservedInParentProcessWhenUsingL0IPCOnImmediateCmdListThenChildProcessReadsMemoryCorrectlyUsingSubDeviceQueue', test_name, re.IGNORECASE)) or \
149159
(re.search('L0_CTS_zeDeviceGetMemoryPropertiesTests_GivenValidDeviceWhenRetrievingMemoryPropertiesThenValidExtPropertiesAreReturned', test_name, re.IGNORECASE)) or \
150160
(re.search('L0_CTS_zeKernelCreateTests_GivenValidFunctionWhenGettingSourceAttributeThenReturnAttributeString', test_name, re.IGNORECASE)) or \
151161
(re.search('L0_CTS_zeKernelGetNameTests_GivenKernelGetNameCorrectNameIsReturned', test_name, re.IGNORECASE)) or \

0 commit comments

Comments
 (0)