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

IntelPython / dpctl / 6611431380

23 Oct 2023 09:35AM UTC coverage: 85.655% (-0.05%) from 85.701%
6611431380

Pull #1452

github

web-flow
Merge 4ac53fd07 into b437c47c0
Pull Request #1452: Use partition_type_property descriptor in DPCTLDevice_GetParentDevice

2446 of 2895 branches covered (0.0%)

Branch coverage included in aggregate %.

9 of 12 new or added lines in 1 file covered. (75.0%)

4 existing lines in 2 files now uncovered.

8696 of 10113 relevant lines covered (85.99%)

8097.99 hits per line

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

87.93
/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-2022 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 <CL/sycl.hpp> /* SYCL headers   */
36
#include <algorithm>
37
#include <cstring>
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
{
32,042✔
53
    return new device(
32,042✔
54
        [=](const device &d) -> int { return sel->operator()(d); });
64,084✔
55
}
32,042✔
56

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

82
} /* end of anonymous namespace */
83

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

389
#define declmethod(FUNC, NAME, TYPE)                                           \
390
    TYPE DPCTLDevice_##FUNC(__dpctl_keep const DPCTLSyclDeviceRef DRef)        \
391
    {                                                                          \
203✔
392
        TYPE result = 0;                                                       \
203✔
393
        auto D = unwrap<device>(DRef);                                         \
203✔
394
        if (D) {                                                               \
203✔
395
            try {                                                              \
196✔
396
                result = D->get_info<info::device::NAME>();                    \
196✔
397
            } catch (std::exception const &e) {                                \
196✔
398
                error_handler(e, __FILE__, __func__, __LINE__);                \
×
399
            }                                                                  \
×
400
        }                                                                      \
196✔
401
        return result;                                                         \
203✔
402
    }
203✔
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
{
29✔
415
    bool SubGroupProgress = false;
29✔
416
    auto D = unwrap<device>(DRef);
29✔
417
    if (D) {
29✔
418
        try {
28✔
419
            SubGroupProgress = D->get_info<
28✔
420
                info::device::sub_group_independent_forward_progress>();
28✔
421
        } catch (std::exception const &e) {
28✔
422
            error_handler(e, __FILE__, __func__, __LINE__);
4✔
423
        }
4✔
424
    }
28✔
425
    return SubGroupProgress;
29✔
426
}
29✔
427

428
namespace
429
{
430

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

446
} // end of anonymous namespace
447

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

734
DPCTLGlobalMemCacheType
735
DPCTLDevice_GetGlobalMemCacheType(__dpctl_keep const DPCTLSyclDeviceRef DRef)
736
{
29✔
737
    if (DRef) {
29✔
738
        auto D = unwrap<device>(DRef);
28✔
739
        auto mem_type = D->get_info<info::device::global_mem_cache_type>();
28✔
740
        switch (mem_type) {
28!
741
        case info::global_mem_cache_type::none:
×
742
            return DPCTL_MEM_CACHE_TYPE_NONE;
×
743
        case info::global_mem_cache_type::read_only:
×
744
            return DPCTL_MEM_CACHE_TYPE_READ_ONLY;
×
745
        case info::global_mem_cache_type::read_write:
28!
746
            return DPCTL_MEM_CACHE_TYPE_READ_WRITE;
28✔
747
        }
28✔
748
        // If execution reaches here unrecognized mem_type was returned. Check
749
        // values in the enumeration `info::global_mem_cache_type` in SYCL specs
750
        assert(false);
×
751
        return DPCTL_MEM_CACHE_TYPE_INDETERMINATE;
×
752
    }
×
753
    else {
1✔
754
        error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
1✔
755
        return DPCTL_MEM_CACHE_TYPE_INDETERMINATE;
1✔
756
    }
1✔
757
}
29✔
758

759
__dpctl_keep size_t *
760
DPCTLDevice_GetSubGroupSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef,
761
                             size_t *res_len)
762
{
29✔
763
    size_t *sizes = nullptr;
29✔
764
    std::vector<size_t> sg_sizes;
29✔
765
    *res_len = 0;
29✔
766
    auto D = unwrap<device>(DRef);
29✔
767
    if (D) {
29✔
768
        try {
28✔
769
            sg_sizes = D->get_info<info::device::sub_group_sizes>();
28✔
770
            *res_len = sg_sizes.size();
28✔
771
        } catch (std::exception const &e) {
28✔
772
            error_handler(e, __FILE__, __func__, __LINE__);
×
773
        }
×
774
        try {
28✔
775
            sizes = new size_t[sg_sizes.size()];
28✔
776
        } catch (std::exception const &e) {
28✔
777
            error_handler(e, __FILE__, __func__, __LINE__);
×
778
        }
×
779
        for (auto i = 0ul; (sizes != nullptr) && i < sg_sizes.size(); ++i) {
168!
780
            sizes[i] = sg_sizes[i];
140✔
781
        }
140✔
782
    }
28✔
783
    return sizes;
29✔
784
}
29✔
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