• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IntelPython / dpctl / 42407937296

07 Nov 2026 07:47PM UTC coverage: 75.173% (+0.04%) from 75.137%
42407937296

Pull #2412

github

web-flow
Merge 7383d0637 into 2ed816f33
Pull Request #2412: Add `sycl_platform::has_aspect` properties

1082 of 1516 branches covered (71.37%)

Branch coverage included in aggregate %.

14 of 16 new or added lines in 1 file covered. (87.5%)

4135 of 5424 relevant lines covered (76.24%)

286.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.38
/libsyclinterface/source/dpctl_sycl_platform_interface.cpp
1
//=== dpctl_sycl_platform_interface.cpp - Implements C API for sycl::platform //
2
//
3
//                      Data Parallel Control (dpctl)
4
//
5
// Copyright 2020 Intel Corporation
6
//
7
// Licensed under the Apache License, Version 2.0 (the "License");
8
// you may not use this file except in compliance with the License.
9
// You may obtain a copy of the License at
10
//
11
//    http://www.apache.org/licenses/LICENSE-2.0
12
//
13
// Unless required by applicable law or agreed to in writing, software
14
// distributed under the License is distributed on an "AS IS" BASIS,
15
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
// See the License for the specific language governing permissions and
17
// limitations under the License.
18
//
19
//===----------------------------------------------------------------------===//
20
///
21
/// \file
22
/// This file implements the functions declared in
23
/// dpctl_sycl_platform_interface.h.
24
///
25
//===----------------------------------------------------------------------===//
26

27
#include "dpctl_sycl_platform_interface.h"
28
#include "Config/dpctl_config.h"
29
#include "dpctl_device_selection.hpp"
30
#include "dpctl_error_handlers.h"
31
#include "dpctl_string_utils.hpp"
32
#include "dpctl_sycl_enum_types.h"
33
#include "dpctl_sycl_type_casters.hpp"
34
#include "dpctl_utils_helper.h"
35
#include <iomanip>
36
#include <iostream>
37
#include <set>
38
#include <sstream>
39
#include <stddef.h>
40
#include <sycl/sycl.hpp>
41
#include <utility>
42
#include <vector>
43

44
using namespace sycl;
45

46
namespace
47
{
48
static_assert(__SYCL_COMPILER_VERSION >= __SYCL_COMPILER_VERSION_REQUIRED,
49
              "The compiler does not meet minimum version requirement");
50

51
using namespace dpctl::syclinterface;
52

53
platform *new_platform_from_selector(const dpctl_device_selector *sel)
54
{
359 ✔
55
    return new platform(
359 ✔
56
        [=](const device &d) -> int { return sel->operator()(d); });
359 ✔
57
}
359 ✔
58

59
} // end of anonymous namespace
60

61
__dpctl_give DPCTLSyclPlatformRef
62
DPCTLPlatform_Copy(__dpctl_keep const DPCTLSyclPlatformRef PRef)
63
{
56 ✔
64
    auto Platform = unwrap<platform>(PRef);
56 ✔
65
    if (!Platform) {
56 ✔
66
        error_handler("Cannot copy DPCTLSyclPlatformRef as input is a nullptr.",
5 ✔
67
                      __FILE__, __func__, __LINE__);
5 ✔
68
        return nullptr;
5 ✔
69
    }
5 ✔
70
    try {
51 ✔
71
        auto CopiedPlatform = new platform(*Platform);
51 ✔
72
        return wrap<platform>(CopiedPlatform);
51 ✔
73
    } catch (std::exception const &e) {
51 ✔
74
        error_handler(e, __FILE__, __func__, __LINE__);
×
75
        return nullptr;
×
76
    }
×
77
}
51 ✔
78

79
__dpctl_give DPCTLSyclPlatformRef DPCTLPlatform_Create()
80
{
24 ✔
81
    DPCTLSyclPlatformRef PRef = nullptr;
24 ✔
82
    try {
24 ✔
83
        auto P = new platform();
24 ✔
84
        PRef = wrap<platform>(P);
24 ✔
85
    } catch (std::exception const &e) {
24 ✔
86
        error_handler(e, __FILE__, __func__, __LINE__);
×
87
    }
×
88
    return PRef;
24 ✔
89
}
24 ✔
90

91
__dpctl_give DPCTLSyclPlatformRef DPCTLPlatform_CreateFromSelector(
92
    __dpctl_keep const DPCTLSyclDeviceSelectorRef DSRef)
93
{
390 ✔
94
    if (DSRef) {
390 ✔
95
        auto DS = unwrap<dpctl_device_selector>(DSRef);
359 ✔
96
        platform *P = nullptr;
359 ✔
97
        try {
359 ✔
98
            P = new_platform_from_selector(DS);
359 ✔
99
            return wrap<platform>(P);
359 ✔
100
        } catch (std::exception const &e) {
359 ✔
101
            delete P;
259 ✔
102
            error_handler(e, __FILE__, __func__, __LINE__);
259 ✔
103
            return nullptr;
259 ✔
104
        }
259 ✔
105
    }
359 ✔
106
    else {
31 ✔
107
        error_handler("Device selector pointer cannot be NULL.", __FILE__,
31 ✔
108
                      __func__, __LINE__);
31 ✔
109
    }
31 ✔
110

111
    return nullptr;
31 ✔
112
}
390 ✔
113

114
void DPCTLPlatform_Delete(__dpctl_take DPCTLSyclPlatformRef PRef)
115
{
534 ✔
116
    auto P = unwrap<platform>(PRef);
534 ✔
117
    delete P;
534 ✔
118
}
534 ✔
119

120
DPCTLSyclBackendType
121
DPCTLPlatform_GetBackend(__dpctl_keep const DPCTLSyclPlatformRef PRef)
122
{
15 ✔
123
    DPCTLSyclBackendType BTy = DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
15 ✔
124
    auto P = unwrap<platform>(PRef);
15 ✔
125
    if (P) {
15 ✔
126
        BTy = DPCTL_SyclBackendToDPCTLBackendType(P->get_backend());
14 ✔
127
    }
14 ✔
128
    else {
1 ✔
129
        error_handler("Backend cannot be looked up for a NULL platform.",
1 ✔
130
                      __FILE__, __func__, __LINE__);
1 ✔
131
    }
1 ✔
132
    return BTy;
15 ✔
133
}
15 ✔
134

135
__dpctl_give const char *
136
DPCTLPlatform_GetName(__dpctl_keep const DPCTLSyclPlatformRef PRef)
137
{
143 ✔
138
    auto P = unwrap<platform>(PRef);
143 ✔
139
    if (P) {
143 ✔
140
        try {
142 ✔
141
            auto name = P->get_info<info::platform::name>();
142 ✔
142
            return dpctl::helper::cstring_from_string(name);
142 ✔
143
        } catch (std::exception const &e) {
142 ✔
144
            error_handler(e, __FILE__, __func__, __LINE__);
×
145
            return nullptr;
×
146
        }
×
147
    }
142 ✔
148
    else {
1 ✔
149
        error_handler("Name cannot be looked up for a NULL platform.", __FILE__,
1 ✔
150
                      __func__, __LINE__);
1 ✔
151
        return nullptr;
1 ✔
152
    }
1 ✔
153
}
143 ✔
154

155
__dpctl_give const char *
156
DPCTLPlatform_GetVendor(__dpctl_keep const DPCTLSyclPlatformRef PRef)
157
{
143 ✔
158
    auto P = unwrap<platform>(PRef);
143 ✔
159
    if (P) {
143 ✔
160
        try {
142 ✔
161
            auto vendor = P->get_info<info::platform::vendor>();
142 ✔
162
            return dpctl::helper::cstring_from_string(vendor);
142 ✔
163
        } catch (std::exception const &e) {
142 ✔
164
            error_handler(e, __FILE__, __func__, __LINE__);
×
165
            return nullptr;
×
166
        }
×
167
    }
142 ✔
168
    else {
1 ✔
169
        error_handler("Vendor cannot be looked up for a NULL platform.",
1 ✔
170
                      __FILE__, __func__, __LINE__);
1 ✔
171
        return nullptr;
1 ✔
172
    }
1 ✔
173
}
143 ✔
174

175
__dpctl_give const char *
176
DPCTLPlatform_GetVersion(__dpctl_keep const DPCTLSyclPlatformRef PRef)
177
{
143 ✔
178
    auto P = unwrap<platform>(PRef);
143 ✔
179
    if (P) {
143 ✔
180
        try {
142 ✔
181
            auto driver = P->get_info<info::platform::version>();
142 ✔
182
            return dpctl::helper::cstring_from_string(driver);
142 ✔
183
        } catch (std::exception const &e) {
142 ✔
184
            error_handler(e, __FILE__, __func__, __LINE__);
×
185
            return nullptr;
×
186
        }
×
187
    }
142 ✔
188
    else {
1 ✔
189
        error_handler("Driver version cannot be looked up for a NULL platform.",
1 ✔
190
                      __FILE__, __func__, __LINE__);
1 ✔
191
        return nullptr;
1 ✔
192
    }
1 ✔
193
}
143 ✔
194

195
__dpctl_give DPCTLPlatformVectorRef DPCTLPlatform_GetPlatforms()
196
{
21 ✔
197
    using vecTy = std::vector<DPCTLSyclPlatformRef>;
21 ✔
198
    vecTy *Platforms = nullptr;
21 ✔
199

200
    std::vector<platform> platforms;
21 ✔
201
    try {
21 ✔
202
        platforms = platform::get_platforms();
21 ✔
203
    } catch (std::exception const &e) {
21 ✔
204
        error_handler(e, __FILE__, __func__, __LINE__);
×
205
        return nullptr;
×
206
    }
×
207

208
    try {
21 ✔
209
        Platforms = new vecTy();
21 ✔
210
        Platforms->reserve(platforms.size());
21 ✔
211
    } catch (std::exception const &e) {
21 ✔
212
        error_handler(e, __FILE__, __func__, __LINE__);
×
213
        return nullptr;
×
214
    }
×
215

216
    // populate the vector
217
    for (const auto &P : platforms) {
21 ✔
218
        Platforms->emplace_back(wrap<platform>(new platform(P)));
21 ✔
219
    }
21 ✔
220

221
    // the wrap function is defined inside dpctl_vector_templ.cpp
222
    return wrap<vecTy>(Platforms);
21 ✔
223
}
21 ✔
224

225
__dpctl_give DPCTLSyclContextRef
226
DPCTLPlatform_GetDefaultContext(__dpctl_keep const DPCTLSyclPlatformRef PRef)
227
{
15 ✔
228
    auto P = unwrap<platform>(PRef);
15 ✔
229
    if (P) {
15 ✔
230
#if defined(SYCL_KHR_DEFAULT_CONTEXT) ||                                       \
14 ✔
231
    defined(SYCL_EXT_ONEAPI_DEFAULT_CONTEXT)
14 ✔
232
        try {
14 ✔
233
            const auto &default_ctx = P->
14 ✔
234
#ifdef SYCL_KHR_DEFAULT_CONTEXT
14 ✔
235
                                      khr_get_default_context()
14 ✔
236
#else
237
                                      ext_oneapi_get_default_context()
238
#endif // SYCL_KHR_DEFAULT_CONTEXT
239
                ;
14 ✔
240
            return wrap<context>(new context(default_ctx));
14 ✔
241
        } catch (const std::exception &ex) {
14 ✔
242
            error_handler(ex, __FILE__, __func__, __LINE__);
×
243
            return nullptr;
×
244
        }
×
245
#else
246
        return nullptr;
247
#endif // SYCL_KHR_DEFAULT_CONTEXT || SYCL_EXT_ONEAPI_DEFAULT_CONTEXT
248
    }
14 ✔
249
    else {
1 ✔
250
        error_handler(
1 ✔
251
            "Default platform cannot be obtained up for a NULL platform.",
1 ✔
252
            __FILE__, __func__, __LINE__);
1 ✔
253
        return nullptr;
1 ✔
254
    }
1 ✔
255
}
15 ✔
256

257
bool DPCTLPlatform_AreEq(__dpctl_keep const DPCTLSyclPlatformRef PRef1,
258
                         __dpctl_keep const DPCTLSyclPlatformRef PRef2)
259
{
22 ✔
260
    auto P1 = unwrap<platform>(PRef1);
22 ✔
261
    auto P2 = unwrap<platform>(PRef2);
22 ✔
262
    if (P1 && P2)
22 !
263
        return *P1 == *P2;
18 ✔
264
    else
4 ✔
265
        return false;
4 ✔
266
}
22 ✔
267

268
size_t DPCTLPlatform_Hash(__dpctl_keep const DPCTLSyclPlatformRef PRef)
269
{
32 ✔
270
    if (PRef) {
32 ✔
271
        auto P = unwrap<platform>(PRef);
28 ✔
272
        std::hash<platform> hash_fn;
28 ✔
273
        return hash_fn(*P);
28 ✔
274
    }
28 ✔
275
    else {
4 ✔
276
        error_handler("Argument PRef is null.", __FILE__, __func__, __LINE__);
4 ✔
277
        return 0;
4 ✔
278
    }
4 ✔
279
}
32 ✔
280

281
__dpctl_give DPCTLDeviceVectorRef
282
DPCTLPlatform_GetDevices(__dpctl_keep const DPCTLSyclPlatformRef PRef,
283
                         DPCTLSyclDeviceType DTy)
284
{
125 ✔
285
    auto P = unwrap<platform>(PRef);
125 ✔
286
    if (!P) {
125 !
287
        error_handler("Cannot retrieve devices from DPCTLSyclPlatformRef as "
×
288
                      "input is a nullptr.",
×
289
                      __FILE__, __func__, __LINE__);
×
290
        return nullptr;
×
291
    }
×
292

293
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
125 ✔
294
    vecTy *DevicesVectorPtr = nullptr;
125 ✔
295
    try {
125 ✔
296
        DevicesVectorPtr = new vecTy();
125 ✔
297
    } catch (std::exception const &e) {
125 ✔
298
        delete DevicesVectorPtr;
×
299
        error_handler(e, __FILE__, __func__, __LINE__);
×
300
        return nullptr;
×
301
    }
×
302

303
    if (DTy == DPCTLSyclDeviceType::DPCTL_UNKNOWN_DEVICE) {
125 !
304
        return wrap<vecTy>(DevicesVectorPtr);
×
305
    }
×
306

307
    // Only OpenCL supports custom devices; other backends may warn when asked
308
    // for them (e.g., the Unified Runtime Level Zero adapter)
309
    if (DTy == DPCTLSyclDeviceType::DPCTL_CUSTOM &&
125 !
310
        DPCTL_SyclBackendToDPCTLBackendType(P->get_backend()) !=
×
311
            DPCTLSyclBackendType::DPCTL_OPENCL)
×
312
    {
×
313
        return wrap<vecTy>(DevicesVectorPtr);
×
314
    }
×
315

316
    try {
125 ✔
317
        auto SyclDTy = DPCTL_DPCTLDeviceTypeToSyclDeviceType(DTy);
125 ✔
318
        auto Devices = P->get_devices(SyclDTy);
125 ✔
319
        DevicesVectorPtr->reserve(Devices.size());
125 ✔
320
        for (const auto &Dev : Devices) {
125 ✔
321
            DevicesVectorPtr->emplace_back(
121 ✔
322
                wrap<device>(new device(std::move(Dev))));
121 ✔
323
        }
121 ✔
324
        return wrap<vecTy>(DevicesVectorPtr);
125 ✔
325
    } catch (std::exception const &e) {
125 ✔
326
        delete DevicesVectorPtr;
×
327
        error_handler(e, __FILE__, __func__, __LINE__);
×
328
        return nullptr;
×
329
    }
×
330
}
125 ✔
331

332
__dpctl_give DPCTLDeviceVectorRef
333
DPCTLPlatform_GetCompositeDevices(__dpctl_keep const DPCTLSyclPlatformRef PRef)
334
{
5 ✔
335
    auto P = unwrap<platform>(PRef);
5 ✔
336
    if (!P) {
5 !
337
        error_handler("Cannot retrieve composite devices from "
×
338
                      "DPCTLSyclPlatformRef as input is a nullptr.",
×
339
                      __FILE__, __func__, __LINE__);
×
340
        return nullptr;
×
341
    }
×
342

343
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
5 ✔
344
    vecTy *DevicesVectorPtr = nullptr;
5 ✔
345
    try {
5 ✔
346
        DevicesVectorPtr = new vecTy();
5 ✔
347
    } catch (std::exception const &e) {
5 ✔
348
        delete DevicesVectorPtr;
×
349
        error_handler(e, __FILE__, __func__, __LINE__);
×
350
        return nullptr;
×
351
    }
×
352

353
    try {
5 ✔
354
        auto composite_devices = P->ext_oneapi_get_composite_devices();
5 ✔
355
        DevicesVectorPtr->reserve(composite_devices.size());
5 ✔
356
        for (const auto &Dev : composite_devices) {
5 !
357
            DevicesVectorPtr->emplace_back(
×
358
                wrap<device>(new device(std::move(Dev))));
×
359
        }
×
360
        return wrap<vecTy>(DevicesVectorPtr);
5 ✔
361
    } catch (std::exception const &e) {
5 ✔
362
        delete DevicesVectorPtr;
×
363
        error_handler(e, __FILE__, __func__, __LINE__);
×
364
        return nullptr;
×
365
    }
×
366
}
5 ✔
367

368
bool DPCTLPlatform_HasAspect(__dpctl_keep const DPCTLSyclPlatformRef PRef,
369
                             DPCTLSyclAspectType AT)
370
{
243 ✔
371
    bool hasAspect = false;
243 ✔
372
    auto P = unwrap<platform>(PRef);
243 ✔
373
    if (P) {
243 ✔
374
        try {
242 ✔
375
            hasAspect = P->has(DPCTL_DPCTLAspectTypeToSyclAspect(AT));
242 ✔
376
        } catch (std::exception const &e) {
242 ✔
NEW
377
            error_handler(e, __FILE__, __func__, __LINE__);
×
NEW
378
        }
×
379
    }
242 ✔
380
    else {
1 ✔
381
        error_handler("Aspect cannot be looked up for a NULL platform.",
1 ✔
382
                      __FILE__, __func__, __LINE__);
1 ✔
383
    }
1 ✔
384
    return hasAspect;
243 ✔
385
}
243 ✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc