@@ -43,16 +43,20 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class<DPCTLSyclDeviceRef>,
43
43
44
44
struct TestDPCTLContextInterface : public ::testing::TestWithParam<const char *>
45
45
{
46
- DPCTLSyclDeviceSelectorRef DSRef = nullptr ;
46
+ DPCTLSyclDeviceRef DRef = nullptr ;
47
47
48
48
TestDPCTLContextInterface ()
49
49
{
50
- EXPECT_NO_FATAL_FAILURE (DSRef = DPCTLFilterSelector_Create (GetParam ()));
50
+ auto DS = DPCTLFilterSelector_Create (GetParam ());
51
+ if (DS) {
52
+ EXPECT_NO_FATAL_FAILURE (DRef = DPCTLDevice_CreateFromSelector (DS));
53
+ }
54
+ DPCTLDeviceSelector_Delete (DS);
51
55
}
52
56
53
57
void SetUp ()
54
58
{
55
- if (!DSRef ) {
59
+ if (!DRef ) {
56
60
auto message = " Skipping as no device of type " +
57
61
std::string (GetParam ()) + " ." ;
58
62
GTEST_SKIP_ (message.c_str ());
@@ -61,32 +65,23 @@ struct TestDPCTLContextInterface : public ::testing::TestWithParam<const char *>
61
65
62
66
~TestDPCTLContextInterface ()
63
67
{
64
- EXPECT_NO_FATAL_FAILURE (DPCTLDeviceSelector_Delete (DSRef ));
68
+ EXPECT_NO_FATAL_FAILURE (DPCTLDevice_Delete (DRef ));
65
69
}
66
70
};
67
71
68
72
TEST_P (TestDPCTLContextInterface, Chk_Create)
69
73
{
70
74
DPCTLSyclContextRef CRef = nullptr ;
71
- DPCTLSyclDeviceRef DRef = nullptr ;
72
- EXPECT_NO_FATAL_FAILURE (DRef = DPCTLDevice_CreateFromSelector (DSRef));
73
- if (!DRef)
74
- GTEST_SKIP_ (" Device not found" );
75
75
EXPECT_NO_FATAL_FAILURE (CRef = DPCTLContext_Create (DRef, nullptr , 0 ));
76
76
ASSERT_TRUE (CRef);
77
- EXPECT_NO_FATAL_FAILURE (DPCTLDevice_Delete (DRef));
78
77
EXPECT_NO_FATAL_FAILURE (DPCTLContext_Delete (CRef));
79
78
}
80
79
81
80
TEST_P (TestDPCTLContextInterface, Chk_CreateWithDevices)
82
81
{
83
82
size_t nCUs = 0 ;
84
83
DPCTLSyclContextRef CRef = nullptr ;
85
- DPCTLSyclDeviceRef DRef = nullptr ;
86
84
DPCTLDeviceVectorRef DVRef = nullptr ;
87
- EXPECT_NO_FATAL_FAILURE (DRef = DPCTLDevice_CreateFromSelector (DSRef));
88
- if (!DRef)
89
- GTEST_SKIP_ (" Device not found" );
90
85
91
86
/* TODO: Once we have wrappers for sub-device creation let us use those
92
87
* functions.
@@ -108,20 +103,67 @@ TEST_P(TestDPCTLContextInterface, Chk_CreateWithDevices)
108
103
GTEST_SKIP_ (" Skipping creating context for sub-devices" );
109
104
}
110
105
}
111
- EXPECT_NO_FATAL_FAILURE (DPCTLDevice_Delete (DRef));
112
106
EXPECT_NO_FATAL_FAILURE (DPCTLDeviceVector_Delete (DVRef));
113
107
EXPECT_NO_FATAL_FAILURE (DPCTLContext_Delete (CRef));
114
108
}
115
109
110
+ TEST_P (TestDPCTLContextInterface, Chk_CreateWithDevices_GetDevices)
111
+ {
112
+ size_t nCUs = 0 ;
113
+ DPCTLSyclContextRef CRef = nullptr ;
114
+ DPCTLDeviceVectorRef DVRef = nullptr ;
115
+ DPCTLDeviceVectorRef Res_DVRef = nullptr ;
116
+
117
+ /* TODO: Once we have wrappers for sub-device creation let us use those
118
+ * functions.
119
+ */
120
+ EXPECT_NO_FATAL_FAILURE (nCUs = DPCTLDevice_GetMaxComputeUnits (DRef));
121
+ if (nCUs) {
122
+ auto D = unwrap (DRef);
123
+ try {
124
+ auto subDevices = D->create_sub_devices <
125
+ info::partition_property::partition_equally>(nCUs / 2 );
126
+ const size_t len = subDevices.size ();
127
+ auto ar = new DPCTLSyclDeviceRef[len];
128
+ for (size_t i = 0 ; i < len; ++i) {
129
+ ar[i] = wrap (&subDevices.at (i));
130
+ }
131
+ EXPECT_NO_FATAL_FAILURE (
132
+ DVRef = DPCTLDeviceVector_CreateFromArray (len, ar));
133
+ EXPECT_NO_FATAL_FAILURE (
134
+ CRef = DPCTLContext_CreateFromDevices (DVRef, nullptr , 0 ));
135
+ ASSERT_TRUE (CRef);
136
+ ASSERT_TRUE (DPCTLContext_DeviceCount (CRef) == len);
137
+ EXPECT_NO_FATAL_FAILURE (Res_DVRef = DPCTLContext_GetDevices (CRef));
138
+ ASSERT_TRUE (DPCTLDeviceVector_Size (Res_DVRef) == len);
139
+ delete[] ar;
140
+ } catch (feature_not_supported const &fnse) {
141
+ GTEST_SKIP_ (" Skipping creating context for sub-devices" );
142
+ }
143
+ }
144
+ EXPECT_NO_FATAL_FAILURE (DPCTLDeviceVector_Delete (DVRef));
145
+ EXPECT_NO_FATAL_FAILURE (DPCTLContext_Delete (CRef));
146
+ EXPECT_NO_FATAL_FAILURE (DPCTLDeviceVector_Delete (Res_DVRef));
147
+ }
148
+
149
+ TEST_P (TestDPCTLContextInterface, Chk_GetDevices)
150
+ {
151
+ DPCTLSyclContextRef CRef = nullptr ;
152
+ DPCTLDeviceVectorRef DVRef = nullptr ;
153
+ EXPECT_NO_FATAL_FAILURE (CRef = DPCTLContext_Create (DRef, nullptr , 0 ));
154
+ ASSERT_TRUE (CRef);
155
+ EXPECT_NO_FATAL_FAILURE (DVRef = DPCTLContext_GetDevices (CRef));
156
+ ASSERT_TRUE (DVRef);
157
+ EXPECT_TRUE (DPCTLDeviceVector_Size (DVRef) == 1 );
158
+ EXPECT_NO_FATAL_FAILURE (DPCTLContext_Delete (CRef));
159
+ EXPECT_NO_FATAL_FAILURE (DPCTLDeviceVector_Delete (DVRef));
160
+ }
161
+
116
162
TEST_P (TestDPCTLContextInterface, Chk_AreEq)
117
163
{
118
164
DPCTLSyclContextRef CRef1 = nullptr , CRef2 = nullptr , CRef3 = nullptr ;
119
- DPCTLSyclDeviceRef DRef = nullptr ;
120
165
bool are_eq = true , are_not_eq = false ;
121
166
122
- EXPECT_NO_FATAL_FAILURE (DRef = DPCTLDevice_CreateFromSelector (DSRef));
123
- if (!DRef)
124
- GTEST_SKIP_ (" Device not found" );
125
167
EXPECT_NO_FATAL_FAILURE (CRef1 = DPCTLContext_Create (DRef, nullptr , 0 ));
126
168
EXPECT_NO_FATAL_FAILURE (CRef2 = DPCTLContext_Copy (CRef1));
127
169
// TODO: This work till DPC++ does not have a default context per device,
@@ -136,7 +178,6 @@ TEST_P(TestDPCTLContextInterface, Chk_AreEq)
136
178
EXPECT_TRUE (are_eq);
137
179
EXPECT_FALSE (are_not_eq);
138
180
139
- EXPECT_NO_FATAL_FAILURE (DPCTLDevice_Delete (DRef));
140
181
EXPECT_NO_FATAL_FAILURE (DPCTLContext_Delete (CRef1));
141
182
EXPECT_NO_FATAL_FAILURE (DPCTLContext_Delete (CRef2));
142
183
EXPECT_NO_FATAL_FAILURE (DPCTLContext_Delete (CRef3));
@@ -145,41 +186,31 @@ TEST_P(TestDPCTLContextInterface, Chk_AreEq)
145
186
TEST_P (TestDPCTLContextInterface, Chk_IsHost)
146
187
{
147
188
DPCTLSyclContextRef CRef = nullptr ;
148
- DPCTLSyclDeviceRef DRef = nullptr ;
149
189
bool is_host_device = false , is_host_context = false ;
150
190
151
- EXPECT_NO_FATAL_FAILURE (DRef = DPCTLDevice_CreateFromSelector (DSRef));
152
- if (!DRef)
153
- GTEST_SKIP_ (" Device not found" );
154
191
EXPECT_NO_FATAL_FAILURE (CRef = DPCTLContext_Create (DRef, nullptr , 0 ));
155
192
ASSERT_TRUE (CRef);
156
193
157
194
EXPECT_NO_FATAL_FAILURE (is_host_device = DPCTLDevice_IsHost (DRef));
158
195
EXPECT_NO_FATAL_FAILURE (is_host_context = DPCTLContext_IsHost (CRef));
159
196
EXPECT_TRUE (is_host_device == is_host_context);
160
197
161
- EXPECT_NO_FATAL_FAILURE (DPCTLDevice_Delete (DRef));
162
198
EXPECT_NO_FATAL_FAILURE (DPCTLContext_Delete (CRef));
163
199
}
164
200
165
201
TEST_P (TestDPCTLContextInterface, Chk_GetBackend)
166
202
{
167
203
DPCTLSyclContextRef CRef = nullptr ;
168
- DPCTLSyclDeviceRef DRef = nullptr ;
169
204
DPCTLSyclBackendType context_backend = DPCTL_UNKNOWN_BACKEND,
170
205
device_backend = DPCTL_UNKNOWN_BACKEND;
171
206
172
- EXPECT_NO_FATAL_FAILURE (DRef = DPCTLDevice_CreateFromSelector (DSRef));
173
- if (!DRef)
174
- GTEST_SKIP_ (" Device not found" );
175
207
EXPECT_NO_FATAL_FAILURE (CRef = DPCTLContext_Create (DRef, nullptr , 0 ));
176
208
ASSERT_TRUE (CRef);
177
209
178
210
EXPECT_NO_FATAL_FAILURE (device_backend = DPCTLDevice_GetBackend (DRef));
179
211
EXPECT_NO_FATAL_FAILURE (context_backend = DPCTLContext_GetBackend (CRef));
180
212
EXPECT_TRUE (device_backend == context_backend);
181
213
182
- EXPECT_NO_FATAL_FAILURE (DPCTLDevice_Delete (DRef));
183
214
EXPECT_NO_FATAL_FAILURE (DPCTLContext_Delete (CRef));
184
215
}
185
216
0 commit comments