-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtest_sycl_kernel_interface.cpp
More file actions
273 lines (224 loc) · 8.36 KB
/
test_sycl_kernel_interface.cpp
File metadata and controls
273 lines (224 loc) · 8.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
//===-- test_sycl_kernel_interface.cpp - Test cases for kernel interface ===//
//
// Data Parallel Control (dpctl)
//
// Copyright 2020-2024 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file has unit test cases for functions defined in
/// dpctl_sycl_kernel_interface.h.
///
//===----------------------------------------------------------------------===//
#include "Config/dpctl_config.h"
#include "dpctl_sycl_context_interface.h"
#include "dpctl_sycl_device_interface.h"
#include "dpctl_sycl_device_selector_interface.h"
#include "dpctl_sycl_kernel_bundle_interface.h"
#include "dpctl_sycl_kernel_interface.h"
#include "dpctl_sycl_queue_interface.h"
#include "dpctl_utils.h"
#include <stddef.h>
#include <array>
#include <gtest/gtest.h>
#include <sycl/sycl.hpp>
using namespace sycl;
namespace
{
struct TestDPCTLSyclKernelInterface
: public ::testing::TestWithParam<const char *>
{
const char *CLProgramStr = R"CLC(
kernel void add(global int* a, global int* b, global int* c) {
size_t index = get_global_id(0);
c[index] = a[index] + b[index];
}
kernel void axpy(global int* a, global int* b, global int* c, int d) {
size_t index = get_global_id(0);
c[index] = a[index] + d*b[index];
}
)CLC";
const char *CompileOpts = "-cl-fast-relaxed-math";
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
DPCTLSyclDeviceRef DRef = nullptr;
DPCTLSyclQueueRef QRef = nullptr;
DPCTLSyclContextRef CtxRef = nullptr;
DPCTLSyclKernelBundleRef KBRef = nullptr;
DPCTLSyclKernelRef AddKRef = nullptr;
DPCTLSyclKernelRef AxpyKRef = nullptr;
TestDPCTLSyclKernelInterface()
{
DSRef = DPCTLFilterSelector_Create(GetParam());
DRef = DPCTLDevice_CreateFromSelector(DSRef);
QRef = DPCTLQueue_CreateForDevice(DRef, nullptr, 0);
CtxRef = DPCTLQueue_GetContext(QRef);
KBRef = DPCTLKernelBundle_CreateFromOCLSource(
CtxRef, DRef, CLProgramStr, CompileOpts);
AddKRef = DPCTLKernelBundle_GetKernel(KBRef, "add");
AxpyKRef = DPCTLKernelBundle_GetKernel(KBRef, "axpy");
}
~TestDPCTLSyclKernelInterface()
{
DPCTLDeviceSelector_Delete(DSRef);
DPCTLDevice_Delete(DRef);
DPCTLQueue_Delete(QRef);
DPCTLContext_Delete(CtxRef);
DPCTLKernelBundle_Delete(KBRef);
DPCTLKernel_Delete(AddKRef);
DPCTLKernel_Delete(AxpyKRef);
}
void SetUp()
{
if (!DRef) {
auto message = "Skipping as no device of type " +
std::string(GetParam()) + ".";
GTEST_SKIP_(message.c_str());
}
}
};
} // namespace
TEST_P(TestDPCTLSyclKernelInterface, CheckGetNumArgs)
{
ASSERT_EQ(DPCTLKernel_GetNumArgs(AddKRef), 3ul);
ASSERT_EQ(DPCTLKernel_GetNumArgs(AxpyKRef), 4ul);
}
TEST_P(TestDPCTLSyclKernelInterface, CheckCopy)
{
DPCTLSyclKernelRef Copied_KRef = nullptr;
EXPECT_NO_FATAL_FAILURE(Copied_KRef = DPCTLKernel_Copy(AddKRef));
ASSERT_EQ(DPCTLKernel_GetNumArgs(Copied_KRef), 3ul);
EXPECT_NO_FATAL_FAILURE(DPCTLKernel_Delete(Copied_KRef));
}
TEST_P(TestDPCTLSyclKernelInterface, CheckGetWorkGroupSize)
{
size_t add_wgsz = 0, axpy_wgsz = 0;
EXPECT_NO_FATAL_FAILURE(add_wgsz = DPCTLKernel_GetWorkGroupSize(AddKRef));
EXPECT_NO_FATAL_FAILURE(axpy_wgsz = DPCTLKernel_GetWorkGroupSize(AxpyKRef));
ASSERT_TRUE(add_wgsz != 0);
ASSERT_TRUE(axpy_wgsz != 0);
}
TEST_P(TestDPCTLSyclKernelInterface, CheckGetPreferredWorkGroupSizeMultiple)
{
size_t add_wgsz_m = 0, axpy_wgsz_m = 0;
EXPECT_NO_FATAL_FAILURE(
add_wgsz_m = DPCTLKernel_GetPreferredWorkGroupSizeMultiple(AddKRef));
EXPECT_NO_FATAL_FAILURE(
axpy_wgsz_m = DPCTLKernel_GetPreferredWorkGroupSizeMultiple(AxpyKRef));
ASSERT_TRUE(add_wgsz_m != 0);
ASSERT_TRUE(axpy_wgsz_m != 0);
}
TEST_P(TestDPCTLSyclKernelInterface, CheckGetPrivateMemSize)
{
size_t add_private_mem_sz = 0, axpy_private_mem_sz = 0;
EXPECT_NO_FATAL_FAILURE(add_private_mem_sz =
DPCTLKernel_GetPrivateMemSize(AddKRef));
EXPECT_NO_FATAL_FAILURE(axpy_private_mem_sz =
DPCTLKernel_GetPrivateMemSize(AxpyKRef));
ASSERT_TRUE(add_private_mem_sz >= 0);
ASSERT_TRUE(axpy_private_mem_sz >= 0);
}
TEST_P(TestDPCTLSyclKernelInterface, CheckGetMaxNumSubGroups)
{
uint32_t add_mnsg = 0, axpy_mnsg = 0;
EXPECT_NO_FATAL_FAILURE(add_mnsg = DPCTLKernel_GetMaxNumSubGroups(AddKRef));
EXPECT_NO_FATAL_FAILURE(axpy_mnsg =
DPCTLKernel_GetMaxNumSubGroups(AxpyKRef));
ASSERT_TRUE(add_mnsg != 0);
ASSERT_TRUE(axpy_mnsg != 0);
}
TEST_P(TestDPCTLSyclKernelInterface, CheckGetMaxSubGroupSize)
{
uint32_t add_msg_sz = 0, axpy_msg_sz = 0;
EXPECT_NO_FATAL_FAILURE(add_msg_sz =
DPCTLKernel_GetMaxSubGroupSize(AddKRef));
EXPECT_NO_FATAL_FAILURE(axpy_msg_sz =
DPCTLKernel_GetMaxSubGroupSize(AxpyKRef));
ASSERT_TRUE(add_msg_sz != 0);
ASSERT_TRUE(axpy_msg_sz != 0);
}
TEST_P(TestDPCTLSyclKernelInterface, CheckGetCompileNumSubGroups)
{
uint32_t add_cnsg = 0, axpy_cnsg = 0;
EXPECT_NO_FATAL_FAILURE(add_cnsg =
DPCTLKernel_GetCompileNumSubGroups(AddKRef));
EXPECT_NO_FATAL_FAILURE(axpy_cnsg =
DPCTLKernel_GetCompileNumSubGroups(AxpyKRef));
EXPECT_TRUE(add_cnsg >= 0);
EXPECT_TRUE(axpy_cnsg >= 0);
}
TEST_P(TestDPCTLSyclKernelInterface, CheckGetCompileSubGroupSize)
{
uint32_t add_csg_sz = 0, axpy_csg_sz = 0;
EXPECT_NO_FATAL_FAILURE(add_csg_sz =
DPCTLKernel_GetCompileSubGroupSize(AddKRef));
EXPECT_NO_FATAL_FAILURE(axpy_csg_sz =
DPCTLKernel_GetCompileSubGroupSize(AxpyKRef));
EXPECT_TRUE(add_csg_sz >= 0);
EXPECT_TRUE(axpy_csg_sz >= 0);
}
INSTANTIATE_TEST_SUITE_P(TestKernelInterfaceFunctions,
TestDPCTLSyclKernelInterface,
::testing::Values("opencl:gpu:0", "opencl:cpu:0"));
struct TestDPCTLSyclKernelNullArgs : public ::testing::Test
{
DPCTLSyclKernelRef Null_KRef;
TestDPCTLSyclKernelNullArgs() : Null_KRef(nullptr) {}
~TestDPCTLSyclKernelNullArgs() {}
};
TEST_F(TestDPCTLSyclKernelNullArgs, CheckNumArgsNullKRef)
{
ASSERT_EQ(DPCTLKernel_GetNumArgs(Null_KRef), -1);
}
TEST_F(TestDPCTLSyclKernelNullArgs, CheckCopyNullKRef)
{
ASSERT_TRUE(DPCTLKernel_Copy(Null_KRef) == nullptr);
}
TEST_F(TestDPCTLSyclKernelNullArgs, CheckGetWorkGroupsSizeNullKRef)
{
DPCTLSyclKernelRef NullKRef = nullptr;
ASSERT_EQ(DPCTLKernel_GetWorkGroupSize(NullKRef), 0);
}
TEST_F(TestDPCTLSyclKernelNullArgs,
CheckGetPreferredWorkGroupsSizeMultipleNullKRef)
{
DPCTLSyclKernelRef NullKRef = nullptr;
ASSERT_EQ(DPCTLKernel_GetPreferredWorkGroupSizeMultiple(NullKRef), 0);
}
TEST_F(TestDPCTLSyclKernelNullArgs, CheckGetPrivateMemSizeNullKRef)
{
DPCTLSyclKernelRef NullKRef = nullptr;
ASSERT_EQ(DPCTLKernel_GetPrivateMemSize(NullKRef), 0);
}
TEST_F(TestDPCTLSyclKernelNullArgs, CheckGetMaxNumSubGroupsNullKRef)
{
DPCTLSyclKernelRef NullKRef = nullptr;
ASSERT_EQ(DPCTLKernel_GetMaxNumSubGroups(NullKRef), 0);
}
TEST_F(TestDPCTLSyclKernelNullArgs, CheckGetMaxSubGroupSizeNullKRef)
{
DPCTLSyclKernelRef NullKRef = nullptr;
ASSERT_EQ(DPCTLKernel_GetMaxSubGroupSize(NullKRef), 0);
}
TEST_F(TestDPCTLSyclKernelNullArgs, CheckGetCompileNumSubGroupsNullKRef)
{
DPCTLSyclKernelRef NullKRef = nullptr;
ASSERT_EQ(DPCTLKernel_GetCompileNumSubGroups(NullKRef), 0);
}
TEST_F(TestDPCTLSyclKernelNullArgs, CheckGetCompileSubGroupSizeNullKRef)
{
DPCTLSyclKernelRef NullKRef = nullptr;
ASSERT_EQ(DPCTLKernel_GetCompileSubGroupSize(NullKRef), 0);
}