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

IntelPython / dpctl / 5548076051

pending completion
5548076051

push

github

web-flow
Merge pull request #1280 from IntelPython/pin-syclos-version

Pin SYCLOS_Nightly version used

2261 of 2775 branches covered (81.48%)

Branch coverage included in aggregate %.

8283 of 9893 relevant lines covered (83.73%)

5826.42 hits per line

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

88.32
/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-2022 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 <CL/sycl.hpp> /* SYCL headers   */
36
#include <algorithm>
37
#include <cstring>
38
#include <vector>
39

40
using namespace sycl;
41

42
namespace
43
{
44

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

48
using namespace dpctl::syclinterface;
49

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

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

81
} /* end of anonymous namespace */
82

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

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

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

131
void DPCTLDevice_Delete(__dpctl_take DPCTLSyclDeviceRef DRef)
132
{
185,710✔
133
    delete unwrap<device>(DRef);
185,710✔
134
}
185,710✔
135

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

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

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

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

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

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

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

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

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

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

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

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

269
__dpctl_keep size_t *
270
DPCTLDevice_GetMaxWorkItemSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef)
271
{
11✔
272
    return DPCTLDevice__GetMaxWorkItemSizes<3>(DRef);
11✔
273
}
11✔
274

275
size_t
276
DPCTLDevice_GetMaxWorkGroupSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
277
{
29✔
278
    size_t max_wg_size = 0;
29✔
279
    auto D = unwrap<device>(DRef);
29✔
280
    if (D) {
29✔
281
        try {
28✔
282
            max_wg_size = D->get_info<info::device::max_work_group_size>();
28✔
283
        } catch (std::exception const &e) {
28✔
284
            error_handler(e, __FILE__, __func__, __LINE__);
×
285
        }
×
286
    }
28✔
287
    return max_wg_size;
29✔
288
}
29✔
289

290
uint32_t
291
DPCTLDevice_GetMaxNumSubGroups(__dpctl_keep const DPCTLSyclDeviceRef DRef)
292
{
29✔
293
    size_t max_nsubgroups = 0;
29✔
294
    auto D = unwrap<device>(DRef);
29✔
295
    if (D) {
29✔
296
        try {
28✔
297
            max_nsubgroups = D->get_info<info::device::max_num_sub_groups>();
28✔
298
        } catch (std::exception const &e) {
28✔
299
            error_handler(e, __FILE__, __func__, __LINE__);
×
300
        }
×
301
    }
28✔
302
    return max_nsubgroups;
29✔
303
}
29✔
304

305
__dpctl_give DPCTLSyclPlatformRef
306
DPCTLDevice_GetPlatform(__dpctl_keep const DPCTLSyclDeviceRef DRef)
307
{
3,544✔
308
    DPCTLSyclPlatformRef PRef = nullptr;
3,544✔
309
    auto D = unwrap<device>(DRef);
3,544✔
310
    if (D) {
3,544✔
311
        try {
3,543✔
312
            PRef = wrap<platform>(new platform(D->get_platform()));
3,543✔
313
        } catch (std::exception const &e) {
3,543✔
314
            error_handler(e, __FILE__, __func__, __LINE__);
×
315
        }
×
316
    }
3,543✔
317
    return PRef;
3,544✔
318
}
3,544✔
319

320
__dpctl_give const char *
321
DPCTLDevice_GetName(__dpctl_keep const DPCTLSyclDeviceRef DRef)
322
{
182,974✔
323
    const char *cstr_name = nullptr;
182,974✔
324
    auto D = unwrap<device>(DRef);
182,974✔
325
    if (D) {
182,974✔
326
        try {
182,973✔
327
            auto name = D->get_info<info::device::name>();
182,973✔
328
            cstr_name = dpctl::helper::cstring_from_string(name);
182,973✔
329
        } catch (std::exception const &e) {
182,973✔
330
            error_handler(e, __FILE__, __func__, __LINE__);
×
331
        }
×
332
    }
182,973✔
333
    return cstr_name;
182,974✔
334
}
182,974✔
335

336
__dpctl_give const char *
337
DPCTLDevice_GetVendor(__dpctl_keep const DPCTLSyclDeviceRef DRef)
338
{
182,974✔
339
    const char *cstr_vendor = nullptr;
182,974✔
340
    auto D = unwrap<device>(DRef);
182,974✔
341
    if (D) {
182,974✔
342
        try {
182,973✔
343
            auto vendor = D->get_info<info::device::vendor>();
182,973✔
344
            cstr_vendor = dpctl::helper::cstring_from_string(vendor);
182,973✔
345
        } catch (std::exception const &e) {
182,973✔
346
            error_handler(e, __FILE__, __func__, __LINE__);
×
347
        }
×
348
    }
182,973✔
349
    return cstr_vendor;
182,974✔
350
}
182,974✔
351

352
__dpctl_give const char *
353
DPCTLDevice_GetDriverVersion(__dpctl_keep const DPCTLSyclDeviceRef DRef)
354
{
182,974✔
355
    const char *cstr_driver = nullptr;
182,974✔
356
    auto D = unwrap<device>(DRef);
182,974✔
357
    if (D) {
182,974✔
358
        try {
182,973✔
359
            auto driver = D->get_info<info::device::driver_version>();
182,973✔
360
            cstr_driver = dpctl::helper::cstring_from_string(driver);
182,973✔
361
        } catch (std::exception const &e) {
182,973✔
362
            error_handler(e, __FILE__, __func__, __LINE__);
×
363
        }
×
364
    }
182,973✔
365
    return cstr_driver;
182,974✔
366
}
182,974✔
367

368
bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DRef1,
369
                       __dpctl_keep const DPCTLSyclDeviceRef DRef2)
370
{
28,299✔
371
    auto D1 = unwrap<device>(DRef1);
28,299✔
372
    auto D2 = unwrap<device>(DRef2);
28,299✔
373
    if (D1 && D2)
28,299!
374
        return *D1 == *D2;
28,298✔
375
    else
1✔
376
        return false;
1✔
377
}
28,299✔
378

379
bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef,
380
                           DPCTLSyclAspectType AT)
381
{
160,280✔
382
    bool hasAspect = false;
160,280✔
383
    auto D = unwrap<device>(DRef);
160,280✔
384
    if (D) {
160,280✔
385
        try {
160,279✔
386
            hasAspect = D->has(DPCTL_DPCTLAspectTypeToSyclAspect(AT));
160,279✔
387
        } catch (std::exception const &e) {
160,279✔
388
            error_handler(e, __FILE__, __func__, __LINE__);
×
389
        }
×
390
    }
160,279✔
391
    return hasAspect;
160,280✔
392
}
160,280✔
393

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

417
bool DPCTLDevice_GetSubGroupIndependentForwardProgress(
418
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
419
{
29✔
420
    bool SubGroupProgress = false;
29✔
421
    auto D = unwrap<device>(DRef);
29✔
422
    if (D) {
29✔
423
        try {
28✔
424
            SubGroupProgress = D->get_info<
28✔
425
                info::device::sub_group_independent_forward_progress>();
28✔
426
        } catch (std::exception const &e) {
28✔
427
            error_handler(e, __FILE__, __func__, __LINE__);
4✔
428
        }
4✔
429
    }
28✔
430
    return SubGroupProgress;
29✔
431
}
29✔
432

433
namespace
434
{
435

436
template <typename descriptorT>
437
uint32_t get_uint32_descriptor(__dpctl_keep const DPCTLSyclDeviceRef DRef)
438
{
399✔
439
    uint32_t descr_val = 0;
399✔
440
    auto D = unwrap<device>(DRef);
399✔
441
    if (D) {
399!
442
        try {
392✔
443
            descr_val = D->get_info<descriptorT>();
392✔
444
        } catch (std::exception const &e) {
392✔
445
            error_handler(e, __FILE__, __func__, __LINE__);
×
446
        }
×
447
    }
392✔
448
    return descr_val;
399✔
449
}
399✔
450

451
} // end of anonymous namespace
452

453
uint32_t DPCTLDevice_GetPreferredVectorWidthChar(
454
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
455
{
29✔
456
    return get_uint32_descriptor<info::device::preferred_vector_width_char>(
29✔
457
        DRef);
29✔
458
}
29✔
459

460
uint32_t DPCTLDevice_GetPreferredVectorWidthShort(
461
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
462
{
29✔
463
    return get_uint32_descriptor<info::device::preferred_vector_width_short>(
29✔
464
        DRef);
29✔
465
}
29✔
466

467
uint32_t DPCTLDevice_GetPreferredVectorWidthInt(
468
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
469
{
29✔
470
    return get_uint32_descriptor<info::device::preferred_vector_width_int>(
29✔
471
        DRef);
29✔
472
}
29✔
473

474
uint32_t DPCTLDevice_GetPreferredVectorWidthLong(
475
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
476
{
29✔
477
    return get_uint32_descriptor<info::device::preferred_vector_width_long>(
29✔
478
        DRef);
29✔
479
}
29✔
480

481
uint32_t DPCTLDevice_GetPreferredVectorWidthFloat(
482
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
483
{
29✔
484
    return get_uint32_descriptor<info::device::preferred_vector_width_float>(
29✔
485
        DRef);
29✔
486
}
29✔
487

488
uint32_t DPCTLDevice_GetPreferredVectorWidthDouble(
489
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
490
{
29✔
491
    return get_uint32_descriptor<info::device::preferred_vector_width_double>(
29✔
492
        DRef);
29✔
493
}
29✔
494

495
uint32_t DPCTLDevice_GetPreferredVectorWidthHalf(
496
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
497
{
29✔
498
    return get_uint32_descriptor<info::device::preferred_vector_width_half>(
29✔
499
        DRef);
29✔
500
}
29✔
501

502
//
503
uint32_t
504
DPCTLDevice_GetNativeVectorWidthChar(__dpctl_keep const DPCTLSyclDeviceRef DRef)
505
{
28✔
506
    return get_uint32_descriptor<info::device::native_vector_width_char>(DRef);
28✔
507
}
28✔
508

509
uint32_t DPCTLDevice_GetNativeVectorWidthShort(
510
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
511
{
28✔
512
    return get_uint32_descriptor<info::device::native_vector_width_short>(DRef);
28✔
513
}
28✔
514

515
uint32_t
516
DPCTLDevice_GetNativeVectorWidthInt(__dpctl_keep const DPCTLSyclDeviceRef DRef)
517
{
28✔
518
    return get_uint32_descriptor<info::device::native_vector_width_int>(DRef);
28✔
519
}
28✔
520

521
uint32_t
522
DPCTLDevice_GetNativeVectorWidthLong(__dpctl_keep const DPCTLSyclDeviceRef DRef)
523
{
28✔
524
    return get_uint32_descriptor<info::device::native_vector_width_long>(DRef);
28✔
525
}
28✔
526

527
uint32_t DPCTLDevice_GetNativeVectorWidthFloat(
528
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
529
{
28✔
530
    return get_uint32_descriptor<info::device::native_vector_width_float>(DRef);
28✔
531
}
28✔
532

533
uint32_t DPCTLDevice_GetNativeVectorWidthDouble(
534
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
535
{
28✔
536
    return get_uint32_descriptor<info::device::native_vector_width_double>(
28✔
537
        DRef);
28✔
538
}
28✔
539

540
uint32_t
541
DPCTLDevice_GetNativeVectorWidthHalf(__dpctl_keep const DPCTLSyclDeviceRef DRef)
542
{
28✔
543
    return get_uint32_descriptor<info::device::native_vector_width_half>(DRef);
28✔
544
}
28✔
545

546
__dpctl_give DPCTLSyclDeviceRef
547
DPCTLDevice_GetParentDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef)
548
{
2,583✔
549
    auto D = unwrap<device>(DRef);
2,583✔
550
    if (D) {
2,583✔
551
        try {
2,582✔
552
            auto parent_D = D->get_info<info::device::parent_device>();
2,582✔
553
            return wrap<device>(new device(parent_D));
2,582✔
554
        } catch (std::exception const &e) {
2,582✔
555
            error_handler(e, __FILE__, __func__, __LINE__);
2,572✔
556
            return nullptr;
2,572✔
557
        }
2,572✔
558
    }
2,582✔
559
    else
1✔
560
        return nullptr;
1✔
561
}
2,583✔
562

563
uint32_t DPCTLDevice_GetPartitionMaxSubDevices(
564
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
565
{
29✔
566
    auto D = unwrap<device>(DRef);
29✔
567
    if (D) {
29✔
568
        try {
28✔
569
            uint32_t part_max_sub_devs =
28✔
570
                D->get_info<info::device::partition_max_sub_devices>();
28✔
571
            return part_max_sub_devs;
28✔
572
        } catch (std::exception const &e) {
28✔
573
            error_handler(e, __FILE__, __func__, __LINE__);
×
574
            return 0;
×
575
        }
×
576
    }
28✔
577
    else
1✔
578
        return 0;
1✔
579
}
29✔
580

581
__dpctl_give DPCTLDeviceVectorRef
582
DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef,
583
                                    size_t count)
584
{
49✔
585
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
49✔
586
    vecTy *Devices = nullptr;
49✔
587
    if (DRef) {
49✔
588
        if (count == 0) {
48✔
589
            error_handler("Cannot create sub-devices with zero compute units",
10✔
590
                          __FILE__, __func__, __LINE__);
10✔
591
            return nullptr;
10✔
592
        }
10✔
593
        auto D = unwrap<device>(DRef);
38✔
594
        try {
38✔
595
            auto subDevices = D->create_sub_devices<
38✔
596
                info::partition_property::partition_equally>(count);
38✔
597
            Devices = new vecTy();
38✔
598
            for (const auto &sd : subDevices) {
76✔
599
                Devices->emplace_back(wrap<device>(new device(sd)));
76✔
600
            }
76✔
601
        } catch (std::exception const &e) {
38✔
602
            delete Devices;
×
603
            error_handler(e, __FILE__, __func__, __LINE__);
×
604
            return nullptr;
×
605
        }
×
606
    }
38✔
607
    return wrap<vecTy>(Devices);
39✔
608
}
49✔
609

610
__dpctl_give DPCTLDeviceVectorRef
611
DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef,
612
                                     __dpctl_keep size_t *counts,
613
                                     size_t ncounts)
614
{
45✔
615
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
45✔
616
    vecTy *Devices = nullptr;
45✔
617
    std::vector<size_t> vcounts(ncounts);
45✔
618
    vcounts.assign(counts, counts + ncounts);
45✔
619
    size_t min_elem = *std::min_element(vcounts.begin(), vcounts.end());
45✔
620
    if (min_elem == 0) {
45✔
621
        error_handler("Cannot create sub-devices with zero compute units",
10✔
622
                      __FILE__, __func__, __LINE__);
10✔
623
        return nullptr;
10✔
624
    }
10✔
625
    if (DRef) {
35✔
626
        auto D = unwrap<device>(DRef);
34✔
627
        std::vector<std::remove_pointer<decltype(D)>::type> subDevices;
34✔
628
        try {
34✔
629
            subDevices = D->create_sub_devices<
34✔
630
                info::partition_property::partition_by_counts>(vcounts);
34✔
631
        } catch (std::exception const &e) {
34✔
632
            error_handler(e, __FILE__, __func__, __LINE__);
×
633
            return nullptr;
×
634
        }
×
635
        try {
34✔
636
            Devices = new vecTy();
34✔
637
            for (const auto &sd : subDevices) {
68✔
638
                Devices->emplace_back(wrap<device>(new device(sd)));
68✔
639
            }
68✔
640
        } catch (std::exception const &e) {
34✔
641
            delete Devices;
×
642
            error_handler(e, __FILE__, __func__, __LINE__);
×
643
            return nullptr;
×
644
        }
×
645
    }
34✔
646
    return wrap<vecTy>(Devices);
35✔
647
}
35✔
648

649
__dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity(
650
    __dpctl_keep const DPCTLSyclDeviceRef DRef,
651
    DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy)
652
{
187✔
653
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
187✔
654
    vecTy *Devices = nullptr;
187✔
655
    auto D = unwrap<device>(DRef);
187✔
656
    if (D) {
187✔
657
        try {
186✔
658
            auto domain = DPCTL_DPCTLPartitionAffinityDomainTypeToSycl(
186✔
659
                PartitionAffinityDomainTy);
186✔
660
            auto subDevices = D->create_sub_devices<
186✔
661
                info::partition_property::partition_by_affinity_domain>(domain);
186✔
662
            Devices = new vecTy();
186✔
663
            for (const auto &sd : subDevices) {
186!
664
                Devices->emplace_back(wrap<device>(new device(sd)));
×
665
            }
×
666
        } catch (std::exception const &e) {
186✔
667
            delete Devices;
186✔
668
            error_handler(e, __FILE__, __func__, __LINE__);
186✔
669
            return nullptr;
186✔
670
        }
186✔
671
    }
186✔
672
    return wrap<vecTy>(Devices);
1✔
673
}
187✔
674

675
size_t DPCTLDevice_Hash(__dpctl_keep const DPCTLSyclDeviceRef DRef)
676
{
27,371✔
677
    if (DRef) {
27,371✔
678
        auto D = unwrap<device>(DRef);
27,370✔
679
        std::hash<device> hash_fn;
27,370✔
680
        return hash_fn(*D);
27,370✔
681
    }
27,370✔
682
    else {
1✔
683
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
684
        return 0;
1✔
685
    }
1✔
686
}
27,371✔
687

688
size_t DPCTLDevice_GetProfilingTimerResolution(
689
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
690
{
29✔
691
    if (DRef) {
29✔
692
        auto D = unwrap<device>(DRef);
28✔
693
        return D->get_info<info::device::profiling_timer_resolution>();
28✔
694
    }
28✔
695
    else {
1✔
696
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
697
        return 0;
1✔
698
    }
1✔
699
}
29✔
700

701
uint32_t DPCTLDevice_GetGlobalMemCacheLineSize(
702
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
703
{
29✔
704
    if (DRef) {
29✔
705
        auto D = unwrap<device>(DRef);
28✔
706
        return D->get_info<info::device::global_mem_cache_line_size>();
28✔
707
    }
28✔
708
    else {
1✔
709
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
710
        return 0;
1✔
711
    }
1✔
712
}
29✔
713

714
uint64_t
715
DPCTLDevice_GetGlobalMemCacheSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
716
{
29✔
717
    if (DRef) {
29✔
718
        auto D = unwrap<device>(DRef);
28✔
719
        return D->get_info<info::device::global_mem_cache_size>();
28✔
720
    }
28✔
721
    else {
1✔
722
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
723
        return 0;
1✔
724
    }
1✔
725
}
29✔
726

727
DPCTLGlobalMemCacheType
728
DPCTLDevice_GetGlobalMemCacheType(__dpctl_keep const DPCTLSyclDeviceRef DRef)
729
{
29✔
730
    if (DRef) {
29✔
731
        auto D = unwrap<device>(DRef);
28✔
732
        auto mem_type = D->get_info<info::device::global_mem_cache_type>();
28✔
733
        switch (mem_type) {
28!
734
        case info::global_mem_cache_type::none:
×
735
            return DPCTL_MEM_CACHE_TYPE_NONE;
×
736
        case info::global_mem_cache_type::read_only:
×
737
            return DPCTL_MEM_CACHE_TYPE_READ_ONLY;
×
738
        case info::global_mem_cache_type::read_write:
28!
739
            return DPCTL_MEM_CACHE_TYPE_READ_WRITE;
28✔
740
        }
28✔
741
        // If execution reaches here unrecognized mem_type was returned. Check
742
        // values in the enumeration `info::global_mem_cache_type` in SYCL specs
743
        assert(false);
×
744
        return DPCTL_MEM_CACHE_TYPE_INDETERMINATE;
×
745
    }
×
746
    else {
1✔
747
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
748
        return DPCTL_MEM_CACHE_TYPE_INDETERMINATE;
1✔
749
    }
1✔
750
}
29✔
751

752
__dpctl_keep size_t *
753
DPCTLDevice_GetSubGroupSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef,
754
                             size_t *res_len)
755
{
29✔
756
    size_t *sizes = nullptr;
29✔
757
    std::vector<size_t> sg_sizes;
29✔
758
    *res_len = 0;
29✔
759
    auto D = unwrap<device>(DRef);
29✔
760
    if (D) {
29✔
761
        try {
28✔
762
            sg_sizes = D->get_info<info::device::sub_group_sizes>();
28✔
763
            *res_len = sg_sizes.size();
28✔
764
        } catch (std::exception const &e) {
28✔
765
            error_handler(e, __FILE__, __func__, __LINE__);
×
766
        }
×
767
        try {
28✔
768
            sizes = new size_t[sg_sizes.size()];
28✔
769
        } catch (std::exception const &e) {
28✔
770
            error_handler(e, __FILE__, __func__, __LINE__);
×
771
        }
×
772
        for (auto i = 0ul; (sizes != nullptr) && i < sg_sizes.size(); ++i) {
168!
773
            sizes[i] = sg_sizes[i];
140✔
774
        }
140✔
775
    }
28✔
776
    return sizes;
29✔
777
}
29✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc