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

IntelPython / dpctl / 9197780664

22 May 2024 08:12PM UTC coverage: 87.943% (-0.03%) from 87.971%
9197780664

Pull #1691

github

web-flow
Merge 09b3c8061 into 183bfd77d
Pull Request #1691: Add support for aspect::emulated

3254 of 3746 branches covered (86.87%)

Branch coverage included in aggregate %.

9 of 12 new or added lines in 2 files covered. (75.0%)

2 existing lines in 2 files now uncovered.

11035 of 12502 relevant lines covered (88.27%)

8259.87 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
{
38✔
38
    std::stringstream ss;
38✔
39
    switch (devTy) {
38✔
40
    case info::device_type::cpu:
26✔
41
        ss << "cpu";
26✔
42
        break;
26✔
43
    case info::device_type::gpu:
1✔
44
        ss << "gpu";
1✔
45
        break;
1✔
46
    case info::device_type::accelerator:
9✔
47
        ss << "accelerator";
9✔
48
        break;
9✔
49
    case info::device_type::custom:
1✔
50
        ss << "custom";
1✔
51
        break;
1✔
52
    default:
1✔
53
        ss << "unknown";
1✔
54
    }
38✔
55
    return ss.str();
38✔
56
}
38✔
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
{
3,785✔
104
    switch (B) {
3,785✔
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:
3,782✔
110
        return DPCTLSyclBackendType::DPCTL_OPENCL;
3,782✔
111
    default:
1✔
112
        return DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
1✔
113
    }
3,785✔
114
}
3,785✔
115

116
info::device_type DPCTL_DPCTLDeviceTypeToSyclDeviceType(DPCTLSyclDeviceType DTy)
117
{
12✔
118
    switch (DTy) {
12✔
119
    case DPCTLSyclDeviceType::DPCTL_ACCELERATOR:
3✔
120
        return info::device_type::accelerator;
3✔
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
    }
12✔
134
}
12✔
135

136
DPCTLSyclDeviceType DPCTL_SyclDeviceTypeToDPCTLDeviceType(info::device_type D)
137
{
3,768✔
138
    switch (D) {
3,768✔
139
    case info::device_type::accelerator:
2,314✔
140
        return DPCTLSyclDeviceType::DPCTL_ACCELERATOR;
2,314✔
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,450✔
146
        return DPCTLSyclDeviceType::DPCTL_CPU;
1,450✔
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
    }
3,768✔
154
}
3,768✔
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;
×
NEW
217
    case aspect::emulated:
×
NEW
218
        ss << "emulated";
×
NEW
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
{
129✔
231
    aspect aspectTy;
129✔
232
    if (aspectTyStr == "cpu") {
129✔
233
        aspectTy = aspect::cpu;
1✔
234
    }
1✔
235
    else if (aspectTyStr == "gpu") {
128✔
236
        aspectTy = aspect::gpu;
1✔
237
    }
1✔
238
    else if (aspectTyStr == "accelerator") {
127✔
239
        aspectTy = aspect::accelerator;
1✔
240
    }
1✔
241
    else if (aspectTyStr == "custom") {
126✔
242
        aspectTy = aspect::custom;
1✔
243
    }
1✔
244
    else if (aspectTyStr == "fp16") {
125✔
245
        aspectTy = aspect::fp16;
21✔
246
    }
21✔
247
    else if (aspectTyStr == "fp64") {
104✔
248
        aspectTy = aspect::fp64;
22✔
249
    }
22✔
250
    else if (aspectTyStr == "atomic64") {
82✔
251
        aspectTy = aspect::atomic64;
1✔
252
    }
1✔
253
    else if (aspectTyStr == "image") {
81✔
254
        aspectTy = aspect::image;
70✔
255
    }
70✔
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✔
UNCOV
289
    else {
×
290
        // \todo handle the error
291
        throw std::runtime_error("Unsupported aspect type");
×
292
    }
×
293
    return aspectTy;
129✔
294
}
129✔
295

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

342
DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(aspect Aspect)
343
{
129✔
344
    switch (Aspect) {
129✔
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:
21✔
354
        return DPCTLSyclAspectType::fp16;
21✔
355
    case aspect::fp64:
22✔
356
        return DPCTLSyclAspectType::fp64;
22✔
357
    case aspect::atomic64:
1✔
358
        return DPCTLSyclAspectType::atomic64;
1✔
359
    case aspect::image:
70✔
360
        return DPCTLSyclAspectType::image;
70✔
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
    }
129✔
386
}
129✔
387

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

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

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

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

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

460
    switch (be) {
31✔
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:
31!
468
        ss << "opencl";
31✔
469
        break;
31✔
470
    default:
×
471
        ss << "unknown";
×
472
    };
31✔
473

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

479
    return ss.str();
31✔
480
}
31✔
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

© 2026 Coveralls, Inc