Skip to content

Commit fedf7b3

Browse files
authored
[import export memory] - Adding host and image memory tests (#172)
1 parent 5477490 commit fedf7b3

File tree

3 files changed

+973
-401
lines changed

3 files changed

+973
-401
lines changed

conformance_tests/core/test_memory/src/test_import_helper.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ int main(int argc, char **argv) {
4242
auto device = lzt::get_default_device(driver);
4343

4444
bool is_immediate = (argv[2][0] != '0');
45+
bool is_device = (argv[3][0] != '0');
4546

4647
#ifdef __linux__
4748
const char *socket_path = "external_memory_socket";
@@ -59,15 +60,27 @@ int main(int argc, char **argv) {
5960
ze_external_memory_export_desc_t export_desc = {};
6061
export_desc.stype = ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_DESC;
6162
export_desc.flags = ZE_EXTERNAL_MEMORY_TYPE_FLAG_DMA_BUF;
62-
ze_device_mem_alloc_desc_t device_alloc_desc = {};
63-
device_alloc_desc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC;
64-
device_alloc_desc.pNext = &export_desc;
6563

66-
result = zeMemAllocDevice(context, &device_alloc_desc, size, 1, device,
67-
&exported_memory);
68-
if (ZE_RESULT_SUCCESS != result) {
69-
LOG_WARNING << "Error allocating device memory to be imported\n";
70-
exit(1);
64+
if (is_device) {
65+
ze_device_mem_alloc_desc_t device_alloc_desc = {};
66+
device_alloc_desc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC;
67+
device_alloc_desc.pNext = &export_desc;
68+
result = zeMemAllocDevice(context, &device_alloc_desc, size, 1, device,
69+
&exported_memory);
70+
if (ZE_RESULT_SUCCESS != result) {
71+
LOG_WARNING << "Error allocating device memory to be imported\n";
72+
exit(1);
73+
}
74+
} else {
75+
ze_host_mem_alloc_desc_t host_alloc_desc = {};
76+
host_alloc_desc.stype = ZE_STRUCTURE_TYPE_HOST_MEM_ALLOC_DESC;
77+
host_alloc_desc.pNext = &export_desc;
78+
result =
79+
zeMemAllocHost(context, &host_alloc_desc, size, 1, &exported_memory);
80+
if (ZE_RESULT_SUCCESS != result) {
81+
LOG_WARNING << "Error allocating host memory to be imported\n";
82+
exit(1);
83+
}
7184
}
7285

7386
auto cmd_bundle = lzt::create_command_bundle(
@@ -227,9 +240,12 @@ int main(int argc, char **argv) {
227240
ze_device_mem_alloc_desc_t device_alloc_desc = {};
228241
device_alloc_desc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC;
229242
device_alloc_desc.pNext = &import_handle;
230-
ASSERT_EQ(ZE_RESULT_SUCCESS,
231-
zeMemAllocDevice(context, &device_alloc_desc, size, 1, device,
232-
&imported_memory));
243+
result = zeMemAllocDevice(context, &device_alloc_desc, size, 1, device,
244+
&imported_memory);
245+
if (ZE_RESULT_SUCCESS != result) {
246+
LOG_WARNING << "Error allocating device memory to be imported\n";
247+
exit(1);
248+
}
233249

234250
auto verification_memory =
235251
lzt::allocate_shared_memory(size, 1, 0, 0, device, context);

0 commit comments

Comments
 (0)