24
24
// /
25
25
// ===----------------------------------------------------------------------===//
26
26
27
+ #include " ../helper/include/dpctl_utils_helper.h"
27
28
#include " dpctl_sycl_device_interface.h"
28
29
#include " dpctl_sycl_device_manager.h"
29
30
#include " dpctl_sycl_device_selector_interface.h"
30
31
#include < gtest/gtest.h>
32
+ #include < string>
31
33
32
34
struct TestDPCTLDeviceManager : public ::testing::TestWithParam<const char *>
33
35
{
@@ -81,12 +83,12 @@ INSTANTIATE_TEST_SUITE_P(DeviceMgrFunctions,
81
83
" opencl:cpu:0" ,
82
84
" level_zero:gpu:0" ));
83
85
84
- struct TestDPCTLDeviceVector : public ::testing::TestWithParam<int >
86
+ struct TestDPCTLGetDevices : public ::testing::TestWithParam<int >
85
87
{
86
88
DPCTLDeviceVectorRef DV = nullptr ;
87
89
size_t nDevices = 0 ;
88
90
89
- TestDPCTLDeviceVector ()
91
+ TestDPCTLGetDevices ()
90
92
{
91
93
EXPECT_NO_FATAL_FAILURE (DV = DPCTLDeviceMgr_GetDevices (GetParam ()));
92
94
EXPECT_TRUE (DV != nullptr );
@@ -100,14 +102,14 @@ struct TestDPCTLDeviceVector : public ::testing::TestWithParam<int>
100
102
}
101
103
}
102
104
103
- ~TestDPCTLDeviceVector ()
105
+ ~TestDPCTLGetDevices ()
104
106
{
105
107
EXPECT_NO_FATAL_FAILURE (DPCTLDeviceVector_Clear (DV));
106
108
EXPECT_NO_FATAL_FAILURE (DPCTLDeviceVector_Delete (DV));
107
109
}
108
110
};
109
111
110
- TEST_P (TestDPCTLDeviceVector , ChkGetAt)
112
+ TEST_P (TestDPCTLGetDevices , ChkGetAt)
111
113
{
112
114
for (auto i = 0ul ; i < nDevices; ++i) {
113
115
DPCTLSyclDeviceRef DRef = nullptr ;
@@ -118,14 +120,18 @@ TEST_P(TestDPCTLDeviceVector, ChkGetAt)
118
120
119
121
INSTANTIATE_TEST_SUITE_P (
120
122
GetDevices,
121
- TestDPCTLDeviceVector ,
123
+ TestDPCTLGetDevices ,
122
124
::testing::Values (DPCTLSyclBackendType::DPCTL_HOST,
123
125
DPCTLSyclBackendType::DPCTL_LEVEL_ZERO,
124
126
DPCTLSyclBackendType::DPCTL_OPENCL,
125
127
DPCTLSyclBackendType::DPCTL_OPENCL |
126
128
DPCTLSyclDeviceType::DPCTL_GPU));
127
129
128
- TEST (TestDPCTLDeviceVector, ChkDPCTLDeviceVectorCreate)
130
+ struct TestDPCTLDeviceVector : public ::testing::Test
131
+ {
132
+ };
133
+
134
+ TEST_F (TestDPCTLDeviceVector, ChkDPCTLDeviceVectorCreate)
129
135
{
130
136
DPCTLDeviceVectorRef DVRef = nullptr ;
131
137
size_t nDevices = 0 ;
@@ -135,3 +141,63 @@ TEST(TestDPCTLDeviceVector, ChkDPCTLDeviceVectorCreate)
135
141
EXPECT_TRUE (nDevices == 0 );
136
142
EXPECT_NO_FATAL_FAILURE (DPCTLDeviceVector_Delete (DVRef));
137
143
}
144
+
145
+ struct TestDPCTLGetDevicesOrdering : public ::testing::TestWithParam<int >
146
+ {
147
+ DPCTLDeviceVectorRef DV = nullptr ;
148
+ size_t nDevices = 0 ;
149
+
150
+ TestDPCTLGetDevicesOrdering ()
151
+ {
152
+ const int device_type_mask =
153
+ (GetParam () & DPCTLSyclDeviceType::DPCTL_ALL) |
154
+ DPCTLSyclBackendType::DPCTL_ALL_BACKENDS;
155
+ EXPECT_NO_FATAL_FAILURE (
156
+ DV = DPCTLDeviceMgr_GetDevices (device_type_mask));
157
+ EXPECT_TRUE (DV != nullptr );
158
+ EXPECT_NO_FATAL_FAILURE (nDevices = DPCTLDeviceVector_Size (DV));
159
+ }
160
+
161
+ void SetUp ()
162
+ {
163
+ if (!nDevices) {
164
+ GTEST_SKIP_ (" Skipping as no devices returned for identifier" );
165
+ }
166
+ }
167
+
168
+ ~TestDPCTLGetDevicesOrdering ()
169
+ {
170
+ EXPECT_NO_FATAL_FAILURE (DPCTLDeviceVector_Clear (DV));
171
+ EXPECT_NO_FATAL_FAILURE (DPCTLDeviceVector_Delete (DV));
172
+ }
173
+ };
174
+
175
+ TEST_P (TestDPCTLGetDevicesOrdering, ChkConsistencyWithFilterSelector)
176
+ {
177
+ for (auto i = 0ul ; i < nDevices; ++i) {
178
+ DPCTLSyclDeviceType Dty;
179
+ std::string fs_device_type, fs;
180
+ DPCTLSyclDeviceRef DRef = nullptr , D0Ref = nullptr ;
181
+ DPCTLSyclDeviceSelectorRef DSRef = nullptr ;
182
+ EXPECT_NO_FATAL_FAILURE (DRef = DPCTLDeviceVector_GetAt (DV, i));
183
+ EXPECT_NO_FATAL_FAILURE (Dty = DPCTLDevice_GetDeviceType (DRef));
184
+ EXPECT_NO_FATAL_FAILURE (
185
+ fs_device_type = DPCTL_DeviceTypeToStr (
186
+ DPCTL_DPCTLDeviceTypeToSyclDeviceType (Dty)));
187
+ EXPECT_NO_FATAL_FAILURE (fs = fs_device_type + " :" + std::to_string (i));
188
+ EXPECT_NO_FATAL_FAILURE (DSRef = DPCTLFilterSelector_Create (fs.c_str ()));
189
+ EXPECT_NO_FATAL_FAILURE (D0Ref = DPCTLDevice_CreateFromSelector (DSRef));
190
+ EXPECT_NO_FATAL_FAILURE (DPCTLDeviceSelector_Delete (DSRef));
191
+ EXPECT_TRUE (DPCTLDevice_AreEq (DRef, D0Ref));
192
+ EXPECT_NO_FATAL_FAILURE (DPCTLDevice_Delete (D0Ref));
193
+ EXPECT_NO_FATAL_FAILURE (DPCTLDevice_Delete (DRef));
194
+ }
195
+ }
196
+
197
+ INSTANTIATE_TEST_SUITE_P (
198
+ GetDevices,
199
+ TestDPCTLGetDevicesOrdering,
200
+ ::testing::Values (DPCTLSyclDeviceType::DPCTL_HOST_DEVICE,
201
+ DPCTLSyclDeviceType::DPCTL_ACCELERATOR,
202
+ DPCTLSyclDeviceType::DPCTL_GPU,
203
+ DPCTLSyclDeviceType::DPCTL_CPU));
0 commit comments