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

IntelPython / dpctl / 35424644453

19 Sep 2026 05:41AM UTC coverage: 75.167% (+0.2%) from 74.959%
35424644453

Pull #2384

github

web-flow
Merge cee555b34 into 3799508da
Pull Request #2384: Enable AdaptiveCpp builds

1053 of 1482 branches covered (71.05%)

Branch coverage included in aggregate %.

81 of 101 new or added lines in 17 files covered. (80.2%)

2 existing lines in 2 files now uncovered.

4111 of 5388 relevant lines covered (76.3%)

286.17 hits per line

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

74.91
/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,551 ✔
54
    return new device(
7,551 ✔
55
        [=](const device &d) -> int { return sel->operator()(d); });
7,551 ✔
56
}
7,551 ✔
57

58
template <int dim>
59
__dpctl_give size_t *
60
DPCTLDevice__GetMaxWorkItemSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef)
61
{
5,263 ✔
62
    size_t *sizes = nullptr;
5,263 ✔
63
    auto D = unwrap<device>(DRef);
5,263 ✔
64
    if (D) {
5,263 ✔
65
        try {
5,260 ✔
66
#if defined(__ADAPTIVECPP__) ||                                                \
5,260 ✔
67
    (__SYCL_COMPILER_VERSION >= __SYCL_COMPILER_MAX_WORK_ITEM_SIZE_THRESHOLD)
5,260 ✔
68
            auto id_sizes =
5,260 ✔
69
                D->get_info<info::device::max_work_item_sizes<dim>>();
5,260 ✔
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,260 ✔
74
            for (auto i = 0ul; i < dim; ++i) {
20,971 ✔
75
                sizes[i] = id_sizes[i];
15,711 ✔
76
            }
15,711 ✔
77
        } catch (std::exception const &e) {
5,260 ✔
78
            error_handler(e, __FILE__, __func__, __LINE__);
×
79
        }
×
80
    }
5,260 ✔
81
    return sizes;
5,263 ✔
82
}
5,263 ✔
83

84
} /* end of anonymous namespace */
85

86
__dpctl_give DPCTLSyclDeviceRef
87
DPCTLDevice_Copy(__dpctl_keep const DPCTLSyclDeviceRef DRef)
88
{
2,544 ✔
89
    auto Device = unwrap<device>(DRef);
2,544 ✔
90
    if (!Device) {
2,544 ✔
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,543 ✔
96
        auto CopiedDevice = new device(*Device);
2,543 ✔
97
        return wrap<device>(CopiedDevice);
2,543 ✔
98
    } catch (std::exception const &e) {
2,543 ✔
99
        error_handler(e, __FILE__, __func__, __LINE__);
×
100
        return nullptr;
×
101
    }
×
102
}
2,543 ✔
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,565 ✔
118
    auto Selector = unwrap<dpctl_device_selector>(DSRef);
7,565 ✔
119
    if (!Selector) {
7,565 ✔
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,551 ✔
126
        auto Device = new_device_from_selector(Selector);
7,551 ✔
127
        return wrap<device>(Device);
7,551 ✔
128
    } catch (std::exception const &e) {
7,551 ✔
129
        error_handler(e, __FILE__, __func__, __LINE__);
4,120 ✔
130
        return nullptr;
4,120 ✔
131
    }
4,120 ✔
132
}
7,551 ✔
133

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

139
DPCTLSyclDeviceType
140
DPCTLDevice_GetDeviceType(__dpctl_keep const DPCTLSyclDeviceRef DRef)
141
{
55 ✔
142
    DPCTLSyclDeviceType DTy = DPCTLSyclDeviceType::DPCTL_UNKNOWN_DEVICE;
55 ✔
143
    auto D = unwrap<device>(DRef);
55 ✔
144
    if (D) {
55 ✔
145
        try {
54 ✔
146
            auto SyclDTy = D->get_info<info::device::device_type>();
54 ✔
147
            DTy = DPCTL_SyclDeviceTypeToDPCTLDeviceType(SyclDTy);
54 ✔
148
        } catch (std::exception const &e) {
54 ✔
149
            error_handler(e, __FILE__, __func__, __LINE__);
×
150
        }
×
151
    }
54 ✔
152
    return DTy;
55 ✔
153
}
55 ✔
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
{
56 ✔
185
    DPCTLSyclBackendType BTy = DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
56 ✔
186
    auto D = unwrap<device>(DRef);
56 ✔
187
    if (D) {
56 !
188
        BTy = DPCTL_SyclBackendToDPCTLBackendType(D->get_backend());
56 ✔
189
    }
56 ✔
190
    return BTy;
56 ✔
191
}
56 ✔
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,215 ✔
268
    return DPCTLDevice__GetMaxWorkItemSizes<3>(DRef);
5,215 ✔
269
}
5,215 ✔
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,215 ✔
319
    const char *cstr_name = nullptr;
5,215 ✔
320
    auto D = unwrap<device>(DRef);
5,215 ✔
321
    if (D) {
5,215 ✔
322
        try {
5,214 ✔
323
            auto name = D->get_info<info::device::name>();
5,214 ✔
324
            cstr_name = dpctl::helper::cstring_from_string(name);
5,214 ✔
325
        } catch (std::exception const &e) {
5,214 ✔
326
            error_handler(e, __FILE__, __func__, __LINE__);
×
327
        }
×
328
    }
5,214 ✔
329
    return cstr_name;
5,215 ✔
330
}
5,215 ✔
331

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

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

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

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

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

413
namespace
414
{
415

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

431
} // end of anonymous namespace
432

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

897
#ifndef __ADAPTIVECPP__
898

899
static inline bool _CallPeerAccess(device dev, device peer)
900
{
×
901
    auto BE1 = dev.get_backend();
×
902
    auto BE2 = peer.get_backend();
×
903

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

918
#endif /* #ifndef __ADAPTIVECPP__ */
919

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1188
namespace
1189
{
1190

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

1219
} // end of anonymous namespace
1220

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

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

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

1245
#ifndef __ADAPTIVECPP__
1246

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

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

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

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

1279
#else
1280

1281
namespace
1282
{
1283

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

1293
} // end of anonymous namespace
1294

1295
__dpctl_give int *DPCTLDevice_GetAtomicMemoryOrderCapabilities(
1296
    __dpctl_keep const DPCTLSyclDeviceRef,
1297
    size_t *res_len)
1298
{
1299
    return unsupported_device_capabilities(res_len);
1300
}
1301

1302
__dpctl_give int *DPCTLDevice_GetAtomicFenceOrderCapabilities(
1303
    __dpctl_keep const DPCTLSyclDeviceRef,
1304
    size_t *res_len)
1305
{
1306
    return unsupported_device_capabilities(res_len);
1307
}
1308

1309
__dpctl_give int *DPCTLDevice_GetAtomicMemoryScopeCapabilities(
1310
    __dpctl_keep const DPCTLSyclDeviceRef,
1311
    size_t *res_len)
1312
{
1313
    return unsupported_device_capabilities(res_len);
1314
}
1315

1316
__dpctl_give int *DPCTLDevice_GetAtomicFenceScopeCapabilities(
1317
    __dpctl_keep const DPCTLSyclDeviceRef,
1318
    size_t *res_len)
1319
{
1320
    return unsupported_device_capabilities(res_len);
1321
}
1322

1323
#endif /* #ifndef __ADAPTIVECPP__ */
1324

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

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

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

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

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