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

IntelPython / dpctl / 14985801068

13 May 2025 12:59AM UTC coverage: 84.957% (-1.4%) from 86.372%
14985801068

Pull #2077

github

web-flow
Merge ba7222f4c into 3aff6ca34
Pull Request #2077: Support peer access DPC++ extension

2963 of 3766 branches covered (78.68%)

Branch coverage included in aggregate %.

41 of 156 new or added lines in 4 files covered. (26.28%)

97 existing lines in 18 files now uncovered.

12218 of 14103 relevant lines covered (86.63%)

6892.03 hits per line

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

74.24
/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-2025 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 <sstream>
37
#include <stddef.h>
38
#include <sycl/sycl.hpp> /* SYCL headers   */
39
#include <utility>
40
#include <vector>
41

42
using namespace sycl;
43

44
namespace
45
{
46

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

50
using namespace dpctl::syclinterface;
51

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

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

83
} /* end of anonymous namespace */
84

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

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

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

133
void DPCTLDevice_Delete(__dpctl_take DPCTLSyclDeviceRef DRef)
134
{
275,359✔
135
    delete unwrap<device>(DRef);
275,359✔
136
}
275,359✔
137

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

412
bool DPCTLDevice_GetSubGroupIndependentForwardProgress(
413
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
414
{
24✔
415
    bool SubGroupProgress = false;
24✔
416
    auto D = unwrap<device>(DRef);
24✔
417
    if (D) {
24✔
418
        try {
23✔
419
            SubGroupProgress = D->get_info<
23✔
420
                info::device::sub_group_independent_forward_progress>();
23✔
421
        } catch (std::exception const &e) {
23✔
422
            error_handler(e, __FILE__, __func__, __LINE__);
×
423
        }
×
424
    }
23✔
425
    return SubGroupProgress;
24✔
426
}
24✔
427

428
namespace
429
{
430

431
template <typename descriptorT>
432
uint32_t get_uint32_descriptor(__dpctl_keep const DPCTLSyclDeviceRef DRef)
433
{
329✔
434
    uint32_t descr_val = 0;
329✔
435
    auto D = unwrap<device>(DRef);
329✔
436
    if (D) {
329!
437
        try {
322✔
438
            descr_val = D->get_info<descriptorT>();
322✔
439
        } catch (std::exception const &e) {
322✔
440
            error_handler(e, __FILE__, __func__, __LINE__);
×
441
        }
×
442
    }
322✔
443
    return descr_val;
329✔
444
}
329✔
445

446
} // end of anonymous namespace
447

448
uint32_t DPCTLDevice_GetPreferredVectorWidthChar(
449
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
450
{
24✔
451
    return get_uint32_descriptor<info::device::preferred_vector_width_char>(
24✔
452
        DRef);
24✔
453
}
24✔
454

455
uint32_t DPCTLDevice_GetPreferredVectorWidthShort(
456
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
457
{
24✔
458
    return get_uint32_descriptor<info::device::preferred_vector_width_short>(
24✔
459
        DRef);
24✔
460
}
24✔
461

462
uint32_t DPCTLDevice_GetPreferredVectorWidthInt(
463
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
464
{
24✔
465
    return get_uint32_descriptor<info::device::preferred_vector_width_int>(
24✔
466
        DRef);
24✔
467
}
24✔
468

469
uint32_t DPCTLDevice_GetPreferredVectorWidthLong(
470
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
471
{
24✔
472
    return get_uint32_descriptor<info::device::preferred_vector_width_long>(
24✔
473
        DRef);
24✔
474
}
24✔
475

476
uint32_t DPCTLDevice_GetPreferredVectorWidthFloat(
477
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
478
{
24✔
479
    return get_uint32_descriptor<info::device::preferred_vector_width_float>(
24✔
480
        DRef);
24✔
481
}
24✔
482

483
uint32_t DPCTLDevice_GetPreferredVectorWidthDouble(
484
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
485
{
24✔
486
    return get_uint32_descriptor<info::device::preferred_vector_width_double>(
24✔
487
        DRef);
24✔
488
}
24✔
489

490
uint32_t DPCTLDevice_GetPreferredVectorWidthHalf(
491
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
492
{
24✔
493
    return get_uint32_descriptor<info::device::preferred_vector_width_half>(
24✔
494
        DRef);
24✔
495
}
24✔
496

497
//
498
uint32_t
499
DPCTLDevice_GetNativeVectorWidthChar(__dpctl_keep const DPCTLSyclDeviceRef DRef)
500
{
23✔
501
    return get_uint32_descriptor<info::device::native_vector_width_char>(DRef);
23✔
502
}
23✔
503

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

510
uint32_t
511
DPCTLDevice_GetNativeVectorWidthInt(__dpctl_keep const DPCTLSyclDeviceRef DRef)
512
{
23✔
513
    return get_uint32_descriptor<info::device::native_vector_width_int>(DRef);
23✔
514
}
23✔
515

516
uint32_t
517
DPCTLDevice_GetNativeVectorWidthLong(__dpctl_keep const DPCTLSyclDeviceRef DRef)
518
{
23✔
519
    return get_uint32_descriptor<info::device::native_vector_width_long>(DRef);
23✔
520
}
23✔
521

522
uint32_t DPCTLDevice_GetNativeVectorWidthFloat(
523
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
524
{
23✔
525
    return get_uint32_descriptor<info::device::native_vector_width_float>(DRef);
23✔
526
}
23✔
527

528
uint32_t DPCTLDevice_GetNativeVectorWidthDouble(
529
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
530
{
23✔
531
    return get_uint32_descriptor<info::device::native_vector_width_double>(
23✔
532
        DRef);
23✔
533
}
23✔
534

535
uint32_t
536
DPCTLDevice_GetNativeVectorWidthHalf(__dpctl_keep const DPCTLSyclDeviceRef DRef)
537
{
23✔
538
    return get_uint32_descriptor<info::device::native_vector_width_half>(DRef);
23✔
539
}
23✔
540

541
__dpctl_give DPCTLSyclDeviceRef
542
DPCTLDevice_GetParentDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef)
543
{
1,731✔
544
    auto D = unwrap<device>(DRef);
1,731✔
545
    if (D) {
1,731✔
546
        bool is_unpartitioned = false;
1,730✔
547
        try {
1,730✔
548
            auto pp =
1,730✔
549
                D->get_info<sycl::info::device::partition_type_property>();
1,730✔
550
            is_unpartitioned =
1,730✔
551
                (pp == sycl::info::partition_property::no_partition);
1,730✔
552
        } catch (std::exception const &e) {
1,730✔
553
            error_handler(e, __FILE__, __func__, __LINE__);
×
554
            return nullptr;
×
555
        }
×
556
        if (is_unpartitioned)
1,730✔
557
            return nullptr;
1,721✔
558
        try {
9✔
559
            const auto &parent_D = D->get_info<info::device::parent_device>();
9✔
560
            return wrap<device>(new device(parent_D));
9✔
561
        } catch (std::exception const &e) {
9✔
562
            error_handler(e, __FILE__, __func__, __LINE__);
×
563
            return nullptr;
×
564
        }
×
565
    }
9✔
566
    else
1✔
567
        return nullptr;
1✔
568
}
1,731✔
569

570
uint32_t DPCTLDevice_GetPartitionMaxSubDevices(
571
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
572
{
24✔
573
    auto D = unwrap<device>(DRef);
24✔
574
    if (D) {
24✔
575
        try {
23✔
576
            uint32_t part_max_sub_devs =
23✔
577
                D->get_info<info::device::partition_max_sub_devices>();
23✔
578
            return part_max_sub_devs;
23✔
579
        } catch (std::exception const &e) {
23✔
580
            error_handler(e, __FILE__, __func__, __LINE__);
×
581
            return 0;
×
582
        }
×
583
    }
23✔
584
    else
1✔
585
        return 0;
1✔
586
}
24✔
587

588
__dpctl_give DPCTLDeviceVectorRef
589
DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef,
590
                                    size_t count)
591
{
40✔
592
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
40✔
593
    vecTy *Devices = nullptr;
40✔
594
    if (DRef) {
40✔
595
        if (count == 0) {
39✔
596
            error_handler("Cannot create sub-devices with zero compute units",
8✔
597
                          __FILE__, __func__, __LINE__);
8✔
598
            return nullptr;
8✔
599
        }
8✔
600
        auto D = unwrap<device>(DRef);
31✔
601
        const auto &supported_properties =
31✔
602
            D->get_info<info::device::partition_properties>();
31✔
603
        const auto &beg_it = supported_properties.begin();
31✔
604
        const auto &end_it = supported_properties.end();
31✔
605
        if (std::find(beg_it, end_it,
31!
606
                      info::partition_property::partition_equally) == end_it)
31✔
607
        {
×
608
            // device does not support partition equally
609
            return nullptr;
×
610
        }
×
611
        try {
31✔
612
            auto subDevices = D->create_sub_devices<
31✔
613
                info::partition_property::partition_equally>(count);
31✔
614
            Devices = new vecTy();
31✔
615
            for (const auto &sd : subDevices) {
62✔
616
                Devices->emplace_back(wrap<device>(new device(sd)));
62✔
617
            }
62✔
618
        } catch (std::exception const &e) {
31✔
619
            delete Devices;
×
620
            error_handler(e, __FILE__, __func__, __LINE__);
×
621
            return nullptr;
×
622
        }
×
623
    }
31✔
624
    return wrap<vecTy>(Devices);
32✔
625
}
40✔
626

627
__dpctl_give DPCTLDeviceVectorRef
628
DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef,
629
                                     __dpctl_keep size_t *counts,
630
                                     size_t ncounts)
631
{
39✔
632
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
39✔
633
    vecTy *Devices = nullptr;
39✔
634
    std::vector<size_t> vcounts(ncounts);
39✔
635
    vcounts.assign(counts, counts + ncounts);
39✔
636
    size_t min_elem = *std::min_element(vcounts.begin(), vcounts.end());
39✔
637
    if (min_elem == 0) {
39✔
638
        error_handler("Cannot create sub-devices with zero compute units",
8✔
639
                      __FILE__, __func__, __LINE__);
8✔
640
        return nullptr;
8✔
641
    }
8✔
642
    if (DRef) {
31✔
643
        auto D = unwrap<device>(DRef);
30✔
644
        const auto &supported_properties =
30✔
645
            D->get_info<info::device::partition_properties>();
30✔
646
        const auto &beg_it = supported_properties.begin();
30✔
647
        const auto &end_it = supported_properties.end();
30✔
648
        if (std::find(beg_it, end_it,
30!
649
                      info::partition_property::partition_by_counts) == end_it)
30✔
650
        {
×
651
            // device does not support partition by counts
652
            return nullptr;
×
653
        }
×
654
        std::vector<std::remove_pointer<decltype(D)>::type> subDevices;
30✔
655
        try {
30✔
656
            subDevices = D->create_sub_devices<
30✔
657
                info::partition_property::partition_by_counts>(vcounts);
30✔
658
        } catch (std::exception const &e) {
30✔
659
            error_handler(e, __FILE__, __func__, __LINE__);
×
660
            return nullptr;
×
661
        }
×
662
        try {
30✔
663
            Devices = new vecTy();
30✔
664
            for (const auto &sd : subDevices) {
60✔
665
                Devices->emplace_back(wrap<device>(new device(sd)));
60✔
666
            }
60✔
667
        } catch (std::exception const &e) {
30✔
668
            delete Devices;
×
669
            error_handler(e, __FILE__, __func__, __LINE__);
×
670
            return nullptr;
×
671
        }
×
672
    }
30✔
673
    return wrap<vecTy>(Devices);
31✔
674
}
31✔
675

676
__dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity(
677
    __dpctl_keep const DPCTLSyclDeviceRef DRef,
678
    DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy)
679
{
157✔
680
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
157✔
681
    vecTy *Devices = nullptr;
157✔
682
    auto D = unwrap<device>(DRef);
157✔
683
    if (D) {
157✔
684
        const auto &supported_properties =
156✔
685
            D->get_info<info::device::partition_properties>();
156✔
686
        const auto &beg_it = supported_properties.begin();
156✔
687
        const auto &end_it = supported_properties.end();
156✔
688
        if (std::find(beg_it, end_it,
156!
689
                      info::partition_property::partition_by_affinity_domain) ==
156✔
690
            end_it)
156✔
691
        {
156✔
692
            // device does not support partition by affinity domain
693
            return nullptr;
156✔
694
        }
156✔
695
        try {
×
696
            auto domain = DPCTL_DPCTLPartitionAffinityDomainTypeToSycl(
×
697
                PartitionAffinityDomainTy);
×
698
            const auto &supported_affinity_domains =
×
699
                D->get_info<info::device::partition_affinity_domains>();
×
700
            const auto &beg_it = supported_affinity_domains.begin();
×
701
            const auto &end_it = supported_affinity_domains.end();
×
702
            if (std::find(beg_it, end_it, domain) == end_it) {
×
703
                // device does not support partitioning by this particular
704
                // affinity domain
705
                return nullptr;
×
706
            }
×
707
            auto subDevices = D->create_sub_devices<
×
708
                info::partition_property::partition_by_affinity_domain>(domain);
×
709
            Devices = new vecTy();
×
710
            for (const auto &sd : subDevices) {
×
711
                Devices->emplace_back(wrap<device>(new device(sd)));
×
712
            }
×
713
        } catch (std::exception const &e) {
×
714
            delete Devices;
×
715
            error_handler(e, __FILE__, __func__, __LINE__);
×
716
            return nullptr;
×
717
        }
×
718
    }
×
719
    return wrap<vecTy>(Devices);
1✔
720
}
157✔
721

722
size_t DPCTLDevice_Hash(__dpctl_keep const DPCTLSyclDeviceRef DRef)
723
{
51,747✔
724
    if (DRef) {
51,747✔
725
        auto D = unwrap<device>(DRef);
51,746✔
726
        std::hash<device> hash_fn;
51,746✔
727
        return hash_fn(*D);
51,746✔
728
    }
51,746✔
729
    else {
1✔
730
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
731
        return 0;
1✔
732
    }
1✔
733
}
51,747✔
734

735
size_t DPCTLDevice_GetProfilingTimerResolution(
736
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
737
{
24✔
738
    if (DRef) {
24✔
739
        auto D = unwrap<device>(DRef);
23✔
740
        return D->get_info<info::device::profiling_timer_resolution>();
23✔
741
    }
23✔
742
    else {
1✔
743
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
744
        return 0;
1✔
745
    }
1✔
746
}
24✔
747

748
uint32_t DPCTLDevice_GetGlobalMemCacheLineSize(
749
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
750
{
24✔
751
    if (DRef) {
24✔
752
        auto D = unwrap<device>(DRef);
23✔
753
        return D->get_info<info::device::global_mem_cache_line_size>();
23✔
754
    }
23✔
755
    else {
1✔
756
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
757
        return 0;
1✔
758
    }
1✔
759
}
24✔
760

761
uint32_t
762
DPCTLDevice_GetMaxClockFrequency(__dpctl_keep const DPCTLSyclDeviceRef DRef)
763
{
24✔
764
    if (DRef) {
24✔
765
        auto D = unwrap<device>(DRef);
23✔
766
        return D->get_info<info::device::max_clock_frequency>();
23✔
767
    }
23✔
768
    else {
1✔
769
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
770
        return 0;
1✔
771
    }
1✔
772
}
24✔
773

774
uint64_t
775
DPCTLDevice_GetMaxMemAllocSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
776
{
24✔
777
    if (DRef) {
24✔
778
        auto D = unwrap<device>(DRef);
23✔
779
        return D->get_info<info::device::max_mem_alloc_size>();
23✔
780
    }
23✔
781
    else {
1✔
782
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
783
        return 0;
1✔
784
    }
1✔
785
}
24✔
786

787
uint64_t
788
DPCTLDevice_GetGlobalMemCacheSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
789
{
24✔
790
    if (DRef) {
24✔
791
        auto D = unwrap<device>(DRef);
23✔
792
        return D->get_info<info::device::global_mem_cache_size>();
23✔
793
    }
23✔
794
    else {
1✔
795
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
796
        return 0;
1✔
797
    }
1✔
798
}
24✔
799

800
DPCTLGlobalMemCacheType
801
DPCTLDevice_GetGlobalMemCacheType(__dpctl_keep const DPCTLSyclDeviceRef DRef)
802
{
24✔
803
    if (DRef) {
24✔
804
        auto D = unwrap<device>(DRef);
23✔
805
        auto mem_type = D->get_info<info::device::global_mem_cache_type>();
23✔
806
        switch (mem_type) {
23!
807
        case info::global_mem_cache_type::none:
×
808
            return DPCTL_MEM_CACHE_TYPE_NONE;
×
809
        case info::global_mem_cache_type::read_only:
×
810
            return DPCTL_MEM_CACHE_TYPE_READ_ONLY;
×
811
        case info::global_mem_cache_type::read_write:
23!
812
            return DPCTL_MEM_CACHE_TYPE_READ_WRITE;
23✔
813
        }
23✔
814
        // If execution reaches here unrecognized mem_type was returned. Check
815
        // values in the enumeration `info::global_mem_cache_type` in SYCL specs
816
        assert(false);
23!
817
        return DPCTL_MEM_CACHE_TYPE_INDETERMINATE;
×
818
    }
×
819
    else {
1✔
820
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
821
        return DPCTL_MEM_CACHE_TYPE_INDETERMINATE;
1✔
822
    }
1✔
823
}
24✔
824

825
__dpctl_keep size_t *
826
DPCTLDevice_GetSubGroupSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef,
827
                             size_t *res_len)
828
{
24✔
829
    size_t *sizes = nullptr;
24✔
830
    std::vector<size_t> sg_sizes;
24✔
831
    *res_len = 0;
24✔
832
    auto D = unwrap<device>(DRef);
24✔
833
    if (D) {
24✔
834
        try {
23✔
835
            sg_sizes = D->get_info<info::device::sub_group_sizes>();
23✔
836
            *res_len = sg_sizes.size();
23✔
837
        } catch (std::exception const &e) {
23✔
838
            error_handler(e, __FILE__, __func__, __LINE__);
×
839
        }
×
840
        try {
23✔
841
            sizes = new size_t[sg_sizes.size()];
23✔
842
        } catch (std::exception const &e) {
23✔
843
            error_handler(e, __FILE__, __func__, __LINE__);
×
844
        }
×
845
        for (auto i = 0ul; (sizes != nullptr) && i < sg_sizes.size(); ++i) {
138!
846
            sizes[i] = sg_sizes[i];
115✔
847
        }
115✔
848
    }
23✔
849
    return sizes;
24✔
850
}
24✔
851

852
__dpctl_give DPCTLDeviceVectorRef
853
DPCTLDevice_GetComponentDevices(__dpctl_keep const DPCTLSyclDeviceRef DRef)
854
{
1✔
855
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
1✔
856
    vecTy *ComponentDevicesVectorPtr = nullptr;
1✔
857
    if (DRef) {
1!
858
        auto D = unwrap<device>(DRef);
×
859
        try {
×
860
            auto componentDevices =
×
861
                D->get_info<sycl::ext::oneapi::experimental::info::device::
×
862
                                component_devices>();
×
863
            ComponentDevicesVectorPtr = new vecTy();
×
864
            ComponentDevicesVectorPtr->reserve(componentDevices.size());
×
865
            for (const auto &cd : componentDevices) {
×
866
                ComponentDevicesVectorPtr->emplace_back(
×
867
                    wrap<device>(new device(cd)));
×
868
            }
×
869
        } catch (std::exception const &e) {
×
870
            delete ComponentDevicesVectorPtr;
×
871
            error_handler(e, __FILE__, __func__, __LINE__);
×
872
            return nullptr;
×
873
        }
×
874
    }
×
875
    return wrap<vecTy>(ComponentDevicesVectorPtr);
1✔
876
}
1✔
877

878
__dpctl_give DPCTLSyclDeviceRef
879
DPCTLDevice_GetCompositeDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef)
880
{
9✔
881
    auto D = unwrap<device>(DRef);
9✔
882
    if (D) {
9✔
883
        bool is_component = false;
8✔
884
        try {
8✔
885
            is_component = D->has(sycl::aspect::ext_oneapi_is_component);
8✔
886
        } catch (std::exception const &e) {
8✔
887
            error_handler(e, __FILE__, __func__, __LINE__);
×
888
            return nullptr;
×
889
        }
×
890
        if (!is_component)
8!
891
            return nullptr;
8✔
892
        try {
×
893
            const auto &compositeDevice =
×
894
                D->get_info<sycl::ext::oneapi::experimental::info::device::
×
895
                                composite_device>();
×
896
            return wrap<device>(new device(compositeDevice));
×
897
        } catch (std::exception const &e) {
×
898
            error_handler(e, __FILE__, __func__, __LINE__);
×
899
            return nullptr;
×
900
        }
×
901
    }
×
902
    else
1✔
903
        return nullptr;
1✔
904
}
9✔
905

906
bool _CallPeerAccess(device dev, device peer)
NEW
907
{
×
NEW
908
    auto BE1 = dev.get_backend();
×
NEW
909
    auto BE2 = peer.get_backend();
×
910

NEW
911
    if ((BE1 == BE2) &&
×
NEW
912
        (BE1 == sycl::backend::ext_oneapi_level_zero ||
×
NEW
913
         BE1 == sycl::backend::ext_oneapi_cuda ||
×
NEW
914
         BE1 == sycl::backend::ext_oneapi_hip) &&
×
NEW
915
        (BE2 == sycl::backend::ext_oneapi_level_zero ||
×
NEW
916
         BE2 == sycl::backend::ext_oneapi_cuda ||
×
NEW
917
         BE2 == sycl::backend::ext_oneapi_hip) &&
×
NEW
918
        (dev != peer))
×
NEW
919
    {
×
NEW
920
        return true;
×
NEW
921
    }
×
NEW
922
    return false;
×
NEW
923
}
×
924

925
bool DPCTLDevice_CanAccessPeer(__dpctl_keep const DPCTLSyclDeviceRef DRef,
926
                               __dpctl_keep const DPCTLSyclDeviceRef PDRef,
927
                               DPCTLPeerAccessType PT)
928
{
2✔
929
    bool canAccess = false;
2✔
930
    auto D = unwrap<device>(DRef);
2✔
931
    auto PD = unwrap<device>(PDRef);
2✔
932
    if (D && PD) {
2!
NEW
933
        if (_CallPeerAccess(*D, *PD)) {
×
NEW
934
            try {
×
NEW
935
                canAccess = D->ext_oneapi_can_access_peer(
×
NEW
936
                    *PD, DPCTL_DPCTLPeerAccessTypeToSycl(PT));
×
NEW
937
            } catch (std::exception const &e) {
×
NEW
938
                error_handler(e, __FILE__, __func__, __LINE__);
×
NEW
939
            }
×
NEW
940
        }
×
NEW
941
    }
×
942
    return canAccess;
2✔
943
}
2✔
944

945
void DPCTLDevice_EnablePeerAccess(__dpctl_keep const DPCTLSyclDeviceRef DRef,
946
                                  __dpctl_keep const DPCTLSyclDeviceRef PDRef)
947
{
1✔
948
    auto D = unwrap<device>(DRef);
1✔
949
    auto PD = unwrap<device>(PDRef);
1✔
950
    if (D && PD) {
1!
NEW
951
        if (_CallPeerAccess(*D, *PD)) {
×
NEW
952
            try {
×
NEW
953
                D->ext_oneapi_enable_peer_access(*PD);
×
NEW
954
            } catch (std::exception const &e) {
×
NEW
955
                error_handler(e, __FILE__, __func__, __LINE__);
×
NEW
956
            }
×
NEW
957
        }
×
NEW
958
        else {
×
NEW
959
            std::ostringstream os;
×
NEW
960
            os << "Given devices do not support peer access";
×
NEW
961
            error_handler(os.str(), __FILE__, __func__, __LINE__);
×
NEW
962
        }
×
NEW
963
    }
×
964
    return;
1✔
965
}
1✔
966

967
void DPCTLDevice_DisablePeerAccess(__dpctl_keep const DPCTLSyclDeviceRef DRef,
968
                                   __dpctl_keep const DPCTLSyclDeviceRef PDRef)
969
{
1✔
970
    auto D = unwrap<device>(DRef);
1✔
971
    auto PD = unwrap<device>(PDRef);
1✔
972
    if (D && PD) {
1!
NEW
973
        if (_CallPeerAccess(*D, *PD)) {
×
NEW
974
            try {
×
NEW
975
                D->ext_oneapi_disable_peer_access(*PD);
×
NEW
976
            } catch (std::exception const &e) {
×
NEW
977
                error_handler(e, __FILE__, __func__, __LINE__);
×
NEW
978
            }
×
NEW
979
        }
×
NEW
980
        else {
×
NEW
981
            std::ostringstream os;
×
NEW
982
            os << "Given devices do not support peer access";
×
NEW
983
            error_handler(os.str(), __FILE__, __func__, __LINE__);
×
NEW
984
        }
×
NEW
985
    }
×
986
    return;
1✔
987
}
1✔
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