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

IntelPython / dpctl / 31424878304

10 Aug 2026 07:35PM UTC coverage: 74.161% (+0.1%) from 74.054%
31424878304

Pull #2354

github

web-flow
Merge d098035c4 into 6c5d2deda
Pull Request #2354: Add `sycl::info::context` queries to `dpctl.SyclContext`

969 of 1372 branches covered (70.63%)

Branch coverage included in aggregate %.

49 of 56 new or added lines in 1 file covered. (87.5%)

108 existing lines in 1 file now uncovered.

3692 of 4913 relevant lines covered (75.15%)

288.56 hits per line

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

77.19
/libsyclinterface/source/dpctl_sycl_device_interface.cpp
1
//===--- dpctl_sycl_device_interface.cpp - Implements C API for sycl::device =//
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 data types and functions declared in
23
/// dpctl_sycl_device_interface.h.
24
///
25
//===----------------------------------------------------------------------===//
26

27
#include "dpctl_sycl_device_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_device_manager.h"
33
#include "dpctl_sycl_type_casters.hpp"
34
#include "dpctl_utils_helper.h"
35
#include <algorithm>
36
#include <stddef.h>
37
#include <sycl/sycl.hpp> /* SYCL headers   */
38
#include <utility>
39
#include <vector>
40

41
using namespace sycl;
42

43
namespace
44
{
45

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

49
using namespace dpctl::syclinterface;
50

51
device *new_device_from_selector(const dpctl_device_selector *sel)
52
{
7,248✔
53
    return new device(
7,248✔
54
        [=](const device &d) -> int { return sel->operator()(d); });
7,248✔
55
}
7,248✔
56

57
template <int dim>
58
__dpctl_give size_t *
59
DPCTLDevice__GetMaxWorkItemSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef)
60
{
4,999✔
61
    size_t *sizes = nullptr;
4,999✔
62
    auto D = unwrap<device>(DRef);
4,999✔
63
    if (D) {
4,999✔
64
        try {
4,996✔
65
#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_MAX_WORK_ITEM_SIZE_THRESHOLD
4,996✔
66
            auto id_sizes =
4,996✔
67
                D->get_info<info::device::max_work_item_sizes<dim>>();
4,996✔
68
#else
69
            auto id_sizes = D->get_info<info::device::max_work_item_sizes>();
70
#endif
71
            sizes = new size_t[dim];
4,996✔
72
            for (auto i = 0ul; i < dim; ++i) {
19,915✔
73
                sizes[i] = id_sizes[i];
14,919✔
74
            }
14,919✔
75
        } catch (std::exception const &e) {
4,996✔
76
            error_handler(e, __FILE__, __func__, __LINE__);
×
77
        }
×
78
    }
4,996✔
79
    return sizes;
4,999✔
80
}
4,999✔
81

82
} /* end of anonymous namespace */
83

84
__dpctl_give DPCTLSyclDeviceRef
85
DPCTLDevice_Copy(__dpctl_keep const DPCTLSyclDeviceRef DRef)
86
{
2,401✔
87
    auto Device = unwrap<device>(DRef);
2,401✔
88
    if (!Device) {
2,401✔
89
        error_handler("Cannot copy DPCTLSyclDeviceRef as input is a nullptr",
1✔
90
                      __FILE__, __func__, __LINE__);
1✔
91
        return nullptr;
1✔
92
    }
1✔
93
    try {
2,400✔
94
        auto CopiedDevice = new device(*Device);
2,400✔
95
        return wrap<device>(CopiedDevice);
2,400✔
96
    } catch (std::exception const &e) {
2,400✔
97
        error_handler(e, __FILE__, __func__, __LINE__);
×
98
        return nullptr;
×
99
    }
×
100
}
2,400✔
101

102
__dpctl_give DPCTLSyclDeviceRef DPCTLDevice_Create()
103
{
1✔
104
    try {
1✔
105
        auto Device = new device();
1✔
106
        return wrap<device>(Device);
1✔
107
    } catch (std::exception const &e) {
1✔
108
        error_handler(e, __FILE__, __func__, __LINE__);
×
109
        return nullptr;
×
110
    }
×
111
}
1✔
112

113
__dpctl_give DPCTLSyclDeviceRef DPCTLDevice_CreateFromSelector(
114
    __dpctl_keep const DPCTLSyclDeviceSelectorRef DSRef)
115
{
7,262✔
116
    auto Selector = unwrap<dpctl_device_selector>(DSRef);
7,262✔
117
    if (!Selector) {
7,262✔
118
        error_handler("Cannot define device selector for DPCTLSyclDeviceRef "
14✔
119
                      "as input is a nullptr.",
14✔
120
                      __FILE__, __func__, __LINE__);
14✔
121
        return nullptr;
14✔
122
    }
14✔
123
    try {
7,248✔
124
        auto Device = new_device_from_selector(Selector);
7,248✔
125
        return wrap<device>(Device);
7,248✔
126
    } catch (std::exception const &e) {
7,248✔
127
        error_handler(e, __FILE__, __func__, __LINE__);
3,999✔
128
        return nullptr;
3,999✔
129
    }
3,999✔
130
}
7,248✔
131

132
void DPCTLDevice_Delete(__dpctl_take DPCTLSyclDeviceRef DRef)
133
{
8,623✔
134
    delete unwrap<device>(DRef);
8,623✔
135
}
8,623✔
136

137
DPCTLSyclDeviceType
138
DPCTLDevice_GetDeviceType(__dpctl_keep const DPCTLSyclDeviceRef DRef)
139
{
55✔
140
    DPCTLSyclDeviceType DTy = DPCTLSyclDeviceType::DPCTL_UNKNOWN_DEVICE;
55✔
141
    auto D = unwrap<device>(DRef);
55✔
142
    if (D) {
55✔
143
        try {
54✔
144
            auto SyclDTy = D->get_info<info::device::device_type>();
54✔
145
            DTy = DPCTL_SyclDeviceTypeToDPCTLDeviceType(SyclDTy);
54✔
146
        } catch (std::exception const &e) {
54✔
147
            error_handler(e, __FILE__, __func__, __LINE__);
×
148
        }
×
149
    }
54✔
150
    return DTy;
55✔
151
}
55✔
152

153
bool DPCTLDevice_IsAccelerator(__dpctl_keep const DPCTLSyclDeviceRef DRef)
154
{
78✔
155
    auto D = unwrap<device>(DRef);
78✔
156
    if (D) {
78✔
157
        return D->is_accelerator();
77✔
158
    }
77✔
159
    return false;
1✔
160
}
78✔
161

162
bool DPCTLDevice_IsCPU(__dpctl_keep const DPCTLSyclDeviceRef DRef)
163
{
26✔
164
    auto D = unwrap<device>(DRef);
26✔
165
    if (D) {
26✔
166
        return D->is_cpu();
25✔
167
    }
25✔
168
    return false;
1✔
169
}
26✔
170

171
bool DPCTLDevice_IsGPU(__dpctl_keep const DPCTLSyclDeviceRef DRef)
172
{
24✔
173
    auto D = unwrap<device>(DRef);
24✔
174
    if (D) {
24✔
175
        return D->is_gpu();
23✔
176
    }
23✔
177
    return false;
1✔
178
}
24✔
179

180
DPCTLSyclBackendType
181
DPCTLDevice_GetBackend(__dpctl_keep const DPCTLSyclDeviceRef DRef)
182
{
56✔
183
    DPCTLSyclBackendType BTy = DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
56✔
184
    auto D = unwrap<device>(DRef);
56✔
185
    if (D) {
56!
186
        BTy = DPCTL_SyclBackendToDPCTLBackendType(D->get_backend());
56✔
187
    }
56✔
188
    return BTy;
56✔
189
}
56✔
190

191
uint32_t
192
DPCTLDevice_GetMaxComputeUnits(__dpctl_keep const DPCTLSyclDeviceRef DRef)
193
{
104✔
194
    uint32_t nComputeUnits = 0;
104✔
195
    auto D = unwrap<device>(DRef);
104✔
196
    if (D) {
104✔
197
        try {
103✔
198
            nComputeUnits = D->get_info<info::device::max_compute_units>();
103✔
199
        } catch (std::exception const &e) {
103✔
200
            error_handler(e, __FILE__, __func__, __LINE__);
×
201
        }
×
202
    }
103✔
203
    return nComputeUnits;
104✔
204
}
104✔
205

206
uint64_t
207
DPCTLDevice_GetGlobalMemSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
208
{
24✔
209
    uint64_t GlobalMemSize = 0;
24✔
210
    auto D = unwrap<device>(DRef);
24✔
211
    if (D) {
24✔
212
        try {
23✔
213
            GlobalMemSize = D->get_info<info::device::global_mem_size>();
23✔
214
        } catch (std::exception const &e) {
23✔
215
            error_handler(e, __FILE__, __func__, __LINE__);
×
216
        }
×
217
    }
23✔
218
    return GlobalMemSize;
24✔
219
}
24✔
220

221
uint64_t DPCTLDevice_GetLocalMemSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
222
{
24✔
223
    uint64_t LocalMemSize = 0;
24✔
224
    auto D = unwrap<device>(DRef);
24✔
225
    if (D) {
24✔
226
        try {
23✔
227
            LocalMemSize = D->get_info<info::device::local_mem_size>();
23✔
228
        } catch (std::exception const &e) {
23✔
229
            error_handler(e, __FILE__, __func__, __LINE__);
×
230
        }
×
231
    }
23✔
232
    return LocalMemSize;
24✔
233
}
24✔
234

235
uint32_t
236
DPCTLDevice_GetMaxWorkItemDims(__dpctl_keep const DPCTLSyclDeviceRef DRef)
237
{
24✔
238
    uint32_t maxWorkItemDims = 0;
24✔
239
    auto D = unwrap<device>(DRef);
24✔
240
    if (D) {
24✔
241
        try {
23✔
242
            maxWorkItemDims =
23✔
243
                D->get_info<info::device::max_work_item_dimensions>();
23✔
244
        } catch (std::exception const &e) {
23✔
245
            error_handler(e, __FILE__, __func__, __LINE__);
×
246
        }
×
247
    }
23✔
248
    return maxWorkItemDims;
24✔
249
}
24✔
250

251
__dpctl_give size_t *
252
DPCTLDevice_GetMaxWorkItemSizes1d(__dpctl_keep const DPCTLSyclDeviceRef DRef)
253
{
24✔
254
    return DPCTLDevice__GetMaxWorkItemSizes<1>(DRef);
24✔
255
}
24✔
256

257
__dpctl_give size_t *
258
DPCTLDevice_GetMaxWorkItemSizes2d(__dpctl_keep const DPCTLSyclDeviceRef DRef)
259
{
24✔
260
    return DPCTLDevice__GetMaxWorkItemSizes<2>(DRef);
24✔
261
}
24✔
262

263
__dpctl_give size_t *
264
DPCTLDevice_GetMaxWorkItemSizes3d(__dpctl_keep const DPCTLSyclDeviceRef DRef)
265
{
4,951✔
266
    return DPCTLDevice__GetMaxWorkItemSizes<3>(DRef);
4,951✔
267
}
4,951✔
268

269
size_t
270
DPCTLDevice_GetMaxWorkGroupSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
271
{
25✔
272
    size_t max_wg_size = 0;
25✔
273
    auto D = unwrap<device>(DRef);
25✔
274
    if (D) {
25✔
275
        try {
24✔
276
            max_wg_size = D->get_info<info::device::max_work_group_size>();
24✔
277
        } catch (std::exception const &e) {
24✔
278
            error_handler(e, __FILE__, __func__, __LINE__);
×
279
        }
×
280
    }
24✔
281
    return max_wg_size;
25✔
282
}
25✔
283

284
uint32_t
285
DPCTLDevice_GetMaxNumSubGroups(__dpctl_keep const DPCTLSyclDeviceRef DRef)
286
{
24✔
287
    size_t max_nsubgroups = 0;
24✔
288
    auto D = unwrap<device>(DRef);
24✔
289
    if (D) {
24✔
290
        try {
23✔
291
            max_nsubgroups = D->get_info<info::device::max_num_sub_groups>();
23✔
292
        } catch (std::exception const &e) {
23✔
293
            error_handler(e, __FILE__, __func__, __LINE__);
×
294
        }
×
295
    }
23✔
296
    return max_nsubgroups;
24✔
297
}
24✔
298

299
__dpctl_give DPCTLSyclPlatformRef
300
DPCTLDevice_GetPlatform(__dpctl_keep const DPCTLSyclDeviceRef DRef)
301
{
38✔
302
    DPCTLSyclPlatformRef PRef = nullptr;
38✔
303
    auto D = unwrap<device>(DRef);
38✔
304
    if (D) {
38✔
305
        try {
37✔
306
            PRef = wrap<platform>(new platform(D->get_platform()));
37✔
307
        } catch (std::exception const &e) {
37✔
308
            error_handler(e, __FILE__, __func__, __LINE__);
×
309
        }
×
310
    }
37✔
311
    return PRef;
38✔
312
}
38✔
313

314
__dpctl_give const char *
315
DPCTLDevice_GetName(__dpctl_keep const DPCTLSyclDeviceRef DRef)
316
{
4,951✔
317
    const char *cstr_name = nullptr;
4,951✔
318
    auto D = unwrap<device>(DRef);
4,951✔
319
    if (D) {
4,951✔
320
        try {
4,950✔
321
            auto name = D->get_info<info::device::name>();
4,950✔
322
            cstr_name = dpctl::helper::cstring_from_string(name);
4,950✔
323
        } catch (std::exception const &e) {
4,950✔
324
            error_handler(e, __FILE__, __func__, __LINE__);
×
325
        }
×
326
    }
4,950✔
327
    return cstr_name;
4,951✔
328
}
4,951✔
329

330
__dpctl_give const char *
331
DPCTLDevice_GetVendor(__dpctl_keep const DPCTLSyclDeviceRef DRef)
332
{
4,951✔
333
    const char *cstr_vendor = nullptr;
4,951✔
334
    auto D = unwrap<device>(DRef);
4,951✔
335
    if (D) {
4,951✔
336
        try {
4,950✔
337
            auto vendor = D->get_info<info::device::vendor>();
4,950✔
338
            cstr_vendor = dpctl::helper::cstring_from_string(vendor);
4,950✔
339
        } catch (std::exception const &e) {
4,950✔
340
            error_handler(e, __FILE__, __func__, __LINE__);
×
341
        }
×
342
    }
4,950✔
343
    return cstr_vendor;
4,951✔
344
}
4,951✔
345

346
__dpctl_give const char *
347
DPCTLDevice_GetDriverVersion(__dpctl_keep const DPCTLSyclDeviceRef DRef)
348
{
4,951✔
349
    const char *cstr_driver = nullptr;
4,951✔
350
    auto D = unwrap<device>(DRef);
4,951✔
351
    if (D) {
4,951✔
352
        try {
4,950✔
353
            auto driver = D->get_info<info::device::driver_version>();
4,950✔
354
            cstr_driver = dpctl::helper::cstring_from_string(driver);
4,950✔
355
        } catch (std::exception const &e) {
4,950✔
356
            error_handler(e, __FILE__, __func__, __LINE__);
×
357
        }
×
358
    }
4,950✔
359
    return cstr_driver;
4,951✔
360
}
4,951✔
361

362
bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DRef1,
363
                       __dpctl_keep const DPCTLSyclDeviceRef DRef2)
364
{
170✔
365
    auto D1 = unwrap<device>(DRef1);
170✔
366
    auto D2 = unwrap<device>(DRef2);
170✔
367
    if (D1 && D2)
170!
368
        return *D1 == *D2;
169✔
369
    else
1✔
370
        return false;
1✔
371
}
170✔
372

373
bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef,
374
                           DPCTLSyclAspectType AT)
375
{
509✔
376
    bool hasAspect = false;
509✔
377
    auto D = unwrap<device>(DRef);
509✔
378
    if (D) {
509✔
379
        try {
508✔
380
            hasAspect = D->has(DPCTL_DPCTLAspectTypeToSyclAspect(AT));
508✔
381
        } catch (std::exception const &e) {
508✔
382
            error_handler(e, __FILE__, __func__, __LINE__);
×
383
        }
×
384
    }
508✔
385
    return hasAspect;
509✔
386
}
509✔
387

388
#define declmethod(FUNC, NAME, TYPE)                                           \
389
    TYPE DPCTLDevice_##FUNC(__dpctl_keep const DPCTLSyclDeviceRef DRef)        \
390
    {                                                                          \
168✔
391
        TYPE result = 0;                                                       \
168✔
392
        auto D = unwrap<device>(DRef);                                         \
168✔
393
        if (D) {                                                               \
168✔
394
            try {                                                              \
161✔
395
                result = D->get_info<info::device::NAME>();                    \
161✔
396
            } catch (std::exception const &e) {                                \
161✔
397
                error_handler(e, __FILE__, __func__, __LINE__);                \
×
398
            }                                                                  \
×
399
        }                                                                      \
161✔
400
        return result;                                                         \
168✔
401
    }
168✔
402
declmethod(GetMaxReadImageArgs, max_read_image_args, uint32_t);
403
declmethod(GetMaxWriteImageArgs, max_write_image_args, uint32_t);
404
declmethod(GetImage2dMaxWidth, image2d_max_width, size_t);
405
declmethod(GetImage2dMaxHeight, image2d_max_height, size_t);
406
declmethod(GetImage3dMaxWidth, image3d_max_width, size_t);
407
declmethod(GetImage3dMaxHeight, image3d_max_height, size_t);
408
declmethod(GetImage3dMaxDepth, image3d_max_depth, size_t);
409
#undef declmethod
410

411
namespace
412
{
413

414
template <typename descriptorT>
415
uint32_t get_uint32_descriptor(__dpctl_keep const DPCTLSyclDeviceRef DRef)
416
{
329✔
417
    uint32_t descr_val = 0;
329✔
418
    auto D = unwrap<device>(DRef);
329✔
419
    if (D) {
329✔
420
        try {
322✔
421
            descr_val = D->get_info<descriptorT>();
322✔
422
        } catch (std::exception const &e) {
322✔
UNCOV
423
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
424
        }
×
425
    }
322✔
426
    return descr_val;
329✔
427
}
329✔
428

429
} // end of anonymous namespace
430

431
uint32_t DPCTLDevice_GetPreferredVectorWidthChar(
432
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
433
{
24✔
434
    return get_uint32_descriptor<info::device::preferred_vector_width_char>(
24✔
435
        DRef);
24✔
436
}
24✔
437

438
uint32_t DPCTLDevice_GetPreferredVectorWidthShort(
439
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
440
{
24✔
441
    return get_uint32_descriptor<info::device::preferred_vector_width_short>(
24✔
442
        DRef);
24✔
443
}
24✔
444

445
uint32_t DPCTLDevice_GetPreferredVectorWidthInt(
446
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
447
{
24✔
448
    return get_uint32_descriptor<info::device::preferred_vector_width_int>(
24✔
449
        DRef);
24✔
450
}
24✔
451

452
uint32_t DPCTLDevice_GetPreferredVectorWidthLong(
453
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
454
{
24✔
455
    return get_uint32_descriptor<info::device::preferred_vector_width_long>(
24✔
456
        DRef);
24✔
457
}
24✔
458

459
uint32_t DPCTLDevice_GetPreferredVectorWidthFloat(
460
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
461
{
24✔
462
    return get_uint32_descriptor<info::device::preferred_vector_width_float>(
24✔
463
        DRef);
24✔
464
}
24✔
465

466
uint32_t DPCTLDevice_GetPreferredVectorWidthDouble(
467
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
468
{
24✔
469
    return get_uint32_descriptor<info::device::preferred_vector_width_double>(
24✔
470
        DRef);
24✔
471
}
24✔
472

473
uint32_t DPCTLDevice_GetPreferredVectorWidthHalf(
474
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
475
{
24✔
476
    return get_uint32_descriptor<info::device::preferred_vector_width_half>(
24✔
477
        DRef);
24✔
478
}
24✔
479

480
//
481
uint32_t
482
DPCTLDevice_GetNativeVectorWidthChar(__dpctl_keep const DPCTLSyclDeviceRef DRef)
483
{
23✔
484
    return get_uint32_descriptor<info::device::native_vector_width_char>(DRef);
23✔
485
}
23✔
486

487
uint32_t DPCTLDevice_GetNativeVectorWidthShort(
488
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
489
{
23✔
490
    return get_uint32_descriptor<info::device::native_vector_width_short>(DRef);
23✔
491
}
23✔
492

493
uint32_t
494
DPCTLDevice_GetNativeVectorWidthInt(__dpctl_keep const DPCTLSyclDeviceRef DRef)
495
{
23✔
496
    return get_uint32_descriptor<info::device::native_vector_width_int>(DRef);
23✔
497
}
23✔
498

499
uint32_t
500
DPCTLDevice_GetNativeVectorWidthLong(__dpctl_keep const DPCTLSyclDeviceRef DRef)
501
{
23✔
502
    return get_uint32_descriptor<info::device::native_vector_width_long>(DRef);
23✔
503
}
23✔
504

505
uint32_t DPCTLDevice_GetNativeVectorWidthFloat(
506
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
507
{
23✔
508
    return get_uint32_descriptor<info::device::native_vector_width_float>(DRef);
23✔
509
}
23✔
510

511
uint32_t DPCTLDevice_GetNativeVectorWidthDouble(
512
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
513
{
23✔
514
    return get_uint32_descriptor<info::device::native_vector_width_double>(
23✔
515
        DRef);
23✔
516
}
23✔
517

518
uint32_t
519
DPCTLDevice_GetNativeVectorWidthHalf(__dpctl_keep const DPCTLSyclDeviceRef DRef)
520
{
23✔
521
    return get_uint32_descriptor<info::device::native_vector_width_half>(DRef);
23✔
522
}
23✔
523

524
__dpctl_give DPCTLSyclDeviceRef
525
DPCTLDevice_GetParentDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef)
526
{
64✔
527
    auto D = unwrap<device>(DRef);
64✔
528
    if (D) {
64✔
529
        bool is_unpartitioned = false;
63✔
530
        try {
63✔
531
            auto pp =
63✔
532
                D->get_info<sycl::info::device::partition_type_property>();
63✔
533
            is_unpartitioned =
63✔
534
                (pp == sycl::info::partition_property::no_partition);
63✔
535
        } catch (std::exception const &e) {
63✔
UNCOV
536
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
537
            return nullptr;
×
UNCOV
538
        }
×
539
        if (is_unpartitioned)
63✔
540
            return nullptr;
54✔
541
        try {
9✔
542
            const auto &parent_D = D->get_info<info::device::parent_device>();
9✔
543
            return wrap<device>(new device(parent_D));
9✔
544
        } catch (std::exception const &e) {
9✔
UNCOV
545
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
546
            return nullptr;
×
UNCOV
547
        }
×
548
    }
9✔
549
    else
1✔
550
        return nullptr;
1✔
551
}
64✔
552

553
uint32_t DPCTLDevice_GetPartitionMaxSubDevices(
554
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
555
{
24✔
556
    auto D = unwrap<device>(DRef);
24✔
557
    if (D) {
24✔
558
        try {
23✔
559
            uint32_t part_max_sub_devs =
23✔
560
                D->get_info<info::device::partition_max_sub_devices>();
23✔
561
            return part_max_sub_devs;
23✔
562
        } catch (std::exception const &e) {
23✔
563
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
564
            return 0;
×
UNCOV
565
        }
×
566
    }
23✔
567
    else
1✔
568
        return 0;
1✔
569
}
24✔
570

571
__dpctl_give DPCTLDeviceVectorRef
572
DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef,
573
                                    size_t count)
574
{
40✔
575
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
40✔
576
    vecTy *Devices = nullptr;
40✔
577
    if (DRef) {
40✔
578
        if (count == 0) {
39✔
579
            error_handler("Cannot create sub-devices with zero compute units",
8✔
580
                          __FILE__, __func__, __LINE__);
8✔
581
            return nullptr;
8✔
582
        }
8✔
583
        auto D = unwrap<device>(DRef);
31✔
584
        const auto &supported_properties =
31✔
585
            D->get_info<info::device::partition_properties>();
31✔
586
        const auto &beg_it = supported_properties.begin();
31✔
587
        const auto &end_it = supported_properties.end();
31✔
588
        if (std::find(beg_it, end_it,
31!
589
                      info::partition_property::partition_equally) == end_it)
31✔
UNCOV
590
        {
×
591
            // device does not support partition equally
UNCOV
592
            return nullptr;
×
UNCOV
593
        }
×
594
        try {
31✔
595
            auto subDevices = D->create_sub_devices<
31✔
596
                info::partition_property::partition_equally>(count);
31✔
597
            Devices = new vecTy();
31✔
598
            for (const auto &sd : subDevices) {
62✔
599
                Devices->emplace_back(wrap<device>(new device(sd)));
62✔
600
            }
62✔
601
        } catch (std::exception const &e) {
31✔
UNCOV
602
            delete Devices;
×
UNCOV
603
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
604
            return nullptr;
×
UNCOV
605
        }
×
606
    }
31✔
607
    return wrap<vecTy>(Devices);
32✔
608
}
40✔
609

610
__dpctl_give DPCTLDeviceVectorRef
611
DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef,
612
                                     __dpctl_keep size_t *counts,
613
                                     size_t ncounts)
614
{
36✔
615
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
36✔
616
    vecTy *Devices = nullptr;
36✔
617
    std::vector<size_t> vcounts(ncounts);
36✔
618
    vcounts.assign(counts, counts + ncounts);
36✔
619
    size_t min_elem = *std::min_element(vcounts.begin(), vcounts.end());
36✔
620
    if (min_elem == 0) {
36✔
621
        error_handler("Cannot create sub-devices with zero compute units",
8✔
622
                      __FILE__, __func__, __LINE__);
8✔
623
        return nullptr;
8✔
624
    }
8✔
625
    if (DRef) {
28✔
626
        auto D = unwrap<device>(DRef);
27✔
627
        const auto &supported_properties =
27✔
628
            D->get_info<info::device::partition_properties>();
27✔
629
        const auto &beg_it = supported_properties.begin();
27✔
630
        const auto &end_it = supported_properties.end();
27✔
631
        if (std::find(beg_it, end_it,
27!
632
                      info::partition_property::partition_by_counts) == end_it)
27✔
UNCOV
633
        {
×
634
            // device does not support partition by counts
UNCOV
635
            return nullptr;
×
UNCOV
636
        }
×
637
        std::vector<std::remove_pointer<decltype(D)>::type> subDevices;
27✔
638
        try {
27✔
639
            subDevices = D->create_sub_devices<
27✔
640
                info::partition_property::partition_by_counts>(vcounts);
27✔
641
        } catch (std::exception const &e) {
27✔
UNCOV
642
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
643
            return nullptr;
×
UNCOV
644
        }
×
645
        try {
27✔
646
            Devices = new vecTy();
27✔
647
            for (const auto &sd : subDevices) {
54✔
648
                Devices->emplace_back(wrap<device>(new device(sd)));
54✔
649
            }
54✔
650
        } catch (std::exception const &e) {
27✔
651
            delete Devices;
×
652
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
653
            return nullptr;
×
UNCOV
654
        }
×
655
    }
27✔
656
    return wrap<vecTy>(Devices);
28✔
657
}
28✔
658

659
__dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity(
660
    __dpctl_keep const DPCTLSyclDeviceRef DRef,
661
    DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy)
662
{
163✔
663
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
163✔
664
    vecTy *Devices = nullptr;
163✔
665
    auto D = unwrap<device>(DRef);
163✔
666
    if (D) {
163✔
667
        const auto &supported_properties =
162✔
668
            D->get_info<info::device::partition_properties>();
162✔
669
        const auto &beg_it = supported_properties.begin();
162✔
670
        const auto &end_it = supported_properties.end();
162✔
671
        if (std::find(beg_it, end_it,
162!
672
                      info::partition_property::partition_by_affinity_domain) ==
162✔
673
            end_it)
162✔
674
        {
162✔
675
            // device does not support partition by affinity domain
676
            return nullptr;
162✔
677
        }
162✔
UNCOV
678
        try {
×
UNCOV
679
            auto domain = DPCTL_DPCTLPartitionAffinityDomainTypeToSycl(
×
UNCOV
680
                PartitionAffinityDomainTy);
×
UNCOV
681
            const auto &supported_affinity_domains =
×
UNCOV
682
                D->get_info<info::device::partition_affinity_domains>();
×
UNCOV
683
            const auto &beg_it = supported_affinity_domains.begin();
×
UNCOV
684
            const auto &end_it = supported_affinity_domains.end();
×
UNCOV
685
            if (std::find(beg_it, end_it, domain) == end_it) {
×
686
                // device does not support partitioning by this particular
687
                // affinity domain
UNCOV
688
                return nullptr;
×
UNCOV
689
            }
×
UNCOV
690
            auto subDevices = D->create_sub_devices<
×
UNCOV
691
                info::partition_property::partition_by_affinity_domain>(domain);
×
UNCOV
692
            Devices = new vecTy();
×
UNCOV
693
            for (const auto &sd : subDevices) {
×
694
                Devices->emplace_back(wrap<device>(new device(sd)));
×
695
            }
×
696
        } catch (std::exception const &e) {
×
697
            delete Devices;
×
698
            error_handler(e, __FILE__, __func__, __LINE__);
×
699
            return nullptr;
×
700
        }
×
701
    }
×
702
    return wrap<vecTy>(Devices);
1✔
703
}
163✔
704

705
size_t DPCTLDevice_Hash(__dpctl_keep const DPCTLSyclDeviceRef DRef)
706
{
93✔
707
    if (DRef) {
93✔
708
        auto D = unwrap<device>(DRef);
92✔
709
        std::hash<device> hash_fn;
92✔
710
        return hash_fn(*D);
92✔
711
    }
92✔
712
    else {
1✔
713
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
714
        return 0;
1✔
715
    }
1✔
716
}
93✔
717

718
size_t DPCTLDevice_GetProfilingTimerResolution(
719
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
720
{
24✔
721
    if (DRef) {
24✔
722
        auto D = unwrap<device>(DRef);
23✔
723
        return D->get_info<info::device::profiling_timer_resolution>();
23✔
724
    }
23✔
725
    else {
1✔
726
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
727
        return 0;
1✔
728
    }
1✔
729
}
24✔
730

731
uint32_t DPCTLDevice_GetGlobalMemCacheLineSize(
732
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
733
{
24✔
734
    if (DRef) {
24✔
735
        auto D = unwrap<device>(DRef);
23✔
736
        return D->get_info<info::device::global_mem_cache_line_size>();
23✔
737
    }
23✔
738
    else {
1✔
739
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
740
        return 0;
1✔
741
    }
1✔
742
}
24✔
743

744
uint32_t
745
DPCTLDevice_GetMaxClockFrequency(__dpctl_keep const DPCTLSyclDeviceRef DRef)
746
{
24✔
747
    if (DRef) {
24✔
748
        auto D = unwrap<device>(DRef);
23✔
749
        return D->get_info<info::device::max_clock_frequency>();
23✔
750
    }
23✔
751
    else {
1✔
752
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
753
        return 0;
1✔
754
    }
1✔
755
}
24✔
756

757
uint64_t
758
DPCTLDevice_GetMaxMemAllocSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
759
{
24✔
760
    if (DRef) {
24✔
761
        auto D = unwrap<device>(DRef);
23✔
762
        return D->get_info<info::device::max_mem_alloc_size>();
23✔
763
    }
23✔
764
    else {
1✔
765
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
766
        return 0;
1✔
767
    }
1✔
768
}
24✔
769

770
uint64_t
771
DPCTLDevice_GetGlobalMemCacheSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
772
{
24✔
773
    if (DRef) {
24✔
774
        auto D = unwrap<device>(DRef);
23✔
775
        return D->get_info<info::device::global_mem_cache_size>();
23✔
776
    }
23✔
777
    else {
1✔
778
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
779
        return 0;
1✔
780
    }
1✔
781
}
24✔
782

783
DPCTLGlobalMemCacheType
784
DPCTLDevice_GetGlobalMemCacheType(__dpctl_keep const DPCTLSyclDeviceRef DRef)
785
{
24✔
786
    if (DRef) {
24✔
787
        auto D = unwrap<device>(DRef);
23✔
788
        try {
23✔
789
            auto mem_type = D->get_info<info::device::global_mem_cache_type>();
23✔
790
            switch (mem_type) {
23!
UNCOV
791
            case info::global_mem_cache_type::none:
×
UNCOV
792
                return DPCTL_MEM_CACHE_TYPE_NONE;
×
UNCOV
793
            case info::global_mem_cache_type::read_only:
×
UNCOV
794
                return DPCTL_MEM_CACHE_TYPE_READ_ONLY;
×
795
            case info::global_mem_cache_type::read_write:
23!
796
                return DPCTL_MEM_CACHE_TYPE_READ_WRITE;
23✔
797
            }
23✔
798
            // If execution reaches here unrecognized mem_type was returned.
799
            // Check values in the enumeration `info::global_mem_cache_type` in
800
            // SYCL specs
801
        } catch (std::exception const &e) {
23✔
UNCOV
802
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
803
        }
×
804
    }
23✔
805
    return DPCTL_MEM_CACHE_TYPE_INDETERMINATE;
1✔
806
}
24✔
807

808
__dpctl_give size_t *
809
DPCTLDevice_GetSubGroupSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef,
810
                             size_t *res_len)
811
{
24✔
812
    size_t *sizes = nullptr;
24✔
813
    std::vector<size_t> sg_sizes;
24✔
814
    *res_len = 0;
24✔
815
    auto D = unwrap<device>(DRef);
24✔
816
    if (D) {
24✔
817
        try {
23✔
818
            sg_sizes = D->get_info<info::device::sub_group_sizes>();
23✔
819
            *res_len = sg_sizes.size();
23✔
820
        } catch (std::exception const &e) {
23✔
UNCOV
821
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
822
        }
×
823
        try {
23✔
824
            sizes = new size_t[sg_sizes.size()];
23✔
825
        } catch (std::exception const &e) {
23✔
UNCOV
826
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
827
        }
×
828
        for (auto i = 0ul; (sizes != nullptr) && i < sg_sizes.size(); ++i) {
138!
829
            sizes[i] = sg_sizes[i];
115✔
830
        }
115✔
831
    }
23✔
832
    return sizes;
24✔
833
}
24✔
834

835
__dpctl_give DPCTLDeviceVectorRef
836
DPCTLDevice_GetComponentDevices(__dpctl_keep const DPCTLSyclDeviceRef DRef)
837
{
1✔
838
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
1✔
839
    vecTy *ComponentDevicesVectorPtr = nullptr;
1✔
840
    if (DRef) {
1!
UNCOV
841
        auto D = unwrap<device>(DRef);
×
842
        try {
×
843
            auto componentDevices =
×
UNCOV
844
                D->get_info<sycl::ext::oneapi::experimental::info::device::
×
UNCOV
845
                                component_devices>();
×
UNCOV
846
            ComponentDevicesVectorPtr = new vecTy();
×
UNCOV
847
            ComponentDevicesVectorPtr->reserve(componentDevices.size());
×
UNCOV
848
            for (const auto &cd : componentDevices) {
×
UNCOV
849
                ComponentDevicesVectorPtr->emplace_back(
×
UNCOV
850
                    wrap<device>(new device(cd)));
×
UNCOV
851
            }
×
UNCOV
852
        } catch (std::exception const &e) {
×
UNCOV
853
            delete ComponentDevicesVectorPtr;
×
UNCOV
854
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
855
            return nullptr;
×
UNCOV
856
        }
×
857
    }
×
858
    return wrap<vecTy>(ComponentDevicesVectorPtr);
1✔
859
}
1✔
860

861
__dpctl_give DPCTLSyclDeviceRef
862
DPCTLDevice_GetCompositeDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef)
863
{
9✔
864
    auto D = unwrap<device>(DRef);
9✔
865
    if (D) {
9✔
866
        bool is_component = false;
8✔
867
        try {
8✔
868
            is_component = D->has(sycl::aspect::ext_oneapi_is_component);
8✔
869
        } catch (std::exception const &e) {
8✔
870
            error_handler(e, __FILE__, __func__, __LINE__);
×
871
            return nullptr;
×
872
        }
×
873
        if (!is_component)
8!
874
            return nullptr;
8✔
UNCOV
875
        try {
×
UNCOV
876
            const auto &compositeDevice =
×
UNCOV
877
                D->get_info<sycl::ext::oneapi::experimental::info::device::
×
UNCOV
878
                                composite_device>();
×
UNCOV
879
            return wrap<device>(new device(compositeDevice));
×
UNCOV
880
        } catch (std::exception const &e) {
×
UNCOV
881
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
882
            return nullptr;
×
UNCOV
883
        }
×
UNCOV
884
    }
×
885
    else
1✔
886
        return nullptr;
1✔
887
}
9✔
888

889
static inline bool _CallPeerAccess(device dev, device peer)
UNCOV
890
{
×
891
    auto BE1 = dev.get_backend();
×
892
    auto BE2 = peer.get_backend();
×
893

894
    if ((BE1 == BE2) &&
×
895
        (BE1 == sycl::backend::ext_oneapi_level_zero ||
×
896
         BE1 == sycl::backend::ext_oneapi_cuda ||
×
897
         BE1 == sycl::backend::ext_oneapi_hip) &&
×
898
        (BE2 == sycl::backend::ext_oneapi_level_zero ||
×
899
         BE2 == sycl::backend::ext_oneapi_cuda ||
×
900
         BE2 == sycl::backend::ext_oneapi_hip) &&
×
UNCOV
901
        (dev != peer))
×
UNCOV
902
    {
×
UNCOV
903
        return true;
×
UNCOV
904
    }
×
UNCOV
905
    return false;
×
906
}
×
907

908
bool DPCTLDevice_CanAccessPeer(__dpctl_keep const DPCTLSyclDeviceRef DRef,
909
                               __dpctl_keep const DPCTLSyclDeviceRef PDRef,
910
                               DPCTLPeerAccessType PT)
911
{
2✔
912
    bool canAccess = false;
2✔
913
    auto D = unwrap<device>(DRef);
2✔
914
    auto PD = unwrap<device>(PDRef);
2✔
915
    if (D && PD) {
2!
916
        if (_CallPeerAccess(*D, *PD)) {
×
917
            try {
×
918
                canAccess = D->ext_oneapi_can_access_peer(
×
919
                    *PD, DPCTL_DPCTLPeerAccessTypeToSycl(PT));
×
920
            } catch (std::exception const &e) {
×
921
                error_handler(e, __FILE__, __func__, __LINE__);
×
922
            }
×
UNCOV
923
        }
×
UNCOV
924
    }
×
925
    return canAccess;
2✔
926
}
2✔
927

928
void DPCTLDevice_EnablePeerAccess(__dpctl_keep const DPCTLSyclDeviceRef DRef,
929
                                  __dpctl_keep const DPCTLSyclDeviceRef PDRef)
930
{
1✔
931
    auto D = unwrap<device>(DRef);
1✔
932
    auto PD = unwrap<device>(PDRef);
1✔
933
    if (D && PD) {
1!
934
        if (_CallPeerAccess(*D, *PD)) {
×
935
            try {
×
936
                D->ext_oneapi_enable_peer_access(*PD);
×
937
            } catch (std::exception const &e) {
×
938
                error_handler(e, __FILE__, __func__, __LINE__);
×
939
            }
×
940
        }
×
UNCOV
941
        else {
×
UNCOV
942
            error_handler("Devices do not support peer access", __FILE__,
×
UNCOV
943
                          __func__, __LINE__);
×
UNCOV
944
        }
×
UNCOV
945
    }
×
946
    return;
1✔
947
}
1✔
948

949
void DPCTLDevice_DisablePeerAccess(__dpctl_keep const DPCTLSyclDeviceRef DRef,
950
                                   __dpctl_keep const DPCTLSyclDeviceRef PDRef)
951
{
1✔
952
    auto D = unwrap<device>(DRef);
1✔
953
    auto PD = unwrap<device>(PDRef);
1✔
954
    if (D && PD) {
1!
955
        if (_CallPeerAccess(*D, *PD)) {
×
956
            try {
×
957
                D->ext_oneapi_disable_peer_access(*PD);
×
958
            } catch (std::exception const &e) {
×
959
                error_handler(e, __FILE__, __func__, __LINE__);
×
960
            }
×
961
        }
×
UNCOV
962
        else {
×
UNCOV
963
            error_handler("Devices do not support peer access", __FILE__,
×
UNCOV
964
                          __func__, __LINE__);
×
UNCOV
965
        }
×
UNCOV
966
    }
×
967
    return;
1✔
968
}
1✔
969

970
uint32_t DPCTLDevice_GetVendorId(__dpctl_keep const DPCTLSyclDeviceRef DRef)
971
{
24✔
972
    uint32_t vendorId = 0;
24✔
973
    auto D = unwrap<device>(DRef);
24✔
974
    if (D) {
24✔
975
        try {
23✔
976
            vendorId = D->get_info<info::device::vendor_id>();
23✔
977
        } catch (std::exception const &e) {
23✔
978
            error_handler(e, __FILE__, __func__, __LINE__);
×
979
        }
×
980
    }
23✔
981
    return vendorId;
24✔
982
}
24✔
983

984
uint32_t DPCTLDevice_GetAddressBits(__dpctl_keep const DPCTLSyclDeviceRef DRef)
985
{
24✔
986
    uint32_t addressBits = 0;
24✔
987
    auto D = unwrap<device>(DRef);
24✔
988
    if (D) {
24✔
989
        try {
23✔
990
            addressBits = D->get_info<info::device::address_bits>();
23✔
991
        } catch (std::exception const &e) {
23✔
UNCOV
992
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
993
        }
×
994
    }
23✔
995
    return addressBits;
24✔
996
}
24✔
997

998
size_t
999
DPCTLDevice_GetImageMaxBufferSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1000
{
24✔
1001
    size_t result = 0;
24✔
1002
    auto D = unwrap<device>(DRef);
24✔
1003
    if (D) {
24✔
1004
        try {
23✔
1005
            result = D->get_info<info::device::image_max_buffer_size>();
23✔
1006
        } catch (std::exception const &e) {
23✔
UNCOV
1007
            error_handler(e, __FILE__, __func__, __LINE__);
×
1008
        }
×
1009
    }
23✔
1010
    return result;
24✔
1011
}
24✔
1012

1013
uint32_t DPCTLDevice_GetMaxSamplers(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1014
{
24✔
1015
    uint32_t result = 0;
24✔
1016
    auto D = unwrap<device>(DRef);
24✔
1017
    if (D) {
24✔
1018
        try {
23✔
1019
            result = D->get_info<info::device::max_samplers>();
23✔
1020
        } catch (std::exception const &e) {
23✔
UNCOV
1021
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
1022
        }
×
1023
    }
23✔
1024
    return result;
24✔
1025
}
24✔
1026

1027
size_t
1028
DPCTLDevice_GetMaxParameterSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1029
{
24✔
1030
    size_t result = 0;
24✔
1031
    auto D = unwrap<device>(DRef);
24✔
1032
    if (D) {
24✔
1033
        try {
23✔
1034
            result = D->get_info<info::device::max_parameter_size>();
23✔
1035
        } catch (std::exception const &e) {
23✔
UNCOV
1036
            error_handler(e, __FILE__, __func__, __LINE__);
×
1037
        }
×
1038
    }
23✔
1039
    return result;
24✔
1040
}
24✔
1041

1042
uint32_t
1043
DPCTLDevice_GetMemBaseAddrAlign(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1044
{
24✔
1045
    uint32_t result = 0;
24✔
1046
    auto D = unwrap<device>(DRef);
24✔
1047
    if (D) {
24✔
1048
        try {
23✔
1049
            result = D->get_info<info::device::mem_base_addr_align>();
23✔
1050
        } catch (std::exception const &e) {
23✔
UNCOV
1051
            error_handler(e, __FILE__, __func__, __LINE__);
×
1052
        }
×
1053
    }
23✔
1054
    return result;
24✔
1055
}
24✔
1056

1057
bool DPCTLDevice_GetErrorCorrectionSupport(
1058
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
1059
{
24✔
1060
    bool result = false;
24✔
1061
    auto D = unwrap<device>(DRef);
24✔
1062
    if (D) {
24✔
1063
        try {
23✔
1064
            result = D->get_info<info::device::error_correction_support>();
23✔
1065
        } catch (std::exception const &e) {
23✔
UNCOV
1066
            error_handler(e, __FILE__, __func__, __LINE__);
×
1067
        }
×
1068
    }
23✔
1069
    return result;
24✔
1070
}
24✔
1071

1072
bool DPCTLDevice_IsAvailable(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1073
{
24✔
1074
    bool result = false;
24✔
1075
    auto D = unwrap<device>(DRef);
24✔
1076
    if (D) {
24✔
1077
        try {
23✔
1078
            result = D->get_info<info::device::is_available>();
23✔
1079
        } catch (std::exception const &e) {
23✔
UNCOV
1080
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
1081
        }
×
1082
    }
23✔
1083
    return result;
24✔
1084
}
24✔
1085

1086
__dpctl_give const char *
1087
DPCTLDevice_GetVersion(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1088
{
24✔
1089
    const char *cstr_version = nullptr;
24✔
1090
    auto D = unwrap<device>(DRef);
24✔
1091
    if (D) {
24✔
1092
        try {
23✔
1093
            auto version = D->get_info<info::device::version>();
23✔
1094
            cstr_version = dpctl::helper::cstring_from_string(version);
23✔
1095
        } catch (std::exception const &e) {
23✔
1096
            error_handler(e, __FILE__, __func__, __LINE__);
×
1097
        }
×
1098
    }
23✔
1099
    return cstr_version;
24✔
1100
}
24✔
1101

1102
__dpctl_give const char *
1103
DPCTLDevice_GetBackendVersion(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1104
{
24✔
1105
    const char *cstr_version = nullptr;
24✔
1106
    auto D = unwrap<device>(DRef);
24✔
1107
    if (D) {
24✔
1108
        try {
23✔
1109
            auto version = D->get_info<info::device::backend_version>();
23✔
1110
            cstr_version = dpctl::helper::cstring_from_string(version);
23✔
1111
        } catch (std::exception const &e) {
23✔
1112
            error_handler(e, __FILE__, __func__, __LINE__);
×
1113
        }
×
1114
    }
23✔
1115
    return cstr_version;
24✔
1116
}
24✔
1117

1118
DPCTLLocalMemType
1119
DPCTLDevice_GetLocalMemType(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1120
{
24✔
1121
    if (DRef) {
24✔
1122
        auto D = unwrap<device>(DRef);
23✔
1123
        try {
23✔
1124
            auto mem_type = D->get_info<info::device::local_mem_type>();
23✔
1125
            return DPCTL_SyclLocalMemTypeToDPCTLType(mem_type);
23✔
1126
        } catch (std::exception const &e) {
23✔
UNCOV
1127
            error_handler(e, __FILE__, __func__, __LINE__);
×
1128
        }
×
1129
    }
23✔
1130
    return DPCTL_LOCAL_MEM_TYPE_UNKNOWN;
1✔
1131
}
24✔
1132

1133
DPCTLPartitionPropertyType
1134
DPCTLDevice_GetPartitionTypeProperty(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1135
{
24✔
1136
    if (DRef) {
24✔
1137
        auto D = unwrap<device>(DRef);
23✔
1138
        try {
23✔
1139
            auto pp = D->get_info<info::device::partition_type_property>();
23✔
1140
            return DPCTL_SyclPartitionPropertyToDPCTLType(pp);
23✔
1141
        } catch (std::exception const &e) {
23✔
UNCOV
1142
            error_handler(e, __FILE__, __func__, __LINE__);
×
1143
        }
×
1144
    }
23✔
1145
    return DPCTL_PARTITION_UNKNOWN;
1✔
1146
}
24✔
1147

1148
DPCTLPartitionAffinityDomainType DPCTLDevice_GetPartitionTypeAffinityDomain(
1149
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
1150
{
24✔
1151
    if (DRef) {
24✔
1152
        auto D = unwrap<device>(DRef);
23✔
1153
        try {
23✔
1154
            auto domain =
23✔
1155
                D->get_info<info::device::partition_type_affinity_domain>();
23✔
1156
            return DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain);
23✔
1157
        } catch (std::exception const &e) {
23✔
1158
            error_handler(e, __FILE__, __func__, __LINE__);
×
1159
        }
×
1160
    }
23✔
1161
    return DPCTLPartitionAffinityDomainType::
1✔
1162
        DPCTL_PARTITION_AFFINITY_DOMAIN_UNKNOWN;
1✔
1163
}
24✔
1164

1165
namespace
1166
{
1167

1168
template <typename InfoDescT, typename ConvertFn>
1169
int *get_info_enum_array(__dpctl_keep const DPCTLSyclDeviceRef DRef,
1170
                         size_t *res_len,
1171
                         ConvertFn convert)
1172
{
232✔
1173
    int *arr = nullptr;
232✔
1174
    *res_len = 0;
232✔
1175
    auto D = unwrap<device>(DRef);
232✔
1176
    if (D) {
232✔
1177
        try {
223✔
1178
            auto values = D->get_info<InfoDescT>();
223✔
1179
            *res_len = values.size();
223✔
1180
            if (*res_len > 0) {
223✔
1181
                arr = new int[*res_len];
200✔
1182
                for (size_t i = 0; i < *res_len; ++i) {
1,039✔
1183
                    arr[i] = convert(values[i]);
839✔
1184
                }
839✔
1185
            }
200✔
1186
        } catch (std::exception const &e) {
223✔
UNCOV
1187
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
1188
            delete[] arr;
×
UNCOV
1189
            arr = nullptr;
×
UNCOV
1190
            *res_len = 0;
×
UNCOV
1191
        }
×
1192
    }
223✔
1193
    return arr;
232✔
1194
}
232✔
1195

1196
} // end of anonymous namespace
1197

1198
__dpctl_give int *
1199
DPCTLDevice_GetHalfFPConfig(__dpctl_keep const DPCTLSyclDeviceRef DRef,
1200
                            size_t *res_len)
1201
{
24✔
1202
    return get_info_enum_array<info::device::half_fp_config>(
24✔
1203
        DRef, res_len, DPCTL_SyclFPConfigToDPCTLType);
24✔
1204
}
24✔
1205

1206
__dpctl_give int *
1207
DPCTLDevice_GetSingleFPConfig(__dpctl_keep const DPCTLSyclDeviceRef DRef,
1208
                              size_t *res_len)
1209
{
24✔
1210
    return get_info_enum_array<info::device::single_fp_config>(
24✔
1211
        DRef, res_len, DPCTL_SyclFPConfigToDPCTLType);
24✔
1212
}
24✔
1213

1214
__dpctl_give int *
1215
DPCTLDevice_GetDoubleFPConfig(__dpctl_keep const DPCTLSyclDeviceRef DRef,
1216
                              size_t *res_len)
1217
{
24✔
1218
    return get_info_enum_array<info::device::double_fp_config>(
24✔
1219
        DRef, res_len, DPCTL_SyclFPConfigToDPCTLType);
24✔
1220
}
24✔
1221

1222
__dpctl_give int *DPCTLDevice_GetAtomicMemoryOrderCapabilities(
1223
    __dpctl_keep const DPCTLSyclDeviceRef DRef,
1224
    size_t *res_len)
1225
{
28✔
1226
    return get_info_enum_array<info::device::atomic_memory_order_capabilities>(
28✔
1227
        DRef, res_len, DPCTL_SyclMemoryOrderToDPCTLType);
28✔
1228
}
28✔
1229

1230
__dpctl_give int *DPCTLDevice_GetAtomicFenceOrderCapabilities(
1231
    __dpctl_keep const DPCTLSyclDeviceRef DRef,
1232
    size_t *res_len)
1233
{
28✔
1234
    return get_info_enum_array<info::device::atomic_fence_order_capabilities>(
28✔
1235
        DRef, res_len, DPCTL_SyclMemoryOrderToDPCTLType);
28✔
1236
}
28✔
1237

1238
__dpctl_give int *DPCTLDevice_GetAtomicMemoryScopeCapabilities(
1239
    __dpctl_keep const DPCTLSyclDeviceRef DRef,
1240
    size_t *res_len)
1241
{
28✔
1242
    return get_info_enum_array<info::device::atomic_memory_scope_capabilities>(
28✔
1243
        DRef, res_len, DPCTL_SyclMemoryScopeToDPCTLType);
28✔
1244
}
28✔
1245

1246
__dpctl_give int *DPCTLDevice_GetAtomicFenceScopeCapabilities(
1247
    __dpctl_keep const DPCTLSyclDeviceRef DRef,
1248
    size_t *res_len)
1249
{
28✔
1250
    return get_info_enum_array<info::device::atomic_fence_scope_capabilities>(
28✔
1251
        DRef, res_len, DPCTL_SyclMemoryScopeToDPCTLType);
28✔
1252
}
28✔
1253

1254
__dpctl_give int *
1255
DPCTLDevice_GetPartitionProperties(__dpctl_keep const DPCTLSyclDeviceRef DRef,
1256
                                   size_t *res_len)
1257
{
24✔
1258
    return get_info_enum_array<info::device::partition_properties>(
24✔
1259
        DRef, res_len, DPCTL_SyclPartitionPropertyToDPCTLType);
24✔
1260
}
24✔
1261

1262
__dpctl_give int *DPCTLDevice_GetPartitionAffinityDomains(
1263
    __dpctl_keep const DPCTLSyclDeviceRef DRef,
1264
    size_t *res_len)
1265
{
24✔
1266
    return get_info_enum_array<info::device::partition_affinity_domains>(
24✔
1267
        DRef, res_len, DPCTL_SyclPartitionAffinityDomainToDPCTLType);
24✔
1268
}
24✔
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