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

IntelPython / dpctl / 10136955542

29 Jul 2024 02:16AM UTC coverage: 87.609% (-0.4%) from 87.968%
10136955542

push

github

web-flow
Merge pull request #1762 from IntelPython/fix-crash-testing-with-sycl-nightly-runtime

Fix crash testing with sycl nightly runtime

3326 of 3844 branches covered (86.52%)

Branch coverage included in aggregate %.

22 of 35 new or added lines in 1 file covered. (62.86%)

31 existing lines in 2 files now uncovered.

11260 of 12805 relevant lines covered (87.93%)

7362.51 hits per line

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

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

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

82
} /* end of anonymous namespace */
83

84
__dpctl_give DPCTLSyclDeviceRef
85
DPCTLDevice_Copy(__dpctl_keep const DPCTLSyclDeviceRef DRef)
86
{
153,686✔
87
    auto Device = unwrap<device>(DRef);
153,686✔
88
    if (!Device) {
153,686✔
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,685✔
94
        auto CopiedDevice = new device(*Device);
153,685✔
95
        return wrap<device>(CopiedDevice);
153,685✔
96
    } catch (std::exception const &e) {
153,685✔
97
        error_handler(e, __FILE__, __func__, __LINE__);
×
98
        return nullptr;
×
99
    }
×
100
}
153,685✔
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,967✔
116
    auto Selector = unwrap<dpctl_device_selector>(DSRef);
19,967✔
117
    if (!Selector) {
19,967✔
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,952✔
124
        auto Device = new_device_from_selector(Selector);
19,952✔
125
        return wrap<device>(Device);
19,952✔
126
    } catch (std::exception const &e) {
19,952✔
127
        error_handler(e, __FILE__, __func__, __LINE__);
3,088✔
128
        return nullptr;
3,088✔
129
    }
3,088✔
130
}
19,952✔
131

132
void DPCTLDevice_Delete(__dpctl_take DPCTLSyclDeviceRef DRef)
133
{
263,689✔
134
    delete unwrap<device>(DRef);
263,689✔
135
}
263,689✔
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
{
64✔
183
    DPCTLSyclBackendType BTy = DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
64✔
184
    auto D = unwrap<device>(DRef);
64✔
185
    if (D) {
64!
186
        BTy = DPCTL_SyclBackendToDPCTLBackendType(
64✔
187
            D->get_platform().get_backend());
64✔
188
    }
64✔
189
    return BTy;
64✔
190
}
64✔
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,902✔
267
    return DPCTLDevice__GetMaxWorkItemSizes<3>(DRef);
260,902✔
268
}
260,902✔
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,902✔
318
    const char *cstr_name = nullptr;
260,902✔
319
    auto D = unwrap<device>(DRef);
260,902✔
320
    if (D) {
260,902✔
321
        try {
260,901✔
322
            auto name = D->get_info<info::device::name>();
260,901✔
323
            cstr_name = dpctl::helper::cstring_from_string(name);
260,901✔
324
        } catch (std::exception const &e) {
260,901✔
325
            error_handler(e, __FILE__, __func__, __LINE__);
×
326
        }
×
327
    }
260,901✔
328
    return cstr_name;
260,902✔
329
}
260,902✔
330

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

347
__dpctl_give const char *
348
DPCTLDevice_GetDriverVersion(__dpctl_keep const DPCTLSyclDeviceRef DRef)
349
{
260,902✔
350
    const char *cstr_driver = nullptr;
260,902✔
351
    auto D = unwrap<device>(DRef);
260,902✔
352
    if (D) {
260,902✔
353
        try {
260,901✔
354
            auto driver = D->get_info<info::device::driver_version>();
260,901✔
355
            cstr_driver = dpctl::helper::cstring_from_string(driver);
260,901✔
356
        } catch (std::exception const &e) {
260,901✔
357
            error_handler(e, __FILE__, __func__, __LINE__);
×
358
        }
×
359
    }
260,901✔
360
    return cstr_driver;
260,902✔
361
}
260,902✔
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
{
368,142✔
377
    bool hasAspect = false;
368,142✔
378
    auto D = unwrap<device>(DRef);
368,142✔
379
    if (D) {
368,142✔
380
        try {
368,141✔
381
            hasAspect = D->has(DPCTL_DPCTLAspectTypeToSyclAspect(AT));
368,141✔
382
        } catch (std::exception const &e) {
368,141✔
383
            error_handler(e, __FILE__, __func__, __LINE__);
×
384
        }
×
385
    }
368,141✔
386
    return hasAspect;
368,142✔
387
}
368,142✔
388

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

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

428
namespace
429
{
430

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

446
} // end of anonymous namespace
447

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

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

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

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

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

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

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

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

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

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

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

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

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

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

541
__dpctl_give DPCTLSyclDeviceRef
542
DPCTLDevice_GetParentDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef)
543
{
1,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
        const auto &supported_properties =
31✔
602
            D->get_info<info::device::partition_properties>();
31✔
603
        const auto &beg_it = supported_properties.begin();
31✔
604
        const auto &end_it = supported_properties.end();
31✔
605
        if (std::find(beg_it, end_it,
31!
606
                      info::partition_property::partition_equally) == end_it)
31✔
NEW
607
        {
×
608
            // device does not support partition equally
NEW
609
            return nullptr;
×
NEW
610
        }
×
611
        try {
31✔
612
            auto subDevices = D->create_sub_devices<
31✔
613
                info::partition_property::partition_equally>(count);
31✔
614
            Devices = new vecTy();
31✔
615
            for (const auto &sd : subDevices) {
62✔
616
                Devices->emplace_back(wrap<device>(new device(sd)));
62✔
617
            }
62✔
618
        } catch (std::exception const &e) {
31✔
619
            delete Devices;
×
620
            error_handler(e, __FILE__, __func__, __LINE__);
×
621
            return nullptr;
×
622
        }
×
623
    }
31✔
624
    return wrap<vecTy>(Devices);
32✔
625
}
40✔
626

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

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

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

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

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

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

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

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

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

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