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

IntelPython / dpctl / 9687667737

26 Jun 2024 10:32PM UTC coverage: 87.965% (-0.09%) from 88.057%
9687667737

Pull #1719

github

web-flow
Merge 20929bec2 into 26d34f565
Pull Request #1719: Add Python scalar support to `dpt.where`

3326 of 3820 branches covered (87.07%)

Branch coverage included in aggregate %.

91 of 94 new or added lines in 1 file covered. (96.81%)

25 existing lines in 8 files now uncovered.

11256 of 12757 relevant lines covered (88.23%)

7348.31 hits per line

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

88.06
/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-2024 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 <cstring>
37
#include <sycl/sycl.hpp> /* SYCL headers   */
38
#include <utility>
39
#include <vector>
40

41
using namespace sycl;
42

43
namespace
44
{
45

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

49
using namespace dpctl::syclinterface;
50

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

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

82
} /* end of anonymous namespace */
83

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

428
namespace
429
{
430

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

446
} // end of anonymous namespace
447

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

588
__dpctl_give DPCTLDeviceVectorRef
589
DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef,
590
                                    size_t count)
591
{
40✔
592
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
40✔
593
    vecTy *Devices = nullptr;
40✔
594
    if (DRef) {
40✔
595
        if (count == 0) {
39✔
596
            error_handler("Cannot create sub-devices with zero compute units",
8✔
597
                          __FILE__, __func__, __LINE__);
8✔
598
            return nullptr;
8✔
599
        }
8✔
600
        auto D = unwrap<device>(DRef);
31✔
601
        try {
31✔
602
            auto subDevices = D->create_sub_devices<
31✔
603
                info::partition_property::partition_equally>(count);
31✔
604
            Devices = new vecTy();
31✔
605
            for (const auto &sd : subDevices) {
62✔
606
                Devices->emplace_back(wrap<device>(new device(sd)));
62✔
607
            }
62✔
608
        } catch (std::exception const &e) {
31✔
609
            delete Devices;
×
610
            error_handler(e, __FILE__, __func__, __LINE__);
×
611
            return nullptr;
×
612
        }
×
613
    }
31✔
614
    return wrap<vecTy>(Devices);
32✔
615
}
40✔
616

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

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

682
size_t DPCTLDevice_Hash(__dpctl_keep const DPCTLSyclDeviceRef DRef)
683
{
47,887✔
684
    if (DRef) {
47,887✔
685
        auto D = unwrap<device>(DRef);
47,886✔
686
        std::hash<device> hash_fn;
47,886✔
687
        return hash_fn(*D);
47,886✔
688
    }
47,886✔
689
    else {
1✔
690
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
691
        return 0;
1✔
692
    }
1✔
693
}
47,887✔
694

695
size_t DPCTLDevice_GetProfilingTimerResolution(
696
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
697
{
24✔
698
    if (DRef) {
24✔
699
        auto D = unwrap<device>(DRef);
23✔
700
        return D->get_info<info::device::profiling_timer_resolution>();
23✔
701
    }
23✔
702
    else {
1✔
703
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
704
        return 0;
1✔
705
    }
1✔
706
}
24✔
707

708
uint32_t DPCTLDevice_GetGlobalMemCacheLineSize(
709
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
710
{
24✔
711
    if (DRef) {
24✔
712
        auto D = unwrap<device>(DRef);
23✔
713
        return D->get_info<info::device::global_mem_cache_line_size>();
23✔
714
    }
23✔
715
    else {
1✔
716
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
717
        return 0;
1✔
718
    }
1✔
719
}
24✔
720

721
uint32_t
722
DPCTLDevice_GetMaxClockFrequency(__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::max_clock_frequency>();
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
uint64_t
735
DPCTLDevice_GetMaxMemAllocSize(__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::max_mem_alloc_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
uint64_t
748
DPCTLDevice_GetGlobalMemCacheSize(__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::global_mem_cache_size>();
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
DPCTLGlobalMemCacheType
761
DPCTLDevice_GetGlobalMemCacheType(__dpctl_keep const DPCTLSyclDeviceRef DRef)
762
{
24✔
763
    if (DRef) {
24✔
764
        auto D = unwrap<device>(DRef);
23✔
765
        auto mem_type = D->get_info<info::device::global_mem_cache_type>();
23✔
766
        switch (mem_type) {
23!
767
        case info::global_mem_cache_type::none:
×
768
            return DPCTL_MEM_CACHE_TYPE_NONE;
×
769
        case info::global_mem_cache_type::read_only:
×
770
            return DPCTL_MEM_CACHE_TYPE_READ_ONLY;
×
771
        case info::global_mem_cache_type::read_write:
23!
772
            return DPCTL_MEM_CACHE_TYPE_READ_WRITE;
23✔
773
        }
23✔
774
        // If execution reaches here unrecognized mem_type was returned. Check
775
        // values in the enumeration `info::global_mem_cache_type` in SYCL specs
776
        assert(false);
×
777
        return DPCTL_MEM_CACHE_TYPE_INDETERMINATE;
×
778
    }
×
779
    else {
1✔
780
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
781
        return DPCTL_MEM_CACHE_TYPE_INDETERMINATE;
1✔
782
    }
1✔
783
}
24✔
784

785
__dpctl_keep size_t *
786
DPCTLDevice_GetSubGroupSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef,
787
                             size_t *res_len)
788
{
24✔
789
    size_t *sizes = nullptr;
24✔
790
    std::vector<size_t> sg_sizes;
24✔
791
    *res_len = 0;
24✔
792
    auto D = unwrap<device>(DRef);
24✔
793
    if (D) {
24✔
794
        try {
23✔
795
            sg_sizes = D->get_info<info::device::sub_group_sizes>();
23✔
796
            *res_len = sg_sizes.size();
23✔
797
        } catch (std::exception const &e) {
23✔
798
            error_handler(e, __FILE__, __func__, __LINE__);
×
799
        }
×
800
        try {
23✔
801
            sizes = new size_t[sg_sizes.size()];
23✔
802
        } catch (std::exception const &e) {
23✔
803
            error_handler(e, __FILE__, __func__, __LINE__);
×
804
        }
×
805
        for (auto i = 0ul; (sizes != nullptr) && i < sg_sizes.size(); ++i) {
138!
806
            sizes[i] = sg_sizes[i];
115✔
807
        }
115✔
808
    }
23✔
809
    return sizes;
24✔
810
}
24✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc