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

IntelPython / dpctl / 42075830536

05 Nov 2026 05:33PM UTC coverage: 75.0% (+0.04%) from 74.963%
42075830536

Pull #2412

github

web-flow
Merge 99176e1c4 into ea89d1b9e
Pull Request #2412: Add `sycl_platform::has_aspect` properties

1065 of 1496 branches covered (71.19%)

Branch coverage included in aggregate %.

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

4071 of 5352 relevant lines covered (76.07%)

286.75 hits per line

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

79.32
/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
{
54 ✔
64
    auto Platform = unwrap<platform>(PRef);
54 ✔
65
    if (!Platform) {
54 ✔
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 {
49 ✔
71
        auto CopiedPlatform = new platform(*Platform);
49 ✔
72
        return wrap<platform>(CopiedPlatform);
49 ✔
73
    } catch (std::exception const &e) {
49 ✔
74
        error_handler(e, __FILE__, __func__, __LINE__);
×
75
        return nullptr;
×
76
    }
×
77
}
49 ✔
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
{
530 ✔
116
    auto P = unwrap<platform>(PRef);
530 ✔
117
    delete P;
530 ✔
118
}
530 ✔
119

120
DPCTLSyclBackendType
121
DPCTLPlatform_GetBackend(__dpctl_keep const DPCTLSyclPlatformRef PRef)
122
{
13 ✔
123
    DPCTLSyclBackendType BTy = DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
13 ✔
124
    auto P = unwrap<platform>(PRef);
13 ✔
125
    if (P) {
13 ✔
126
        BTy = DPCTL_SyclBackendToDPCTLBackendType(P->get_backend());
12 ✔
127
    }
12 ✔
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;
13 ✔
133
}
13 ✔
134

135
__dpctl_give const char *
136
DPCTLPlatform_GetName(__dpctl_keep const DPCTLSyclPlatformRef PRef)
137
{
139 ✔
138
    auto P = unwrap<platform>(PRef);
139 ✔
139
    if (P) {
139 ✔
140
        try {
138 ✔
141
            auto name = P->get_info<info::platform::name>();
138 ✔
142
            return dpctl::helper::cstring_from_string(name);
138 ✔
143
        } catch (std::exception const &e) {
138 ✔
144
            error_handler(e, __FILE__, __func__, __LINE__);
×
145
            return nullptr;
×
146
        }
×
147
    }
138 ✔
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
}
139 ✔
154

155
__dpctl_give const char *
156
DPCTLPlatform_GetVendor(__dpctl_keep const DPCTLSyclPlatformRef PRef)
157
{
139 ✔
158
    auto P = unwrap<platform>(PRef);
139 ✔
159
    if (P) {
139 ✔
160
        try {
138 ✔
161
            auto vendor = P->get_info<info::platform::vendor>();
138 ✔
162
            return dpctl::helper::cstring_from_string(vendor);
138 ✔
163
        } catch (std::exception const &e) {
138 ✔
164
            error_handler(e, __FILE__, __func__, __LINE__);
×
165
            return nullptr;
×
166
        }
×
167
    }
138 ✔
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
}
139 ✔
174

175
__dpctl_give const char *
176
DPCTLPlatform_GetVersion(__dpctl_keep const DPCTLSyclPlatformRef PRef)
177
{
139 ✔
178
    auto P = unwrap<platform>(PRef);
139 ✔
179
    if (P) {
139 ✔
180
        try {
138 ✔
181
            auto driver = P->get_info<info::platform::version>();
138 ✔
182
            return dpctl::helper::cstring_from_string(driver);
138 ✔
183
        } catch (std::exception const &e) {
138 ✔
184
            error_handler(e, __FILE__, __func__, __LINE__);
×
185
            return nullptr;
×
186
        }
×
187
    }
138 ✔
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
}
139 ✔
194

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

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

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

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

221
    // the wrap function is defined inside dpctl_vector_templ.cpp
222
    return wrap<vecTy>(Platforms);
19 ✔
223
}
19 ✔
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
    try {
125 ✔
308
        auto SyclDTy = DPCTL_DPCTLDeviceTypeToSyclDeviceType(DTy);
125 ✔
309
        auto Devices = P->get_devices(SyclDTy);
125 ✔
310
        DevicesVectorPtr->reserve(Devices.size());
125 ✔
311
        for (const auto &Dev : Devices) {
125 ✔
312
            DevicesVectorPtr->emplace_back(
121 ✔
313
                wrap<device>(new device(std::move(Dev))));
121 ✔
314
        }
121 ✔
315
        return wrap<vecTy>(DevicesVectorPtr);
125 ✔
316
    } catch (std::exception const &e) {
125 ✔
317
        delete DevicesVectorPtr;
×
318
        error_handler(e, __FILE__, __func__, __LINE__);
×
319
        return nullptr;
×
320
    }
×
321
}
125 ✔
322

323
__dpctl_give DPCTLDeviceVectorRef
324
DPCTLPlatform_GetCompositeDevices(__dpctl_keep const DPCTLSyclPlatformRef PRef)
325
{
5 ✔
326
    auto P = unwrap<platform>(PRef);
5 ✔
327
    if (!P) {
5 !
328
        error_handler("Cannot retrieve composite devices from "
×
329
                      "DPCTLSyclPlatformRef as input is a nullptr.",
×
330
                      __FILE__, __func__, __LINE__);
×
331
        return nullptr;
×
332
    }
×
333

334
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
5 ✔
335
    vecTy *DevicesVectorPtr = nullptr;
5 ✔
336
    try {
5 ✔
337
        DevicesVectorPtr = new vecTy();
5 ✔
338
    } catch (std::exception const &e) {
5 ✔
339
        delete DevicesVectorPtr;
×
340
        error_handler(e, __FILE__, __func__, __LINE__);
×
341
        return nullptr;
×
342
    }
×
343

344
    try {
5 ✔
345
        auto composite_devices = P->ext_oneapi_get_composite_devices();
5 ✔
346
        DevicesVectorPtr->reserve(composite_devices.size());
5 ✔
347
        for (const auto &Dev : composite_devices) {
5 !
348
            DevicesVectorPtr->emplace_back(
×
349
                wrap<device>(new device(std::move(Dev))));
×
350
        }
×
351
        return wrap<vecTy>(DevicesVectorPtr);
5 ✔
352
    } catch (std::exception const &e) {
5 ✔
353
        delete DevicesVectorPtr;
×
354
        error_handler(e, __FILE__, __func__, __LINE__);
×
355
        return nullptr;
×
356
    }
×
357
}
5 ✔
358

359
bool DPCTLPlatform_HasAspect(__dpctl_keep const DPCTLSyclPlatformRef PRef,
360
                             DPCTLSyclAspectType AT)
361
{
243 ✔
362
    bool hasAspect = false;
243 ✔
363
    auto P = unwrap<platform>(PRef);
243 ✔
364
    if (P) {
243 ✔
365
        try {
242 ✔
366
            hasAspect = P->has(DPCTL_DPCTLAspectTypeToSyclAspect(AT));
242 ✔
367
        } catch (std::exception const &e) {
242 ✔
NEW
368
            error_handler(e, __FILE__, __func__, __LINE__);
×
NEW
369
        }
×
370
    }
242 ✔
371
    else {
1 ✔
372
        error_handler("Aspect cannot be looked up for a NULL platform.",
1 ✔
373
                      __FILE__, __func__, __LINE__);
1 ✔
374
    }
1 ✔
375
    return hasAspect;
243 ✔
376
}
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