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

IntelPython / dpctl / 47369197318

04 Dec 2026 03:50PM UTC coverage: 75.182% (+0.03%) from 75.148%
47369197318

push

github

web-flow
Merge pull request #2384 from IntelPython/feature/build-with-adaptivecpp

Enable AdaptiveCpp builds

1083 of 1518 branches covered (71.34%)

Branch coverage included in aggregate %.

53 of 80 new or added lines in 15 files covered. (66.25%)

1 existing line in 1 file now uncovered.

4182 of 5485 relevant lines covered (76.24%)

297.4 hits per line

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

74.87
/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
#ifndef __ADAPTIVECPP__
46
static_assert(__SYCL_COMPILER_VERSION >= __SYCL_COMPILER_VERSION_REQUIRED,
47
              "The compiler does not meet minimum version requirement");
48
#endif
49

50
using namespace dpctl::syclinterface;
51

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

58
template <int dim>
59
__dpctl_give size_t *
60
DPCTLDevice__GetMaxWorkItemSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef)
61
{
5,452 ✔
62
    size_t *sizes = nullptr;
5,452 ✔
63
    auto D = unwrap<device>(DRef);
5,452 ✔
64
    if (D) {
5,452 ✔
65
        try {
5,449 ✔
66
#if defined(__ADAPTIVECPP__) ||                                                \
5,449 ✔
67
    (__SYCL_COMPILER_VERSION >= __SYCL_COMPILER_MAX_WORK_ITEM_SIZE_THRESHOLD)
5,449 ✔
68
            auto id_sizes =
5,449 ✔
69
                D->get_info<info::device::max_work_item_sizes<dim>>();
5,449 ✔
70
#else
71
            auto id_sizes = D->get_info<info::device::max_work_item_sizes<3>>();
72
#endif
73
            sizes = new size_t[dim];
5,449 ✔
74
            for (auto i = 0ul; i < dim; ++i) {
21,727 ✔
75
                sizes[i] = id_sizes[i];
16,278 ✔
76
            }
16,278 ✔
77
        } catch (std::exception const &e) {
5,449 ✔
78
            error_handler(e, __FILE__, __func__, __LINE__);
×
79
        }
×
80
    }
5,449 ✔
81
    return sizes;
5,452 ✔
82
}
5,452 ✔
83

84
} /* end of anonymous namespace */
85

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

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

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

134
void DPCTLDevice_Delete(__dpctl_take DPCTLSyclDeviceRef DRef)
135
{
9,347 ✔
136
    delete unwrap<device>(DRef);
9,347 ✔
137
}
9,347 ✔
138

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

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

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

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

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

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

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

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

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

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

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

265
__dpctl_give size_t *
266
DPCTLDevice_GetMaxWorkItemSizes3d(__dpctl_keep const DPCTLSyclDeviceRef DRef)
267
{
5,404 ✔
268
    return DPCTLDevice__GetMaxWorkItemSizes<3>(DRef);
5,404 ✔
269
}
5,404 ✔
270

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

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

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

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

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

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

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

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

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

414
namespace
415
{
416

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

432
} // end of anonymous namespace
433

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

868
__dpctl_give DPCTLSyclDeviceRef
869
DPCTLDevice_GetCompositeDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef)
870
{
9 ✔
871
#ifndef __ADAPTIVECPP__
9 ✔
872
    auto D = unwrap<device>(DRef);
9 ✔
873
    if (D) {
9 ✔
874
        bool is_component = false;
8 ✔
875
        try {
8 ✔
876
            is_component = D->has(sycl::aspect::ext_oneapi_is_component);
8 ✔
877
        } catch (std::exception const &e) {
8 ✔
878
            error_handler(e, __FILE__, __func__, __LINE__);
×
879
            return nullptr;
×
880
        }
×
881
        if (!is_component)
8 !
882
            return nullptr;
8 ✔
883
        try {
×
884
            const auto &compositeDevice =
×
885
                D->get_info<sycl::ext::oneapi::experimental::info::device::
×
886
                                composite_device>();
×
887
            return wrap<device>(new device(compositeDevice));
×
888
        } catch (std::exception const &e) {
×
889
            error_handler(e, __FILE__, __func__, __LINE__);
×
890
            return nullptr;
×
891
        }
×
892
    }
×
893
    else
1 ✔
894
        return nullptr;
1 ✔
895
#else
896
    return nullptr;
897
#endif
898
}
9 ✔
899

900
#ifndef __ADAPTIVECPP__
901

902
static inline bool _CallPeerAccess(device dev, device peer)
903
{
×
904
    auto BE1 = dev.get_backend();
×
905
    auto BE2 = peer.get_backend();
×
906

907
    if ((BE1 == BE2) &&
×
908
        (BE1 == sycl::backend::ext_oneapi_level_zero ||
×
909
         BE1 == sycl::backend::ext_oneapi_cuda ||
×
910
         BE1 == sycl::backend::ext_oneapi_hip) &&
×
911
        (BE2 == sycl::backend::ext_oneapi_level_zero ||
×
912
         BE2 == sycl::backend::ext_oneapi_cuda ||
×
913
         BE2 == sycl::backend::ext_oneapi_hip) &&
×
914
        (dev != peer))
×
915
    {
×
916
        return true;
×
917
    }
×
918
    return false;
×
919
}
×
920

921
#endif /* #ifndef __ADAPTIVECPP__ */
922

923
bool DPCTLDevice_CanAccessPeer(__dpctl_keep const DPCTLSyclDeviceRef DRef,
924
                               __dpctl_keep const DPCTLSyclDeviceRef PDRef,
925
                               DPCTLPeerAccessType PT)
926
{
2 ✔
927
    bool canAccess = false;
2 ✔
928
#ifndef __ADAPTIVECPP__
2 ✔
929
    auto D = unwrap<device>(DRef);
2 ✔
930
    auto PD = unwrap<device>(PDRef);
2 ✔
931
    if (D && PD) {
2 !
932
        if (_CallPeerAccess(*D, *PD)) {
×
933
            try {
×
934
                canAccess = D->ext_oneapi_can_access_peer(
×
935
                    *PD, DPCTL_DPCTLPeerAccessTypeToSycl(PT));
×
936
            } catch (std::exception const &e) {
×
937
                error_handler(e, __FILE__, __func__, __LINE__);
×
938
            }
×
939
        }
×
940
    }
×
941
#endif
2 ✔
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
#ifndef __ADAPTIVECPP__
1 ✔
949
    auto D = unwrap<device>(DRef);
1 ✔
950
    auto PD = unwrap<device>(PDRef);
1 ✔
951
    if (D && PD) {
1 !
952
        if (_CallPeerAccess(*D, *PD)) {
×
953
            try {
×
954
                D->ext_oneapi_enable_peer_access(*PD);
×
955
            } catch (std::exception const &e) {
×
956
                error_handler(e, __FILE__, __func__, __LINE__);
×
957
            }
×
958
        }
×
959
        else {
×
960
            error_handler("Devices do not support peer access", __FILE__,
×
961
                          __func__, __LINE__);
×
962
        }
×
963
    }
×
964
#endif
1 ✔
965
    return;
1 ✔
966
}
1 ✔
967

968
void DPCTLDevice_DisablePeerAccess(__dpctl_keep const DPCTLSyclDeviceRef DRef,
969
                                   __dpctl_keep const DPCTLSyclDeviceRef PDRef)
970
{
1 ✔
971
#ifndef __ADAPTIVECPP__
1 ✔
972
    auto D = unwrap<device>(DRef);
1 ✔
973
    auto PD = unwrap<device>(PDRef);
1 ✔
974
    if (D && PD) {
1 !
975
        if (_CallPeerAccess(*D, *PD)) {
×
976
            try {
×
977
                D->ext_oneapi_disable_peer_access(*PD);
×
978
            } catch (std::exception const &e) {
×
979
                error_handler(e, __FILE__, __func__, __LINE__);
×
980
            }
×
981
        }
×
982
        else {
×
983
            error_handler("Devices do not support peer access", __FILE__,
×
984
                          __func__, __LINE__);
×
985
        }
×
986
    }
×
987
#endif
1 ✔
988
    return;
1 ✔
989
}
1 ✔
990

991
uint32_t DPCTLDevice_GetVendorId(__dpctl_keep const DPCTLSyclDeviceRef DRef)
992
{
24 ✔
993
    uint32_t vendorId = 0;
24 ✔
994
    auto D = unwrap<device>(DRef);
24 ✔
995
    if (D) {
24 ✔
996
        try {
23 ✔
997
            vendorId = D->get_info<info::device::vendor_id>();
23 ✔
998
        } catch (std::exception const &e) {
23 ✔
999
            error_handler(e, __FILE__, __func__, __LINE__);
×
1000
        }
×
1001
    }
23 ✔
1002
    return vendorId;
24 ✔
1003
}
24 ✔
1004

1005
uint32_t DPCTLDevice_GetAddressBits(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1006
{
24 ✔
1007
    uint32_t addressBits = 0;
24 ✔
1008
    auto D = unwrap<device>(DRef);
24 ✔
1009
    if (D) {
24 ✔
1010
        try {
23 ✔
1011
            addressBits = D->get_info<info::device::address_bits>();
23 ✔
1012
        } catch (std::exception const &e) {
23 ✔
1013
            error_handler(e, __FILE__, __func__, __LINE__);
×
1014
        }
×
1015
    }
23 ✔
1016
    return addressBits;
24 ✔
1017
}
24 ✔
1018

1019
size_t
1020
DPCTLDevice_GetImageMaxBufferSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1021
{
24 ✔
1022
    size_t result = 0;
24 ✔
1023
    auto D = unwrap<device>(DRef);
24 ✔
1024
    if (D) {
24 ✔
1025
        try {
23 ✔
1026
            result = D->get_info<info::device::image_max_buffer_size>();
23 ✔
1027
        } catch (std::exception const &e) {
23 ✔
1028
            error_handler(e, __FILE__, __func__, __LINE__);
×
1029
        }
×
1030
    }
23 ✔
1031
    return result;
24 ✔
1032
}
24 ✔
1033

1034
uint32_t DPCTLDevice_GetMaxSamplers(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1035
{
24 ✔
1036
    uint32_t result = 0;
24 ✔
1037
    auto D = unwrap<device>(DRef);
24 ✔
1038
    if (D) {
24 ✔
1039
        try {
23 ✔
1040
            result = D->get_info<info::device::max_samplers>();
23 ✔
1041
        } catch (std::exception const &e) {
23 ✔
1042
            error_handler(e, __FILE__, __func__, __LINE__);
×
1043
        }
×
1044
    }
23 ✔
1045
    return result;
24 ✔
1046
}
24 ✔
1047

1048
size_t
1049
DPCTLDevice_GetMaxParameterSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1050
{
24 ✔
1051
    size_t result = 0;
24 ✔
1052
    auto D = unwrap<device>(DRef);
24 ✔
1053
    if (D) {
24 ✔
1054
        try {
23 ✔
1055
            result = D->get_info<info::device::max_parameter_size>();
23 ✔
1056
        } catch (std::exception const &e) {
23 ✔
1057
            error_handler(e, __FILE__, __func__, __LINE__);
×
1058
        }
×
1059
    }
23 ✔
1060
    return result;
24 ✔
1061
}
24 ✔
1062

1063
uint32_t
1064
DPCTLDevice_GetMemBaseAddrAlign(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1065
{
24 ✔
1066
    uint32_t result = 0;
24 ✔
1067
    auto D = unwrap<device>(DRef);
24 ✔
1068
    if (D) {
24 ✔
1069
        try {
23 ✔
1070
            result = D->get_info<info::device::mem_base_addr_align>();
23 ✔
1071
        } catch (std::exception const &e) {
23 ✔
1072
            error_handler(e, __FILE__, __func__, __LINE__);
×
1073
        }
×
1074
    }
23 ✔
1075
    return result;
24 ✔
1076
}
24 ✔
1077

1078
bool DPCTLDevice_GetErrorCorrectionSupport(
1079
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
1080
{
24 ✔
1081
    bool result = false;
24 ✔
1082
    auto D = unwrap<device>(DRef);
24 ✔
1083
    if (D) {
24 ✔
1084
        try {
23 ✔
1085
            result = D->get_info<info::device::error_correction_support>();
23 ✔
1086
        } catch (std::exception const &e) {
23 ✔
1087
            error_handler(e, __FILE__, __func__, __LINE__);
×
1088
        }
×
1089
    }
23 ✔
1090
    return result;
24 ✔
1091
}
24 ✔
1092

1093
bool DPCTLDevice_IsAvailable(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1094
{
24 ✔
1095
    bool result = false;
24 ✔
1096
    auto D = unwrap<device>(DRef);
24 ✔
1097
    if (D) {
24 ✔
1098
        try {
23 ✔
1099
            result = D->get_info<info::device::is_available>();
23 ✔
1100
        } catch (std::exception const &e) {
23 ✔
1101
            error_handler(e, __FILE__, __func__, __LINE__);
×
1102
        }
×
1103
    }
23 ✔
1104
    return result;
24 ✔
1105
}
24 ✔
1106

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

1123
__dpctl_give const char *
1124
DPCTLDevice_GetBackendVersion(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1125
{
24 ✔
1126
    const char *cstr_version = nullptr;
24 ✔
1127
#ifndef __ADAPTIVECPP__
24 ✔
1128
    auto D = unwrap<device>(DRef);
24 ✔
1129
    if (D) {
24 ✔
1130
        try {
23 ✔
1131
            auto version = D->get_info<info::device::backend_version>();
23 ✔
1132
            cstr_version = dpctl::helper::cstring_from_string(version);
23 ✔
1133
        } catch (std::exception const &e) {
23 ✔
1134
            error_handler(e, __FILE__, __func__, __LINE__);
×
1135
        }
×
1136
    }
23 ✔
1137
#else
1138
    error_handler("Backend version of a device is not queryable in AdaptiveCpp",
1139
                  __FILE__, __func__, __LINE__, error_level::error);
1140
#endif
1141
    return cstr_version;
24 ✔
1142
}
24 ✔
1143

1144
DPCTLLocalMemType
1145
DPCTLDevice_GetLocalMemType(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1146
{
24 ✔
1147
    if (DRef) {
24 ✔
1148
        auto D = unwrap<device>(DRef);
23 ✔
1149
        try {
23 ✔
1150
            auto mem_type = D->get_info<info::device::local_mem_type>();
23 ✔
1151
            return DPCTL_SyclLocalMemTypeToDPCTLType(mem_type);
23 ✔
1152
        } catch (std::exception const &e) {
23 ✔
1153
            error_handler(e, __FILE__, __func__, __LINE__);
×
1154
        }
×
1155
    }
23 ✔
1156
    return DPCTL_LOCAL_MEM_TYPE_UNKNOWN;
1 ✔
1157
}
24 ✔
1158

1159
DPCTLPartitionPropertyType
1160
DPCTLDevice_GetPartitionTypeProperty(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1161
{
24 ✔
1162
    if (DRef) {
24 ✔
1163
        auto D = unwrap<device>(DRef);
23 ✔
1164
        try {
23 ✔
1165
            auto pp = D->get_info<info::device::partition_type_property>();
23 ✔
1166
            return DPCTL_SyclPartitionPropertyToDPCTLType(pp);
23 ✔
1167
        } catch (std::exception const &e) {
23 ✔
1168
            error_handler(e, __FILE__, __func__, __LINE__);
×
1169
        }
×
1170
    }
23 ✔
1171
    return DPCTL_PARTITION_UNKNOWN;
1 ✔
1172
}
24 ✔
1173

1174
DPCTLPartitionAffinityDomainType DPCTLDevice_GetPartitionTypeAffinityDomain(
1175
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
1176
{
24 ✔
1177
    if (DRef) {
24 ✔
1178
        auto D = unwrap<device>(DRef);
23 ✔
1179
        try {
23 ✔
1180
            auto domain =
23 ✔
1181
                D->get_info<info::device::partition_type_affinity_domain>();
23 ✔
1182
            return DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain);
23 ✔
1183
        } catch (std::exception const &e) {
23 ✔
1184
            error_handler(e, __FILE__, __func__, __LINE__);
×
1185
        }
×
1186
    }
23 ✔
1187
    return DPCTLPartitionAffinityDomainType::
1 ✔
1188
        DPCTL_PARTITION_AFFINITY_DOMAIN_UNKNOWN;
1 ✔
1189
}
24 ✔
1190

1191
namespace
1192
{
1193

1194
template <typename InfoDescT, typename ConvertFn>
1195
int *get_info_enum_array(__dpctl_keep const DPCTLSyclDeviceRef DRef,
1196
                         size_t *res_len,
1197
                         ConvertFn convert)
1198
{
232 ✔
1199
    int *arr = nullptr;
232 ✔
1200
    *res_len = 0;
232 ✔
1201
    auto D = unwrap<device>(DRef);
232 ✔
1202
    if (D) {
232 ✔
1203
        try {
223 ✔
1204
            auto values = D->get_info<InfoDescT>();
223 ✔
1205
            *res_len = values.size();
223 ✔
1206
            if (*res_len > 0) {
223 ✔
1207
                arr = new int[*res_len];
200 ✔
1208
                for (size_t i = 0; i < *res_len; ++i) {
1,039 ✔
1209
                    arr[i] = convert(values[i]);
839 ✔
1210
                }
839 ✔
1211
            }
200 ✔
1212
        } catch (std::exception const &e) {
223 ✔
1213
            error_handler(e, __FILE__, __func__, __LINE__);
×
1214
            delete[] arr;
×
1215
            arr = nullptr;
×
1216
            *res_len = 0;
×
1217
        }
×
1218
    }
223 ✔
1219
    return arr;
232 ✔
1220
}
232 ✔
1221

1222
} // end of anonymous namespace
1223

1224
__dpctl_give int *
1225
DPCTLDevice_GetHalfFPConfig(__dpctl_keep const DPCTLSyclDeviceRef DRef,
1226
                            size_t *res_len)
1227
{
24 ✔
1228
    return get_info_enum_array<info::device::half_fp_config>(
24 ✔
1229
        DRef, res_len, DPCTL_SyclFPConfigToDPCTLType);
24 ✔
1230
}
24 ✔
1231

1232
__dpctl_give int *
1233
DPCTLDevice_GetSingleFPConfig(__dpctl_keep const DPCTLSyclDeviceRef DRef,
1234
                              size_t *res_len)
1235
{
24 ✔
1236
    return get_info_enum_array<info::device::single_fp_config>(
24 ✔
1237
        DRef, res_len, DPCTL_SyclFPConfigToDPCTLType);
24 ✔
1238
}
24 ✔
1239

1240
__dpctl_give int *
1241
DPCTLDevice_GetDoubleFPConfig(__dpctl_keep const DPCTLSyclDeviceRef DRef,
1242
                              size_t *res_len)
1243
{
24 ✔
1244
    return get_info_enum_array<info::device::double_fp_config>(
24 ✔
1245
        DRef, res_len, DPCTL_SyclFPConfigToDPCTLType);
24 ✔
1246
}
24 ✔
1247

1248
#ifndef __ADAPTIVECPP__
1249

1250
__dpctl_give int *DPCTLDevice_GetAtomicMemoryOrderCapabilities(
1251
    __dpctl_keep const DPCTLSyclDeviceRef DRef,
1252
    size_t *res_len)
1253
{
28 ✔
1254
    return get_info_enum_array<info::device::atomic_memory_order_capabilities>(
28 ✔
1255
        DRef, res_len, DPCTL_SyclMemoryOrderToDPCTLType);
28 ✔
1256
}
28 ✔
1257

1258
__dpctl_give int *DPCTLDevice_GetAtomicFenceOrderCapabilities(
1259
    __dpctl_keep const DPCTLSyclDeviceRef DRef,
1260
    size_t *res_len)
1261
{
28 ✔
1262
    return get_info_enum_array<info::device::atomic_fence_order_capabilities>(
28 ✔
1263
        DRef, res_len, DPCTL_SyclMemoryOrderToDPCTLType);
28 ✔
1264
}
28 ✔
1265

1266
__dpctl_give int *DPCTLDevice_GetAtomicMemoryScopeCapabilities(
1267
    __dpctl_keep const DPCTLSyclDeviceRef DRef,
1268
    size_t *res_len)
1269
{
28 ✔
1270
    return get_info_enum_array<info::device::atomic_memory_scope_capabilities>(
28 ✔
1271
        DRef, res_len, DPCTL_SyclMemoryScopeToDPCTLType);
28 ✔
1272
}
28 ✔
1273

1274
__dpctl_give int *DPCTLDevice_GetAtomicFenceScopeCapabilities(
1275
    __dpctl_keep const DPCTLSyclDeviceRef DRef,
1276
    size_t *res_len)
1277
{
28 ✔
1278
    return get_info_enum_array<info::device::atomic_fence_scope_capabilities>(
28 ✔
1279
        DRef, res_len, DPCTL_SyclMemoryScopeToDPCTLType);
28 ✔
1280
}
28 ✔
1281

1282
#else
1283

1284
namespace
1285
{
1286

1287
int *unsupported_device_capabilities(size_t *res_len)
1288
{
1289
    error_handler("Atomic capabilities of a device are not queryable in "
1290
                  "AdaptiveCpp",
1291
                  __FILE__, __func__, __LINE__, error_level::error);
1292
    *res_len = 0;
1293
    return nullptr;
1294
}
1295

1296
} // end of anonymous namespace
1297

1298
__dpctl_give int *DPCTLDevice_GetAtomicMemoryOrderCapabilities(
1299
    __dpctl_keep const DPCTLSyclDeviceRef,
1300
    size_t *res_len)
1301
{
1302
    return unsupported_device_capabilities(res_len);
1303
}
1304

1305
__dpctl_give int *DPCTLDevice_GetAtomicFenceOrderCapabilities(
1306
    __dpctl_keep const DPCTLSyclDeviceRef,
1307
    size_t *res_len)
1308
{
1309
    return unsupported_device_capabilities(res_len);
1310
}
1311

1312
__dpctl_give int *DPCTLDevice_GetAtomicMemoryScopeCapabilities(
1313
    __dpctl_keep const DPCTLSyclDeviceRef,
1314
    size_t *res_len)
1315
{
1316
    return unsupported_device_capabilities(res_len);
1317
}
1318

1319
__dpctl_give int *DPCTLDevice_GetAtomicFenceScopeCapabilities(
1320
    __dpctl_keep const DPCTLSyclDeviceRef,
1321
    size_t *res_len)
1322
{
1323
    return unsupported_device_capabilities(res_len);
1324
}
1325

1326
#endif /* #ifndef __ADAPTIVECPP__ */
1327

1328
__dpctl_give int *
1329
DPCTLDevice_GetPartitionProperties(__dpctl_keep const DPCTLSyclDeviceRef DRef,
1330
                                   size_t *res_len)
1331
{
24 ✔
1332
    return get_info_enum_array<info::device::partition_properties>(
24 ✔
1333
        DRef, res_len, DPCTL_SyclPartitionPropertyToDPCTLType);
24 ✔
1334
}
24 ✔
1335

1336
__dpctl_give int *DPCTLDevice_GetPartitionAffinityDomains(
1337
    __dpctl_keep const DPCTLSyclDeviceRef DRef,
1338
    size_t *res_len)
1339
{
24 ✔
1340
    return get_info_enum_array<info::device::partition_affinity_domains>(
24 ✔
1341
        DRef, res_len, DPCTL_SyclPartitionAffinityDomainToDPCTLType);
24 ✔
1342
}
24 ✔
1343

1344
bool DPCTLDevice_CanCompileSPIRV(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1345
{
×
1346
    bool canCompile = false;
×
NEW
1347
#ifndef __ADAPTIVECPP__
×
1348
    auto Dev = unwrap<device>(DRef);
×
1349
    if (Dev) {
×
1350
        try {
×
1351
            auto Backend = Dev->get_platform().get_backend();
×
1352
            canCompile = Backend == backend::opencl ||
×
1353
                         Backend == backend::ext_oneapi_level_zero;
×
1354
        } catch (std::exception const &e) {
×
1355
            error_handler(e, __FILE__, __func__, __LINE__);
×
1356
        }
×
1357
    }
×
NEW
1358
#endif
×
1359
    return canCompile;
×
1360
}
×
1361

1362
bool DPCTLDevice_CanCompileOpenCL(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1363
{
×
1364
    bool canCompile = false;
×
NEW
1365
#ifndef __ADAPTIVECPP__
×
1366
    auto Dev = unwrap<device>(DRef);
×
1367
    if (Dev) {
×
1368
        try {
×
1369
            canCompile = Dev->get_platform().get_backend() == backend::opencl;
×
1370
        } catch (std::exception const &e) {
×
1371
            error_handler(e, __FILE__, __func__, __LINE__);
×
1372
        }
×
1373
    }
×
NEW
1374
#endif
×
1375
    return canCompile;
×
1376
}
×
1377

1378
bool DPCTLDevice_CanCompileSYCL(__dpctl_keep const DPCTLSyclDeviceRef DRef)
1379
{
21 ✔
1380
#ifdef SYCL_EXT_ONEAPI_KERNEL_COMPILER
21 ✔
1381
    bool canCompile = false;
21 ✔
1382
    auto Dev = unwrap<device>(DRef);
21 ✔
1383
    if (Dev) {
21 !
1384
        try {
21 ✔
1385
            canCompile = Dev->ext_oneapi_can_compile(
21 ✔
1386
                ext::oneapi::experimental::source_language::sycl);
21 ✔
1387
        } catch (std::exception const &e) {
21 ✔
1388
            error_handler(e, __FILE__, __func__, __LINE__);
×
1389
        }
×
1390
    }
21 ✔
1391
    return canCompile;
21 ✔
1392
#else
1393
    return false;
1394
#endif
1395
}
21 ✔
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