Skip to content

Commit 64c6baf

Browse files
Add test cases for zeCommandListAppendLaunchKernel with SVM (#260)
- atomic/non-atomic kernel - immediate/regular command list - USM/SVM buffers - Varying buffers size with sizes larger than page size Signed-off-by: Misiak, Konstanty <[email protected]>
1 parent df72727 commit 64c6baf

File tree

5 files changed

+161
-0
lines changed

5 files changed

+161
-0
lines changed

conformance_tests/core/test_memory/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ add_lzt_test(
1414
src/test_memory.cpp
1515
src/test_param_tests.cpp
1616
src/test_memory_export_import.cpp
17+
src/test_svm.cpp
1718
src/test_virtual_memory.cpp
1819
src/main.cpp
1920
LINK_LIBRARIES
@@ -23,6 +24,7 @@ add_lzt_test(
2324
level_zero_tests::random
2425
${OS_SPECIFIC_LIBS}
2526
KERNELS
27+
memory_add
2628
unified_mem_test
2729
write_memory_pattern
2830
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
*
3+
* Copyright (C) 2025 Intel Corporation
4+
*
5+
* SPDX-License-Identifier: MIT
6+
*
7+
*/
8+
9+
kernel void memory_add(global int* result, global int* source, int value) {
10+
const int gid = get_global_id(0);
11+
result[gid] = source[gid] + value;
12+
}
13+
14+
kernel void memory_atomic_add(global int* result, global int* source, int value) {
15+
const int gid = get_global_id(0);
16+
atomic_add(&result[gid], source[gid] + value);
17+
}
Binary file not shown.
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
*
3+
* Copyright (C) 2025 Intel Corporation
4+
*
5+
* SPDX-License-Identifier: MIT
6+
*
7+
*/
8+
9+
#include "gtest/gtest.h"
10+
11+
#include "test_harness/test_harness.hpp"
12+
13+
namespace lzt = level_zero_tests;
14+
15+
class SharedSystemMemoryTests
16+
: public testing::TestWithParam<
17+
std::tuple<std::pair<bool, bool>, bool, bool, size_t>> {
18+
protected:
19+
void SetUp() override {
20+
device = lzt::zeDevice::get_instance()->get_device();
21+
module = lzt::create_module(device, "memory_add.spv");
22+
}
23+
24+
void TearDown() override { lzt::destroy_module(module); }
25+
26+
ze_device_handle_t device;
27+
ze_module_handle_t module;
28+
};
29+
30+
LZT_TEST_P(
31+
SharedSystemMemoryTests,
32+
GivenSharedSystemMemoryAllocationsAsKernelArgumentsWhenKernelExecutesThenValuesAreCorrect) {
33+
bool is_dst_shared_system = std::get<0>(GetParam()).first;
34+
bool is_src_shared_system = std::get<0>(GetParam()).second;
35+
bool use_atomic_kernel = std::get<1>(GetParam());
36+
bool use_immediate_cmdlist = std::get<2>(GetParam());
37+
size_t buffer_size = std::get<3>(GetParam());
38+
39+
constexpr size_t group_size = 32;
40+
ASSERT_EQ(buffer_size % (sizeof(int) * group_size), 0);
41+
42+
if (is_dst_shared_system || is_src_shared_system) {
43+
SKIP_IF_SHARED_SYSTEM_ALLOC_UNSUPPORTED();
44+
}
45+
46+
constexpr int source_value = 1234;
47+
constexpr int add_value = 5678;
48+
49+
void *result = lzt::allocate_shared_memory_with_allocator_selector(
50+
buffer_size, 1, 0, 0, device, is_dst_shared_system);
51+
void *source = lzt::allocate_shared_memory_with_allocator_selector(
52+
buffer_size, 1, 0, 0, device, is_src_shared_system);
53+
54+
memset(result, 0, buffer_size);
55+
int *source_as_int = reinterpret_cast<int *>(source);
56+
for (size_t i = 0; i < buffer_size / sizeof(int); i++) {
57+
source_as_int[i] = source_value;
58+
}
59+
60+
const char *funcion_name =
61+
use_atomic_kernel ? "memory_atomic_add" : "memory_add";
62+
ze_kernel_handle_t function = lzt::create_function(module, funcion_name);
63+
lzt::set_group_size(function, group_size, 1, 1);
64+
65+
lzt::set_argument_value(function, 0, sizeof(result), &result);
66+
lzt::set_argument_value(function, 1, sizeof(source), &source);
67+
lzt::set_argument_value(function, 2, sizeof(add_value), &add_value);
68+
69+
lzt::zeCommandBundle cmd_bundle =
70+
lzt::create_command_bundle(use_immediate_cmdlist);
71+
72+
const uint32_t group_count_x = buffer_size / (sizeof(int) * group_size);
73+
ze_group_count_t thread_group_dimensions = {group_count_x, 1, 1};
74+
lzt::append_launch_function(cmd_bundle.list, function,
75+
&thread_group_dimensions, nullptr, 0, nullptr);
76+
77+
lzt::close_command_list(cmd_bundle.list);
78+
lzt::execute_and_sync_command_bundle(cmd_bundle, UINT64_MAX);
79+
80+
int *result_as_int = reinterpret_cast<int *>(result);
81+
for (size_t i = 0; i < buffer_size / sizeof(int); i++) {
82+
EXPECT_EQ(result_as_int[i], source_value + add_value) << "index = " << i;
83+
}
84+
85+
lzt::destroy_command_bundle(cmd_bundle);
86+
lzt::destroy_function(function);
87+
88+
lzt::free_memory_with_allocator_selector(source, is_dst_shared_system);
89+
lzt::free_memory_with_allocator_selector(result, is_src_shared_system);
90+
}
91+
92+
struct SharedSystemMemoryTestsNameSuffix {
93+
template <class ParamType>
94+
std::string operator()(const testing::TestParamInfo<ParamType> &info) const {
95+
std::stringstream ss;
96+
bool is_dst_shared_system = std::get<0>(info.param).first;
97+
bool is_src_shared_system = std::get<0>(info.param).second;
98+
bool use_atomic_kernel = std::get<1>(info.param);
99+
bool use_immediate_cmdlist = std::get<2>(info.param);
100+
size_t buffer_size = std::get<3>(info.param);
101+
102+
const char *buffer_size_str = [](size_t size) -> const char * {
103+
switch (size) {
104+
case 0x80u:
105+
return "_128B";
106+
case 0x1000u:
107+
return "_4KB";
108+
case 0x1800u:
109+
return "_6KB";
110+
case 0x100000u:
111+
return "_1MB";
112+
case 0x100800u:
113+
return "_1MB2KB";
114+
case 0x4000'0000u:
115+
return "_1GB";
116+
case 0x4000'0800u:
117+
return "_1GB2KB";
118+
}
119+
return "";
120+
}(buffer_size);
121+
122+
ss << (is_src_shared_system ? "SVM" : "USM");
123+
ss << "to";
124+
ss << (is_dst_shared_system ? "SVM" : "USM");
125+
ss << (use_atomic_kernel ? "_Atomic" : "_NonAtomic");
126+
ss << (use_immediate_cmdlist ? "_Immediate" : "_Regular");
127+
ss << buffer_size_str;
128+
129+
return ss.str();
130+
}
131+
};
132+
133+
INSTANTIATE_TEST_SUITE_P(
134+
ParamSVMAllocationTests, SharedSystemMemoryTests,
135+
testing::Combine(testing::Values(std::make_pair(true, false),
136+
std::make_pair(false, true),
137+
std::make_pair(true, true)),
138+
testing::Bool(), testing::Bool(),
139+
testing::Values(0x80u, 0x1000u, 0x1800u, 0x100000u,
140+
0x100800u, 0x4000'0000u, 0x4000'0800u)),
141+
SharedSystemMemoryTestsNameSuffix());

scripts/level_zero_report_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def assign_test_feature_tag(test_feature: str, test_name: str, test_section: str
5858
(test_name.find("Thread") != -1) or \
5959
(test_name.find("Affinity") != -1) or \
6060
(test_name.find("Luid") != -1) or \
61+
(test_name.find("ParamSVMAllocationTests_SharedSystemMemoryTests") != -1) or \
6162
(re.search('concurrent', test_name, re.IGNORECASE)) or \
6263
(re.search('context', test_name, re.IGNORECASE)) or \
6364
(re.search('KernelOffset', test_name, re.IGNORECASE)) or \

0 commit comments

Comments
 (0)