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

IntelPython / dpctl / 9974566682

17 Jul 2024 12:52PM UTC coverage: 87.967%. Remained the same
9974566682

Pull #1737

github

web-flow
Merge b23013880 into 6d34a6beb
Pull Request #1737: Replace "-c intel" in docs and readme file

3328 of 3822 branches covered (87.07%)

Branch coverage included in aggregate %.

11257 of 12758 relevant lines covered (88.23%)

7349.42 hits per line

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

78.0
/libsyclinterface/helper/source/dpctl_utils_helper.cpp
1
//===- dpctl_utils_helper.cpp - Implementation of enum to string helpers   ===//
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 helper functions defined in dpctl_utils_helper.h.
23
///
24
//===----------------------------------------------------------------------===//
25

26
#include "dpctl_utils_helper.h"
27
#include "Config/dpctl_config.h"
28
#include <sstream>
29
#include <string>
30

31
using namespace sycl;
32

33
/*!
34
 * Transforms enum info::device_type to string.
35
 */
36
std::string DPCTL_DeviceTypeToStr(info::device_type devTy)
37
{
32✔
38
    std::stringstream ss;
32✔
39
    switch (devTy) {
32✔
40
    case info::device_type::cpu:
28✔
41
        ss << "cpu";
28✔
42
        break;
28✔
43
    case info::device_type::gpu:
1✔
44
        ss << "gpu";
1✔
45
        break;
1✔
46
    case info::device_type::accelerator:
1✔
47
        ss << "accelerator";
1✔
48
        break;
1✔
49
    case info::device_type::custom:
1✔
50
        ss << "custom";
1✔
51
        break;
1✔
52
    default:
1✔
53
        ss << "unknown";
1✔
54
    }
32✔
55
    return ss.str();
32✔
56
}
32✔
57

58
/*!
59
 * Transforms string to enum info::device_type.
60
 */
61
info::device_type DPCTL_StrToDeviceType(const std::string &devTyStr)
62
{
5✔
63
    info::device_type devTy;
5✔
64
    if (devTyStr == "cpu") {
5✔
65
        devTy = info::device_type::cpu;
1✔
66
    }
1✔
67
    else if (devTyStr == "gpu") {
4✔
68
        devTy = info::device_type::gpu;
1✔
69
    }
1✔
70
    else if (devTyStr == "accelerator") {
3✔
71
        devTy = info::device_type::accelerator;
1✔
72
    }
1✔
73
    else if (devTyStr == "custom") {
2✔
74
        devTy = info::device_type::custom;
1✔
75
    }
1✔
76
    else if (devTyStr == "host") {
1!
77
        devTy = info::device_type::host;
×
78
    }
×
79
    else {
1✔
80
        // \todo handle the error
81
        throw std::runtime_error("Unknown device type.");
1✔
82
    }
1✔
83
    return devTy;
4✔
84
}
5✔
85

86
backend DPCTL_DPCTLBackendTypeToSyclBackend(DPCTLSyclBackendType BeTy)
87
{
8✔
88
    switch (BeTy) {
8✔
89
    case DPCTLSyclBackendType::DPCTL_CUDA:
2✔
90
        return backend::ext_oneapi_cuda;
2✔
91
    case DPCTLSyclBackendType::DPCTL_LEVEL_ZERO:
2✔
92
        return backend::ext_oneapi_level_zero;
2✔
93
    case DPCTLSyclBackendType::DPCTL_OPENCL:
2✔
94
        return backend::opencl;
2✔
95
    case DPCTLSyclBackendType::DPCTL_ALL_BACKENDS:
1✔
96
        return backend::all;
1✔
97
    default:
1✔
98
        throw std::runtime_error("Unsupported backend type");
1✔
99
    }
8✔
100
}
8✔
101

102
DPCTLSyclBackendType DPCTL_SyclBackendToDPCTLBackendType(backend B)
103
{
1,540✔
104
    switch (B) {
1,540✔
105
    case backend::ext_oneapi_cuda:
1✔
106
        return DPCTLSyclBackendType::DPCTL_CUDA;
1✔
107
    case backend::ext_oneapi_level_zero:
1✔
108
        return DPCTLSyclBackendType::DPCTL_LEVEL_ZERO;
1✔
109
    case backend::opencl:
1,537✔
110
        return DPCTLSyclBackendType::DPCTL_OPENCL;
1,537✔
111
    default:
1✔
112
        return DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
1✔
113
    }
1,540✔
114
}
1,540✔
115

116
info::device_type DPCTL_DPCTLDeviceTypeToSyclDeviceType(DPCTLSyclDeviceType DTy)
117
{
11✔
118
    switch (DTy) {
11✔
119
    case DPCTLSyclDeviceType::DPCTL_ACCELERATOR:
2✔
120
        return info::device_type::accelerator;
2✔
121
    case DPCTLSyclDeviceType::DPCTL_ALL:
2✔
122
        return info::device_type::all;
2✔
123
    case DPCTLSyclDeviceType::DPCTL_AUTOMATIC:
1✔
124
        return info::device_type::automatic;
1✔
125
    case DPCTLSyclDeviceType::DPCTL_CPU:
3✔
126
        return info::device_type::cpu;
3✔
127
    case DPCTLSyclDeviceType::DPCTL_CUSTOM:
1✔
128
        return info::device_type::custom;
1✔
129
    case DPCTLSyclDeviceType::DPCTL_GPU:
2✔
130
        return info::device_type::gpu;
2✔
131
    default:
×
132
        throw std::runtime_error("Unsupported device type");
×
133
    }
11✔
134
}
11✔
135

136
DPCTLSyclDeviceType DPCTL_SyclDeviceTypeToDPCTLDeviceType(info::device_type D)
137
{
1,526✔
138
    switch (D) {
1,526✔
139
    case info::device_type::accelerator:
1✔
140
        return DPCTLSyclDeviceType::DPCTL_ACCELERATOR;
1✔
141
    case info::device_type::all:
1✔
142
        return DPCTLSyclDeviceType::DPCTL_ALL;
1✔
143
    case info::device_type::automatic:
1✔
144
        return DPCTLSyclDeviceType::DPCTL_AUTOMATIC;
1✔
145
    case info::device_type::cpu:
1,521✔
146
        return DPCTLSyclDeviceType::DPCTL_CPU;
1,521✔
147
    case info::device_type::custom:
1✔
148
        return DPCTLSyclDeviceType::DPCTL_CUSTOM;
1✔
149
    case info::device_type::gpu:
1✔
150
        return DPCTLSyclDeviceType::DPCTL_GPU;
1✔
151
    default:
×
152
        return DPCTLSyclDeviceType::DPCTL_UNKNOWN_DEVICE;
×
153
    }
1,526✔
154
}
1,526✔
155

156
/*!
157
 * Transforms sycl::aspect to string.
158
 */
159
std::string DPCTL_AspectToStr(aspect aspectTy)
160
{
×
161
    std::stringstream ss;
×
162
    switch (aspectTy) {
×
163
    case aspect::cpu:
×
164
        ss << "cpu";
×
165
        break;
×
166
    case aspect::gpu:
×
167
        ss << "gpu";
×
168
        break;
×
169
    case aspect::accelerator:
×
170
        ss << "accelerator";
×
171
        break;
×
172
    case aspect::custom:
×
173
        ss << "custom";
×
174
        break;
×
175
    case aspect::fp16:
×
176
        ss << "fp16";
×
177
        break;
×
178
    case aspect::fp64:
×
179
        ss << "fp64";
×
180
        break;
×
181
    case aspect::atomic64:
×
182
        ss << "atomic64";
×
183
        break;
×
184
    case aspect::image:
×
185
        ss << "image";
×
186
        break;
×
187
    case aspect::online_compiler:
×
188
        ss << "online_compiler";
×
189
        break;
×
190
    case aspect::online_linker:
×
191
        ss << "online_linker";
×
192
        break;
×
193
    case aspect::queue_profiling:
×
194
        ss << "queue_profiling";
×
195
        break;
×
196
    case aspect::usm_device_allocations:
×
197
        ss << "usm_device_allocations";
×
198
        break;
×
199
    case aspect::usm_host_allocations:
×
200
        ss << "usm_host_allocations";
×
201
        break;
×
202
    case aspect::usm_shared_allocations:
×
203
        ss << "usm_shared_allocations";
×
204
        break;
×
205
    case aspect::usm_system_allocations:
×
206
        ss << "usm_system_allocations";
×
207
        break;
×
208
    case aspect::usm_atomic_host_allocations:
×
209
        ss << "usm_atomic_host_allocations";
×
210
        break;
×
211
    case aspect::usm_atomic_shared_allocations:
×
212
        ss << "usm_atomic_shared_allocations";
×
213
        break;
×
214
    case aspect::host_debuggable:
×
215
        ss << "host_debuggable";
×
216
        break;
×
217
    case aspect::emulated:
×
218
        ss << "emulated";
×
219
        break;
×
220
    default:
×
221
        throw std::runtime_error("Unsupported aspect type");
×
222
    }
×
223
    return ss.str();
×
224
}
×
225

226
/*!
227
 * Transforms string to sycl::aspect.
228
 */
229
aspect DPCTL_StrToAspectType(const std::string &aspectTyStr)
230
{
107✔
231
    aspect aspectTy;
107✔
232
    if (aspectTyStr == "cpu") {
107✔
233
        aspectTy = aspect::cpu;
1✔
234
    }
1✔
235
    else if (aspectTyStr == "gpu") {
106✔
236
        aspectTy = aspect::gpu;
1✔
237
    }
1✔
238
    else if (aspectTyStr == "accelerator") {
105✔
239
        aspectTy = aspect::accelerator;
1✔
240
    }
1✔
241
    else if (aspectTyStr == "custom") {
104✔
242
        aspectTy = aspect::custom;
1✔
243
    }
1✔
244
    else if (aspectTyStr == "fp16") {
103✔
245
        aspectTy = aspect::fp16;
17✔
246
    }
17✔
247
    else if (aspectTyStr == "fp64") {
86✔
248
        aspectTy = aspect::fp64;
18✔
249
    }
18✔
250
    else if (aspectTyStr == "atomic64") {
68✔
251
        aspectTy = aspect::atomic64;
1✔
252
    }
1✔
253
    else if (aspectTyStr == "image") {
67✔
254
        aspectTy = aspect::image;
56✔
255
    }
56✔
256
    else if (aspectTyStr == "online_compiler") {
11✔
257
        aspectTy = aspect::online_compiler;
1✔
258
    }
1✔
259
    else if (aspectTyStr == "online_linker") {
10✔
260
        aspectTy = aspect::online_linker;
1✔
261
    }
1✔
262
    else if (aspectTyStr == "queue_profiling") {
9✔
263
        aspectTy = aspect::queue_profiling;
1✔
264
    }
1✔
265
    else if (aspectTyStr == "usm_device_allocations") {
8✔
266
        aspectTy = aspect::usm_device_allocations;
1✔
267
    }
1✔
268
    else if (aspectTyStr == "usm_host_allocations") {
7✔
269
        aspectTy = aspect::usm_host_allocations;
1✔
270
    }
1✔
271
    else if (aspectTyStr == "usm_shared_allocations") {
6✔
272
        aspectTy = aspect::usm_shared_allocations;
1✔
273
    }
1✔
274
    else if (aspectTyStr == "usm_system_allocations") {
5✔
275
        aspectTy = aspect::usm_system_allocations;
1✔
276
    }
1✔
277
    else if (aspectTyStr == "usm_atomic_host_allocations") {
4✔
278
        aspectTy = aspect::usm_atomic_host_allocations;
1✔
279
    }
1✔
280
    else if (aspectTyStr == "usm_atomic_shared_allocations") {
3✔
281
        aspectTy = aspect::usm_atomic_shared_allocations;
1✔
282
    }
1✔
283
    else if (aspectTyStr == "host_debuggable") {
2✔
284
        aspectTy = aspect::host_debuggable;
1✔
285
    }
1✔
286
    else if (aspectTyStr == "emulated") {
1!
287
        aspectTy = aspect::emulated;
1✔
288
    }
1✔
289
    else {
×
290
        // \todo handle the error
291
        throw std::runtime_error("Unsupported aspect type");
×
292
    }
×
293
    return aspectTy;
107✔
294
}
107✔
295

296
aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy)
297
{
363,655✔
298
    switch (AspectTy) {
363,655✔
299
    case DPCTLSyclAspectType::cpu:
21✔
300
        return aspect::cpu;
21✔
301
    case DPCTLSyclAspectType::gpu:
19✔
302
        return aspect::gpu;
19✔
303
    case DPCTLSyclAspectType::accelerator:
18✔
304
        return aspect::accelerator;
18✔
305
    case DPCTLSyclAspectType::custom:
18✔
306
        return aspect::custom;
18✔
307
    case DPCTLSyclAspectType::fp16:
119,618✔
308
        return aspect::fp16;
119,618✔
309
    case DPCTLSyclAspectType::fp64:
243,662✔
310
        return aspect::fp64;
243,662✔
311
    case DPCTLSyclAspectType::atomic64:
19✔
312
        return aspect::atomic64;
19✔
313
    case DPCTLSyclAspectType::image:
73✔
314
        return aspect::image;
73✔
315
    case DPCTLSyclAspectType::online_compiler:
19✔
316
        return aspect::online_compiler;
19✔
317
    case DPCTLSyclAspectType::online_linker:
19✔
318
        return aspect::online_linker;
19✔
319
    case DPCTLSyclAspectType::queue_profiling:
19✔
320
        return aspect::queue_profiling;
19✔
321
    case DPCTLSyclAspectType::usm_device_allocations:
19✔
322
        return aspect::usm_device_allocations;
19✔
323
    case DPCTLSyclAspectType::usm_host_allocations:
19✔
324
        return aspect::usm_host_allocations;
19✔
325
    case DPCTLSyclAspectType::usm_shared_allocations:
19✔
326
        return aspect::usm_shared_allocations;
19✔
327
    case DPCTLSyclAspectType::usm_system_allocations:
19✔
328
        return aspect::usm_system_allocations;
19✔
329
    case DPCTLSyclAspectType::usm_atomic_host_allocations:
19✔
330
        return aspect::usm_atomic_host_allocations;
19✔
331
    case DPCTLSyclAspectType::usm_atomic_shared_allocations:
19✔
332
        return aspect::usm_atomic_shared_allocations;
19✔
333
    case DPCTLSyclAspectType::host_debuggable:
18✔
334
        return aspect::host_debuggable;
18✔
335
    case DPCTLSyclAspectType::emulated:
18✔
336
        return aspect::emulated;
18✔
337
    default:
×
338
        throw std::runtime_error("Unsupported aspect type");
×
339
    }
363,655✔
340
}
363,655✔
341

342
DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(aspect Aspect)
343
{
107✔
344
    switch (Aspect) {
107✔
345
    case aspect::cpu:
1✔
346
        return DPCTLSyclAspectType::cpu;
1✔
347
    case aspect::gpu:
1✔
348
        return DPCTLSyclAspectType::gpu;
1✔
349
    case aspect::accelerator:
1✔
350
        return DPCTLSyclAspectType::accelerator;
1✔
351
    case aspect::custom:
1✔
352
        return DPCTLSyclAspectType::custom;
1✔
353
    case aspect::fp16:
17✔
354
        return DPCTLSyclAspectType::fp16;
17✔
355
    case aspect::fp64:
18✔
356
        return DPCTLSyclAspectType::fp64;
18✔
357
    case aspect::atomic64:
1✔
358
        return DPCTLSyclAspectType::atomic64;
1✔
359
    case aspect::image:
56✔
360
        return DPCTLSyclAspectType::image;
56✔
361
    case aspect::online_compiler:
1✔
362
        return DPCTLSyclAspectType::online_compiler;
1✔
363
    case aspect::online_linker:
1✔
364
        return DPCTLSyclAspectType::online_linker;
1✔
365
    case aspect::queue_profiling:
1✔
366
        return DPCTLSyclAspectType::queue_profiling;
1✔
367
    case aspect::usm_device_allocations:
1✔
368
        return DPCTLSyclAspectType::usm_device_allocations;
1✔
369
    case aspect::usm_host_allocations:
1✔
370
        return DPCTLSyclAspectType::usm_host_allocations;
1✔
371
    case aspect::usm_shared_allocations:
1✔
372
        return DPCTLSyclAspectType::usm_shared_allocations;
1✔
373
    case aspect::usm_system_allocations:
1✔
374
        return DPCTLSyclAspectType::usm_system_allocations;
1✔
375
    case aspect::usm_atomic_host_allocations:
1✔
376
        return DPCTLSyclAspectType::usm_atomic_host_allocations;
1✔
377
    case aspect::usm_atomic_shared_allocations:
1✔
378
        return DPCTLSyclAspectType::usm_atomic_shared_allocations;
1✔
379
    case aspect::host_debuggable:
1✔
380
        return DPCTLSyclAspectType::host_debuggable;
1✔
381
    case aspect::emulated:
1✔
382
        return DPCTLSyclAspectType::emulated;
1✔
383
    default:
×
384
        throw std::runtime_error("Unsupported aspect type");
×
385
    }
107✔
386
}
107✔
387

388
info::partition_affinity_domain DPCTL_DPCTLPartitionAffinityDomainTypeToSycl(
389
    DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy)
390
{
154✔
391
    switch (PartitionAffinityDomainTy) {
154✔
392
    case DPCTLPartitionAffinityDomainType::not_applicable:
15✔
393
        return info::partition_affinity_domain::not_applicable;
15✔
394
    case DPCTLPartitionAffinityDomainType::numa:
23✔
395
        return info::partition_affinity_domain::numa;
23✔
396
    case DPCTLPartitionAffinityDomainType::L4_cache:
23✔
397
        return info::partition_affinity_domain::L4_cache;
23✔
398
    case DPCTLPartitionAffinityDomainType::L3_cache:
23✔
399
        return info::partition_affinity_domain::L3_cache;
23✔
400
    case DPCTLPartitionAffinityDomainType::L2_cache:
23✔
401
        return info::partition_affinity_domain::L2_cache;
23✔
402
    case DPCTLPartitionAffinityDomainType::L1_cache:
23✔
403
        return info::partition_affinity_domain::L1_cache;
23✔
404
    case DPCTLPartitionAffinityDomainType::next_partitionable:
24✔
405
        return info::partition_affinity_domain::next_partitionable;
24✔
406
    default:
×
407
        throw std::runtime_error("Unsupported partition_affinity_domain type");
×
408
    }
154✔
409
}
154✔
410

411
DPCTLPartitionAffinityDomainType DPCTL_SyclPartitionAffinityDomainToDPCTLType(
412
    sycl::info::partition_affinity_domain PartitionAffinityDomain)
413
{
56✔
414
    switch (PartitionAffinityDomain) {
56✔
415
    case info::partition_affinity_domain::not_applicable:
8✔
416
        return DPCTLPartitionAffinityDomainType::not_applicable;
8✔
417
    case info::partition_affinity_domain::numa:
8✔
418
        return DPCTLPartitionAffinityDomainType::numa;
8✔
419
    case info::partition_affinity_domain::L4_cache:
8✔
420
        return DPCTLPartitionAffinityDomainType::L4_cache;
8✔
421
    case info::partition_affinity_domain::L3_cache:
8✔
422
        return DPCTLPartitionAffinityDomainType::L3_cache;
8✔
423
    case info::partition_affinity_domain::L2_cache:
8✔
424
        return DPCTLPartitionAffinityDomainType::L2_cache;
8✔
425
    case info::partition_affinity_domain::L1_cache:
8✔
426
        return DPCTLPartitionAffinityDomainType::L1_cache;
8✔
427
    case info::partition_affinity_domain::next_partitionable:
8✔
428
        return DPCTLPartitionAffinityDomainType::next_partitionable;
8✔
429
    default:
×
430
        throw std::runtime_error("Unsupported partition_affinity_domain type");
×
431
    }
56✔
432
}
56✔
433

434
int64_t DPCTL_GetRelativeDeviceId(const device &Device)
435
{
35✔
436
    auto relid = -1;
35✔
437
    auto p = Device.get_platform();
35✔
438
    auto be = p.get_backend();
35✔
439
    auto dt = Device.get_info<sycl::info::device::device_type>();
35✔
440
    auto dev_vec = device::get_devices(dt);
35✔
441
    int64_t id = 0;
35✔
442
    for (const auto &d_i : dev_vec) {
35!
443
        if (Device == d_i) {
35!
444
            relid = id;
35✔
445
            break;
35✔
446
        }
35✔
447
        if (d_i.get_platform().get_backend() == be)
×
448
            ++id;
×
449
    }
×
450
    return relid;
35✔
451
}
35✔
452

453
std::string DPCTL_GetDeviceFilterString(const device &Device)
454
{
26✔
455
    std::stringstream ss;
26✔
456
    static constexpr const char *filter_string_separator = ":";
26✔
457

458
    auto be = Device.get_platform().get_backend();
26✔
459

460
    switch (be) {
26✔
461
    case backend::ext_oneapi_level_zero:
×
462
        ss << "level_zero";
×
463
        break;
×
464
    case backend::ext_oneapi_cuda:
×
465
        ss << "cuda";
×
466
        break;
×
467
    case backend::opencl:
26!
468
        ss << "opencl";
26✔
469
        break;
26✔
470
    default:
×
471
        ss << "unknown";
×
472
    };
26✔
473

474
    ss << filter_string_separator;
26✔
475
    ss << DPCTL_DeviceTypeToStr(Device.get_info<info::device::device_type>());
26✔
476
    ss << filter_string_separator;
26✔
477
    ss << DPCTL_GetRelativeDeviceId(Device);
26✔
478

479
    return ss.str();
26✔
480
}
26✔
481

482
DPCTLSyclEventStatusType
483
DPCTL_SyclEventStatusToDPCTLEventStatusType(info::event_command_status E)
484
{
6✔
485
    switch (E) {
6✔
486
    case info::event_command_status::submitted:
2✔
487
        return DPCTLSyclEventStatusType::DPCTL_SUBMITTED;
2✔
488
    case info::event_command_status::running:
1✔
489
        return DPCTLSyclEventStatusType::DPCTL_RUNNING;
1✔
490
    case info::event_command_status::complete:
3✔
491
        return DPCTLSyclEventStatusType::DPCTL_COMPLETE;
3✔
492
    default:
×
493
        return DPCTLSyclEventStatusType::DPCTL_UNKNOWN_STATUS;
×
494
    }
6✔
495
}
6✔
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