-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathdevice.cpp
1532 lines (1426 loc) · 64.4 KB
/
device.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//===--------- device.cpp - Level Zero Adapter ----------------------------===//
//
// Copyright (C) 2023 Intel Corporation
//
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "device.hpp"
#include "adapter.hpp"
#include "ur_level_zero.hpp"
#include "ur_util.hpp"
#include <algorithm>
#include <climits>
#include <optional>
UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(
ur_platform_handle_t Platform, ///< [in] handle of the platform instance
ur_device_type_t DeviceType, ///< [in] the type of the devices.
uint32_t NumEntries, ///< [in] the number of devices to be added to
///< phDevices. If phDevices in not NULL then
///< NumEntries should be greater than zero, otherwise
///< ::UR_RESULT_ERROR_INVALID_SIZE, will be returned.
ur_device_handle_t
*Devices, ///< [out][optional][range(0, NumEntries)] array of handle of
///< devices. If NumEntries is less than the number of devices
///< available, then platform shall only retrieve that number
///< of devices.
uint32_t *NumDevices ///< [out][optional] pointer to the number of devices.
///< pNumDevices will be updated with the total number
///< of devices available.
) {
auto Res = Platform->populateDeviceCacheIfNeeded();
if (Res != UR_RESULT_SUCCESS) {
return Res;
}
// Filter available devices based on input DeviceType.
std::vector<ur_device_handle_t> MatchedDevices;
std::shared_lock<ur_shared_mutex> Lock(Platform->URDevicesCacheMutex);
// We need to filter out composite devices when
// ZE_FLAT_DEVICE_HIERARCHY=COMBINED. We can know if we are in combined
// mode depending on the return value of zeDeviceGetRootDevice:
// - If COMPOSITE, L0 returns cards as devices. Since we filter out
// subdevices early, zeDeviceGetRootDevice must return nullptr, because we
// only query for root-devices and they don't have any device higher up in
// the hierarchy.
// - If FLAT, according to L0 spec, zeDeviceGetRootDevice always returns
// nullptr in this mode.
// - If COMBINED, L0 returns tiles as devices, and zeDeviceGetRootdevice
// returns the card containing a given tile.
bool isCombinedMode =
std::any_of(Platform->URDevicesCache.begin(),
Platform->URDevicesCache.end(), [](const auto &D) {
if (D->isSubDevice())
return false;
ze_device_handle_t RootDev = nullptr;
// Query Root Device for root-devices.
// We cannot use ZE2UR_CALL because under some circumstances
// this call may return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE,
// and ZE2UR_CALL will abort because it's not
// UR_RESULT_SUCCESS. Instead, we use ZE_CALL_NOCHECK and we
// check manually that the result is either
// ZE_RESULT_SUCCESS or ZE_RESULT_ERROR_UNSUPPORTED_FEATURE.
auto errc = ZE_CALL_NOCHECK(zeDeviceGetRootDevice,
(D->ZeDevice, &RootDev));
return (errc == ZE_RESULT_SUCCESS && RootDev != nullptr);
});
for (auto &D : Platform->URDevicesCache) {
// Only ever return root-devices from urDeviceGet, but the
// devices cache also keeps sub-devices.
if (D->isSubDevice())
continue;
bool Matched = false;
switch (DeviceType) {
case UR_DEVICE_TYPE_ALL:
Matched = true;
break;
case UR_DEVICE_TYPE_GPU:
case UR_DEVICE_TYPE_DEFAULT:
Matched = (D->ZeDeviceProperties->type == ZE_DEVICE_TYPE_GPU);
break;
case UR_DEVICE_TYPE_CPU:
Matched = (D->ZeDeviceProperties->type == ZE_DEVICE_TYPE_CPU);
break;
case UR_DEVICE_TYPE_FPGA:
Matched = D->ZeDeviceProperties->type == ZE_DEVICE_TYPE_FPGA;
break;
case UR_DEVICE_TYPE_MCA:
Matched = D->ZeDeviceProperties->type == ZE_DEVICE_TYPE_MCA;
break;
default:
Matched = false;
urPrint("Unknown device type");
break;
}
if (Matched) {
bool isComposite =
isCombinedMode && (D->ZeDeviceProperties->flags &
ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE) == 0;
if (!isComposite)
MatchedDevices.push_back(D.get());
}
}
uint32_t ZeDeviceCount = MatchedDevices.size();
auto N = (std::min)(ZeDeviceCount, NumEntries);
if (Devices)
std::copy_n(MatchedDevices.begin(), N, Devices);
if (NumDevices) {
if (*NumDevices == 0)
*NumDevices = ZeDeviceCount;
else
*NumDevices = N;
}
return UR_RESULT_SUCCESS;
}
uint64_t calculateGlobalMemSize(ur_device_handle_t Device) {
// Cache GlobalMemSize
Device->ZeGlobalMemSize.Compute =
[Device](struct ze_global_memsize &GlobalMemSize) {
for (const auto &ZeDeviceMemoryExtProperty :
Device->ZeDeviceMemoryProperties->second) {
GlobalMemSize.value += ZeDeviceMemoryExtProperty.physicalSize;
}
if (GlobalMemSize.value == 0) {
for (const auto &ZeDeviceMemoryProperty :
Device->ZeDeviceMemoryProperties->first) {
GlobalMemSize.value += ZeDeviceMemoryProperty.totalSize;
}
}
};
return Device->ZeGlobalMemSize.operator->()->value;
}
UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(
ur_device_handle_t Device, ///< [in] handle of the device instance
ur_device_info_t ParamName, ///< [in] type of the info to retrieve
size_t propSize, ///< [in] the number of bytes pointed to by ParamValue.
void *ParamValue, ///< [out][optional] array of bytes holding the info.
///< If propSize is not equal to or greater than the real
///< number of bytes needed to return the info then the
///< ::UR_RESULT_ERROR_INVALID_SIZE error is returned and
///< pDeviceInfo is not used.
size_t *pSize ///< [out][optional] pointer to the actual size in bytes of
///< the queried infoType.
) {
UrReturnHelper ReturnValue(propSize, ParamValue, pSize);
ze_device_handle_t ZeDevice = Device->ZeDevice;
switch ((int)ParamName) {
case UR_DEVICE_INFO_TYPE: {
switch (Device->ZeDeviceProperties->type) {
case ZE_DEVICE_TYPE_GPU:
return ReturnValue(UR_DEVICE_TYPE_GPU);
case ZE_DEVICE_TYPE_CPU:
return ReturnValue(UR_DEVICE_TYPE_CPU);
case ZE_DEVICE_TYPE_FPGA:
return ReturnValue(UR_DEVICE_TYPE_FPGA);
default:
urPrint("This device type is not supported\n");
return UR_RESULT_ERROR_INVALID_VALUE;
}
}
case UR_DEVICE_INFO_PARENT_DEVICE:
return ReturnValue(Device->RootDevice);
case UR_DEVICE_INFO_PLATFORM:
return ReturnValue(Device->Platform);
case UR_DEVICE_INFO_VENDOR_ID:
return ReturnValue(uint32_t{Device->ZeDeviceProperties->vendorId});
case UR_DEVICE_INFO_UUID: {
// Intel extension for device UUID. This returns the UUID as
// std::array<std::byte, 16>. For details about this extension,
// see sycl/doc/extensions/supported/sycl_ext_intel_device_info.md.
const auto &UUID = Device->ZeDeviceProperties->uuid.id;
return ReturnValue(UUID, sizeof(UUID));
}
case UR_DEVICE_INFO_ATOMIC_64:
return ReturnValue(
static_cast<uint32_t>(Device->ZeDeviceModuleProperties->flags &
ZE_DEVICE_MODULE_FLAG_INT64_ATOMICS));
case UR_DEVICE_INFO_EXTENSIONS: {
// Convention adopted from OpenCL:
// "Returns a space separated list of extension names (the extension
// names themselves do not contain any spaces) supported by the device."
//
// TODO: Use proper mechanism to get this information from Level Zero after
// it is added to Level Zero.
// Hardcoding the few we know are supported by the current hardware.
//
//
std::string SupportedExtensions;
// cl_khr_il_program - OpenCL 2.0 KHR extension for SPIR-V support. Core
// feature in >OpenCL 2.1
// cl_khr_subgroups - Extension adds support for implementation-controlled
// subgroups.
// cl_intel_subgroups - Extension adds subgroup features, defined by Intel.
// cl_intel_subgroups_short - Extension adds subgroup functions described in
// the cl_intel_subgroups extension to support 16-bit integer data types
// for performance.
// cl_intel_required_subgroup_size - Extension to allow programmers to
// optionally specify the required subgroup size for a kernel function.
// cl_khr_fp16 - Optional half floating-point support.
// cl_khr_fp64 - Support for double floating-point precision.
// cl_khr_int64_base_atomics, cl_khr_int64_extended_atomics - Optional
// extensions that implement atomic operations on 64-bit signed and
// unsigned integers to locations in __global and __local memory.
// cl_khr_3d_image_writes - Extension to enable writes to 3D image memory
// objects.
//
// Hardcoding some extensions we know are supported by all Level Zero
// devices.
SupportedExtensions += (ZE_SUPPORTED_EXTENSIONS);
if (Device->ZeDeviceModuleProperties->flags & ZE_DEVICE_MODULE_FLAG_FP16)
SupportedExtensions += ("cl_khr_fp16 ");
if (Device->ZeDeviceModuleProperties->flags & ZE_DEVICE_MODULE_FLAG_FP64)
SupportedExtensions += ("cl_khr_fp64 ");
if (Device->ZeDeviceModuleProperties->flags &
ZE_DEVICE_MODULE_FLAG_INT64_ATOMICS)
// int64AtomicsSupported indicates support for both.
SupportedExtensions +=
("cl_khr_int64_base_atomics cl_khr_int64_extended_atomics ");
if (Device->ZeDeviceImageProperties->maxImageDims3D > 0)
// Supports reading and writing of images.
SupportedExtensions += ("cl_khr_3d_image_writes ");
// L0 does not tell us if bfloat16 is supported.
// For now, assume ATS and PVC support it.
// TODO: change the way we detect bfloat16 support.
if ((Device->ZeDeviceProperties->deviceId & 0xfff) == 0x201 ||
(Device->ZeDeviceProperties->deviceId & 0xff0) == 0xbd0)
SupportedExtensions += ("cl_intel_bfloat16_conversions ");
// Return supported for the UR command-buffer experimental feature
SupportedExtensions += ("ur_exp_command_buffer ");
// Return supported for the UR multi-device compile experimental feature
SupportedExtensions += ("ur_exp_multi_device_compile ");
return ReturnValue(SupportedExtensions.c_str());
}
case UR_DEVICE_INFO_NAME:
return ReturnValue(Device->ZeDeviceProperties->name);
// zeModuleCreate allows using root device module for sub-devices:
// > The application must only use the module for the device, or its
// > sub-devices, which was provided during creation.
case UR_DEVICE_INFO_BUILD_ON_SUBDEVICE:
return ReturnValue(uint32_t{0});
case UR_DEVICE_INFO_COMPILER_AVAILABLE:
return ReturnValue(static_cast<uint32_t>(true));
case UR_DEVICE_INFO_LINKER_AVAILABLE:
return ReturnValue(static_cast<uint32_t>(true));
case UR_DEVICE_INFO_MAX_COMPUTE_UNITS: {
uint32_t MaxComputeUnits =
Device->ZeDeviceProperties->numEUsPerSubslice *
Device->ZeDeviceProperties->numSubslicesPerSlice *
Device->ZeDeviceProperties->numSlices;
bool RepresentsCSlice =
Device->QueueGroup[ur_device_handle_t_::queue_group_info_t::Compute]
.ZeIndex >= 0;
if (RepresentsCSlice)
MaxComputeUnits /= Device->RootDevice->SubDevices.size();
return ReturnValue(uint32_t{MaxComputeUnits});
}
case UR_DEVICE_INFO_MAX_WORK_ITEM_DIMENSIONS:
// Level Zero spec defines only three dimensions
return ReturnValue(uint32_t{3});
case UR_DEVICE_INFO_MAX_WORK_GROUP_SIZE:
return ReturnValue(
uint64_t{Device->ZeDeviceComputeProperties->maxTotalGroupSize});
case UR_DEVICE_INFO_MAX_WORK_ITEM_SIZES: {
struct {
size_t Arr[3];
} MaxGroupSize = {{Device->ZeDeviceComputeProperties->maxGroupSizeX,
Device->ZeDeviceComputeProperties->maxGroupSizeY,
Device->ZeDeviceComputeProperties->maxGroupSizeZ}};
return ReturnValue(MaxGroupSize);
}
case UR_DEVICE_INFO_MAX_WORK_GROUPS_3D: {
struct {
size_t Arr[3];
} MaxGroupCounts = {{Device->ZeDeviceComputeProperties->maxGroupCountX,
Device->ZeDeviceComputeProperties->maxGroupCountY,
Device->ZeDeviceComputeProperties->maxGroupCountZ}};
return ReturnValue(MaxGroupCounts);
}
case UR_DEVICE_INFO_MAX_CLOCK_FREQUENCY:
return ReturnValue(uint32_t{Device->ZeDeviceProperties->coreClockRate});
case UR_DEVICE_INFO_ADDRESS_BITS: {
// TODO: To confirm with spec.
return ReturnValue(uint32_t{64});
}
case UR_DEVICE_INFO_MAX_MEM_ALLOC_SIZE:
// if the user wishes to allocate large allocations on a system that usually
// does not allow that allocation size, then we return the max global mem
// size as the limit.
if (Device->useRelaxedAllocationLimits()) {
return ReturnValue(uint64_t{calculateGlobalMemSize(Device)});
} else {
return ReturnValue(uint64_t{Device->ZeDeviceProperties->maxMemAllocSize});
}
case UR_DEVICE_INFO_GLOBAL_MEM_SIZE: {
// Support to read physicalSize depends on kernel,
// so fallback into reading totalSize if physicalSize
// is not available.
uint64_t GlobalMemSize = calculateGlobalMemSize(Device);
return ReturnValue(uint64_t{GlobalMemSize});
}
case UR_DEVICE_INFO_LOCAL_MEM_SIZE:
return ReturnValue(
uint64_t{Device->ZeDeviceComputeProperties->maxSharedLocalMemory});
case UR_DEVICE_INFO_IMAGE_SUPPORTED:
return ReturnValue(static_cast<uint32_t>(
Device->ZeDeviceImageProperties->maxImageDims1D > 0));
case UR_DEVICE_INFO_HOST_UNIFIED_MEMORY:
return ReturnValue(
static_cast<uint32_t>((Device->ZeDeviceProperties->flags &
ZE_DEVICE_PROPERTY_FLAG_INTEGRATED) != 0));
case UR_DEVICE_INFO_AVAILABLE:
return ReturnValue(static_cast<uint32_t>(ZeDevice ? true : false));
case UR_DEVICE_INFO_VENDOR:
// TODO: Level-Zero does not return vendor's name at the moment
// only the ID.
return ReturnValue("Intel(R) Corporation");
case UR_DEVICE_INFO_DRIVER_VERSION:
case UR_DEVICE_INFO_BACKEND_RUNTIME_VERSION:
return ReturnValue(Device->Platform->ZeDriverVersion.c_str());
case UR_DEVICE_INFO_VERSION:
return ReturnValue(Device->Platform->ZeDriverApiVersion.c_str());
case UR_DEVICE_INFO_PARTITION_MAX_SUB_DEVICES: {
auto Res = Device->Platform->populateDeviceCacheIfNeeded();
if (Res != UR_RESULT_SUCCESS) {
return Res;
}
return ReturnValue((uint32_t)Device->SubDevices.size());
}
case UR_DEVICE_INFO_REFERENCE_COUNT:
return ReturnValue(uint32_t{Device->RefCount.load()});
case UR_DEVICE_INFO_SUPPORTED_PARTITIONS: {
// SYCL spec says: if this SYCL device cannot be partitioned into at least
// two sub devices then the returned vector must be empty.
auto Res = Device->Platform->populateDeviceCacheIfNeeded();
if (Res != UR_RESULT_SUCCESS) {
return Res;
}
uint32_t ZeSubDeviceCount = Device->SubDevices.size();
if (pSize && ZeSubDeviceCount < 2) {
*pSize = 0;
return UR_RESULT_SUCCESS;
}
bool PartitionedByCSlice = Device->SubDevices[0]->isCCS();
auto ReturnHelper = [&](auto... Partitions) {
struct {
ur_device_partition_t Arr[sizeof...(Partitions)];
} PartitionProperties = {{Partitions...}};
return ReturnValue(PartitionProperties);
};
if (ExposeCSliceInAffinityPartitioning) {
if (PartitionedByCSlice)
return ReturnHelper(UR_DEVICE_PARTITION_BY_CSLICE,
UR_DEVICE_PARTITION_BY_AFFINITY_DOMAIN);
else
return ReturnHelper(UR_DEVICE_PARTITION_BY_AFFINITY_DOMAIN);
} else {
return ReturnHelper(PartitionedByCSlice
? UR_DEVICE_PARTITION_BY_CSLICE
: UR_DEVICE_PARTITION_BY_AFFINITY_DOMAIN);
}
break;
}
case UR_DEVICE_INFO_PARTITION_AFFINITY_DOMAIN:
return ReturnValue(ur_device_affinity_domain_flag_t(
UR_DEVICE_AFFINITY_DOMAIN_FLAG_NUMA |
UR_DEVICE_AFFINITY_DOMAIN_FLAG_NEXT_PARTITIONABLE));
case UR_DEVICE_INFO_PARTITION_TYPE: {
// For root-device there is no partitioning to report.
if (Device->SubDeviceCreationProperty == std::nullopt ||
!Device->isSubDevice()) {
if (pSize)
*pSize = 0;
return UR_RESULT_SUCCESS;
}
if (Device->isCCS()) {
ur_device_partition_property_t cslice{};
cslice.type = UR_DEVICE_PARTITION_BY_CSLICE;
return ReturnValue(cslice);
}
return ReturnValue(*Device->SubDeviceCreationProperty);
}
// Everything under here is not supported yet
case UR_EXT_DEVICE_INFO_OPENCL_C_VERSION:
return ReturnValue("");
case UR_DEVICE_INFO_PREFERRED_INTEROP_USER_SYNC:
return ReturnValue(static_cast<uint32_t>(true));
case UR_DEVICE_INFO_PRINTF_BUFFER_SIZE:
return ReturnValue(
size_t{Device->ZeDeviceModuleProperties->printfBufferSize});
case UR_DEVICE_INFO_PROFILE:
return ReturnValue("FULL_PROFILE");
case UR_DEVICE_INFO_BUILT_IN_KERNELS:
// TODO: To find out correct value
return ReturnValue("");
case UR_DEVICE_INFO_QUEUE_PROPERTIES:
return ReturnValue(
ur_queue_flag_t(UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE |
UR_QUEUE_FLAG_PROFILING_ENABLE));
case UR_DEVICE_INFO_EXECUTION_CAPABILITIES:
return ReturnValue(ur_device_exec_capability_flag_t{
UR_DEVICE_EXEC_CAPABILITY_FLAG_NATIVE_KERNEL});
case UR_DEVICE_INFO_ENDIAN_LITTLE:
return ReturnValue(static_cast<uint32_t>(true));
case UR_DEVICE_INFO_ERROR_CORRECTION_SUPPORT:
return ReturnValue(static_cast<uint32_t>(Device->ZeDeviceProperties->flags &
ZE_DEVICE_PROPERTY_FLAG_ECC));
case UR_DEVICE_INFO_PROFILING_TIMER_RESOLUTION:
return ReturnValue(
static_cast<size_t>(Device->ZeDeviceProperties->timerResolution));
case UR_DEVICE_INFO_LOCAL_MEM_TYPE:
return ReturnValue(UR_DEVICE_LOCAL_MEM_TYPE_LOCAL);
case UR_DEVICE_INFO_MAX_CONSTANT_ARGS:
return ReturnValue(uint32_t{64});
case UR_DEVICE_INFO_MAX_CONSTANT_BUFFER_SIZE:
return ReturnValue(
uint64_t{Device->ZeDeviceImageProperties->maxImageBufferSize});
case UR_DEVICE_INFO_GLOBAL_MEM_CACHE_TYPE:
return ReturnValue(UR_DEVICE_MEM_CACHE_TYPE_READ_WRITE_CACHE);
case UR_DEVICE_INFO_GLOBAL_MEM_CACHELINE_SIZE:
return ReturnValue(
// TODO[1.0]: how to query cache line-size?
uint32_t{1});
case UR_DEVICE_INFO_GLOBAL_MEM_CACHE_SIZE:
return ReturnValue(uint64_t{Device->ZeDeviceCacheProperties->cacheSize});
case UR_DEVICE_INFO_IP_VERSION:
return ReturnValue(uint32_t{Device->ZeDeviceIpVersionExt->ipVersion});
case UR_DEVICE_INFO_MAX_PARAMETER_SIZE:
return ReturnValue(
size_t{Device->ZeDeviceModuleProperties->maxArgumentsSize});
case UR_DEVICE_INFO_MEM_BASE_ADDR_ALIGN:
// SYCL/OpenCL spec is vague on what this means exactly, but seems to
// be for "alignment requirement (in bits) for sub-buffer offsets."
// An OpenCL implementation returns 8*128, but Level Zero can do just 8,
// meaning unaligned access for values of types larger than 8 bits.
return ReturnValue(uint32_t{8});
case UR_DEVICE_INFO_MAX_SAMPLERS:
return ReturnValue(uint32_t{Device->ZeDeviceImageProperties->maxSamplers});
case UR_DEVICE_INFO_MAX_READ_IMAGE_ARGS:
return ReturnValue(
uint32_t{Device->ZeDeviceImageProperties->maxReadImageArgs});
case UR_DEVICE_INFO_MAX_WRITE_IMAGE_ARGS:
return ReturnValue(
uint32_t{Device->ZeDeviceImageProperties->maxWriteImageArgs});
case UR_DEVICE_INFO_SINGLE_FP_CONFIG: {
ur_device_fp_capability_flags_t SingleFPValue = 0;
ze_device_fp_flags_t ZeSingleFPCapabilities =
Device->ZeDeviceModuleProperties->fp32flags;
if (ZE_DEVICE_FP_FLAG_DENORM & ZeSingleFPCapabilities) {
SingleFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_DENORM;
}
if (ZE_DEVICE_FP_FLAG_INF_NAN & ZeSingleFPCapabilities) {
SingleFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_INF_NAN;
}
if (ZE_DEVICE_FP_FLAG_ROUND_TO_NEAREST & ZeSingleFPCapabilities) {
SingleFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_NEAREST;
}
if (ZE_DEVICE_FP_FLAG_ROUND_TO_ZERO & ZeSingleFPCapabilities) {
SingleFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_ZERO;
}
if (ZE_DEVICE_FP_FLAG_ROUND_TO_INF & ZeSingleFPCapabilities) {
SingleFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_INF;
}
if (ZE_DEVICE_FP_FLAG_FMA & ZeSingleFPCapabilities) {
SingleFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_FMA;
}
if (ZE_DEVICE_FP_FLAG_ROUNDED_DIVIDE_SQRT & ZeSingleFPCapabilities) {
SingleFPValue |=
UR_DEVICE_FP_CAPABILITY_FLAG_CORRECTLY_ROUNDED_DIVIDE_SQRT;
}
return ReturnValue(SingleFPValue);
}
case UR_DEVICE_INFO_HALF_FP_CONFIG: {
ur_device_fp_capability_flags_t HalfFPValue = 0;
ze_device_fp_flags_t ZeHalfFPCapabilities =
Device->ZeDeviceModuleProperties->fp16flags;
if (ZE_DEVICE_FP_FLAG_DENORM & ZeHalfFPCapabilities) {
HalfFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_DENORM;
}
if (ZE_DEVICE_FP_FLAG_INF_NAN & ZeHalfFPCapabilities) {
HalfFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_INF_NAN;
}
if (ZE_DEVICE_FP_FLAG_ROUND_TO_NEAREST & ZeHalfFPCapabilities) {
HalfFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_NEAREST;
}
if (ZE_DEVICE_FP_FLAG_ROUND_TO_ZERO & ZeHalfFPCapabilities) {
HalfFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_ZERO;
}
if (ZE_DEVICE_FP_FLAG_ROUND_TO_INF & ZeHalfFPCapabilities) {
HalfFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_INF;
}
if (ZE_DEVICE_FP_FLAG_FMA & ZeHalfFPCapabilities) {
HalfFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_FMA;
}
if (ZE_DEVICE_FP_FLAG_ROUNDED_DIVIDE_SQRT & ZeHalfFPCapabilities) {
HalfFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_CORRECTLY_ROUNDED_DIVIDE_SQRT;
}
return ReturnValue(HalfFPValue);
}
case UR_DEVICE_INFO_DOUBLE_FP_CONFIG: {
ur_device_fp_capability_flags_t DoubleFPValue = 0;
ze_device_fp_flags_t ZeDoubleFPCapabilities =
Device->ZeDeviceModuleProperties->fp64flags;
if (ZE_DEVICE_FP_FLAG_DENORM & ZeDoubleFPCapabilities) {
DoubleFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_DENORM;
}
if (ZE_DEVICE_FP_FLAG_INF_NAN & ZeDoubleFPCapabilities) {
DoubleFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_INF_NAN;
}
if (ZE_DEVICE_FP_FLAG_ROUND_TO_NEAREST & ZeDoubleFPCapabilities) {
DoubleFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_NEAREST;
}
if (ZE_DEVICE_FP_FLAG_ROUND_TO_ZERO & ZeDoubleFPCapabilities) {
DoubleFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_ZERO;
}
if (ZE_DEVICE_FP_FLAG_ROUND_TO_INF & ZeDoubleFPCapabilities) {
DoubleFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_INF;
}
if (ZE_DEVICE_FP_FLAG_FMA & ZeDoubleFPCapabilities) {
DoubleFPValue |= UR_DEVICE_FP_CAPABILITY_FLAG_FMA;
}
if (ZE_DEVICE_FP_FLAG_ROUNDED_DIVIDE_SQRT & ZeDoubleFPCapabilities) {
DoubleFPValue |=
UR_DEVICE_FP_CAPABILITY_FLAG_CORRECTLY_ROUNDED_DIVIDE_SQRT;
}
return ReturnValue(DoubleFPValue);
}
case UR_DEVICE_INFO_IMAGE2D_MAX_WIDTH:
return ReturnValue(size_t{Device->ZeDeviceImageProperties->maxImageDims2D});
case UR_DEVICE_INFO_IMAGE2D_MAX_HEIGHT:
return ReturnValue(size_t{Device->ZeDeviceImageProperties->maxImageDims2D});
case UR_DEVICE_INFO_IMAGE3D_MAX_WIDTH:
return ReturnValue(size_t{Device->ZeDeviceImageProperties->maxImageDims3D});
case UR_DEVICE_INFO_IMAGE3D_MAX_HEIGHT:
return ReturnValue(size_t{Device->ZeDeviceImageProperties->maxImageDims3D});
case UR_DEVICE_INFO_IMAGE3D_MAX_DEPTH:
return ReturnValue(size_t{Device->ZeDeviceImageProperties->maxImageDims3D});
case UR_DEVICE_INFO_IMAGE_MAX_BUFFER_SIZE:
return ReturnValue(
size_t{Device->ZeDeviceImageProperties->maxImageBufferSize});
case UR_DEVICE_INFO_IMAGE_MAX_ARRAY_SIZE:
return ReturnValue(
size_t{Device->ZeDeviceImageProperties->maxImageArraySlices});
// Handle SIMD widths.
// TODO: can we do better than this?
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_CHAR:
case UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_CHAR:
return ReturnValue(Device->ZeDeviceProperties->physicalEUSimdWidth / 1);
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_SHORT:
case UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_SHORT:
return ReturnValue(Device->ZeDeviceProperties->physicalEUSimdWidth / 2);
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_INT:
case UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_INT:
return ReturnValue(Device->ZeDeviceProperties->physicalEUSimdWidth / 4);
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_LONG:
case UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_LONG:
return ReturnValue(Device->ZeDeviceProperties->physicalEUSimdWidth / 8);
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_FLOAT:
case UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_FLOAT:
return ReturnValue(Device->ZeDeviceProperties->physicalEUSimdWidth / 4);
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_DOUBLE:
case UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_DOUBLE:
return ReturnValue(Device->ZeDeviceProperties->physicalEUSimdWidth / 8);
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_HALF:
case UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_HALF:
return ReturnValue(Device->ZeDeviceProperties->physicalEUSimdWidth / 2);
case UR_DEVICE_INFO_MAX_NUM_SUB_GROUPS: {
// Max_num_sub_Groups = maxTotalGroupSize/min(set of subGroupSizes);
uint32_t MinSubGroupSize =
Device->ZeDeviceComputeProperties->subGroupSizes[0];
for (uint32_t I = 1;
I < Device->ZeDeviceComputeProperties->numSubGroupSizes; I++) {
if (MinSubGroupSize > Device->ZeDeviceComputeProperties->subGroupSizes[I])
MinSubGroupSize = Device->ZeDeviceComputeProperties->subGroupSizes[I];
}
return ReturnValue(Device->ZeDeviceComputeProperties->maxTotalGroupSize /
MinSubGroupSize);
}
case UR_DEVICE_INFO_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS: {
// TODO: Not supported yet. Needs to be updated after support is added.
return ReturnValue(static_cast<uint32_t>(false));
}
case UR_DEVICE_INFO_SUB_GROUP_SIZES_INTEL: {
// ze_device_compute_properties.subGroupSizes is in uint32_t whereas the
// expected return is size_t datatype. size_t can be 8 bytes of data.
return ReturnValue.template operator()<size_t>(
Device->ZeDeviceComputeProperties->subGroupSizes,
Device->ZeDeviceComputeProperties->numSubGroupSizes);
}
case UR_DEVICE_INFO_IL_VERSION: {
// Set to a space separated list of IL version strings of the form
// <IL_Prefix>_<Major_version>.<Minor_version>.
// "SPIR-V" is a required IL prefix when cl_khr_il_progam extension is
// reported.
uint32_t SpirvVersion =
Device->ZeDeviceModuleProperties->spirvVersionSupported;
uint32_t SpirvVersionMajor = ZE_MAJOR_VERSION(SpirvVersion);
uint32_t SpirvVersionMinor = ZE_MINOR_VERSION(SpirvVersion);
char SpirvVersionString[50];
int Len = sprintf(SpirvVersionString, "SPIR-V_%d.%d ", SpirvVersionMajor,
SpirvVersionMinor);
// returned string to contain only len number of characters.
std::string ILVersion(SpirvVersionString, Len);
return ReturnValue(ILVersion.c_str());
}
case UR_DEVICE_INFO_USM_HOST_SUPPORT:
case UR_DEVICE_INFO_USM_DEVICE_SUPPORT:
case UR_DEVICE_INFO_USM_SINGLE_SHARED_SUPPORT:
case UR_DEVICE_INFO_USM_CROSS_SHARED_SUPPORT:
case UR_DEVICE_INFO_USM_SYSTEM_SHARED_SUPPORT: {
auto MapCaps = [](const ze_memory_access_cap_flags_t &ZeCapabilities) {
ur_device_usm_access_capability_flags_t Capabilities = 0;
if (ZeCapabilities & ZE_MEMORY_ACCESS_CAP_FLAG_RW)
Capabilities |= UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS;
if (ZeCapabilities & ZE_MEMORY_ACCESS_CAP_FLAG_ATOMIC)
Capabilities |= UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ATOMIC_ACCESS;
if (ZeCapabilities & ZE_MEMORY_ACCESS_CAP_FLAG_CONCURRENT)
Capabilities |= UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_CONCURRENT_ACCESS;
if (ZeCapabilities & ZE_MEMORY_ACCESS_CAP_FLAG_CONCURRENT_ATOMIC)
Capabilities |=
UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ATOMIC_CONCURRENT_ACCESS;
return Capabilities;
};
auto &Props = Device->ZeDeviceMemoryAccessProperties;
switch (ParamName) {
case UR_DEVICE_INFO_USM_HOST_SUPPORT:
return ReturnValue(MapCaps(Props->hostAllocCapabilities));
case UR_DEVICE_INFO_USM_DEVICE_SUPPORT:
return ReturnValue(MapCaps(Props->deviceAllocCapabilities));
case UR_DEVICE_INFO_USM_SINGLE_SHARED_SUPPORT:
return ReturnValue(MapCaps(Props->sharedSingleDeviceAllocCapabilities));
case UR_DEVICE_INFO_USM_CROSS_SHARED_SUPPORT:
return ReturnValue(MapCaps(Props->sharedCrossDeviceAllocCapabilities));
case UR_DEVICE_INFO_USM_SYSTEM_SHARED_SUPPORT:
return ReturnValue(MapCaps(Props->sharedSystemAllocCapabilities));
default:
die("urDeviceGetInfo: unexpected ParamName.");
}
}
// intel extensions for GPU information
case UR_DEVICE_INFO_DEVICE_ID:
return ReturnValue(uint32_t{Device->ZeDeviceProperties->deviceId});
case UR_DEVICE_INFO_PCI_ADDRESS: {
ze_pci_address_ext_t PciAddr{};
ZeStruct<ze_pci_ext_properties_t> ZeDevicePciProperties;
ZeDevicePciProperties.address = PciAddr;
ZE2UR_CALL(zeDevicePciGetPropertiesExt, (ZeDevice, &ZeDevicePciProperties));
constexpr size_t AddressBufferSize = 13;
char AddressBuffer[AddressBufferSize];
std::snprintf(AddressBuffer, AddressBufferSize, "%04x:%02x:%02x.%01x",
ZeDevicePciProperties.address.domain,
ZeDevicePciProperties.address.bus,
ZeDevicePciProperties.address.device,
ZeDevicePciProperties.address.function);
return ReturnValue(AddressBuffer);
}
case UR_DEVICE_INFO_GLOBAL_MEM_FREE: {
if (getenv("ZES_ENABLE_SYSMAN") == nullptr) {
setErrorMessage("Set ZES_ENABLE_SYSMAN=1 to obtain free memory",
UR_RESULT_ERROR_UNINITIALIZED,
static_cast<int32_t>(ZE_RESULT_ERROR_UNINITIALIZED));
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
}
// Calculate the global memory size as the max limit that can be reported as
// "free" memory for the user to allocate.
uint64_t GlobalMemSize = calculateGlobalMemSize(Device);
// Only report device memory which zeMemAllocDevice can allocate from.
// Currently this is only the one enumerated with ordinal 0.
uint64_t FreeMemory = 0;
uint32_t MemCount = 0;
ZE2UR_CALL(zesDeviceEnumMemoryModules, (ZeDevice, &MemCount, nullptr));
if (MemCount != 0) {
std::vector<zes_mem_handle_t> ZesMemHandles(MemCount);
ZE2UR_CALL(zesDeviceEnumMemoryModules,
(ZeDevice, &MemCount, ZesMemHandles.data()));
for (auto &ZesMemHandle : ZesMemHandles) {
ZesStruct<zes_mem_properties_t> ZesMemProperties;
ZE2UR_CALL(zesMemoryGetProperties, (ZesMemHandle, &ZesMemProperties));
// For root-device report memory from all memory modules since that
// is what totally available in the default implicit scaling mode.
// For sub-devices only report memory local to them.
if (!Device->isSubDevice() || Device->ZeDeviceProperties->subdeviceId ==
ZesMemProperties.subdeviceId) {
ZesStruct<zes_mem_state_t> ZesMemState;
ZE2UR_CALL(zesMemoryGetState, (ZesMemHandle, &ZesMemState));
FreeMemory += ZesMemState.free;
}
}
}
if (MemCount > 0) {
return ReturnValue(std::min(GlobalMemSize, FreeMemory));
} else {
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
}
case UR_DEVICE_INFO_MEMORY_CLOCK_RATE: {
// If there are not any memory modules then return 0.
if (Device->ZeDeviceMemoryProperties->first.empty())
return ReturnValue(uint32_t{0});
// If there are multiple memory modules on the device then we have to report
// the value of the slowest memory.
auto Comp = [](const ze_device_memory_properties_t &A,
const ze_device_memory_properties_t &B) -> bool {
return A.maxClockRate < B.maxClockRate;
};
auto MinIt =
std::min_element(Device->ZeDeviceMemoryProperties->first.begin(),
Device->ZeDeviceMemoryProperties->first.end(), Comp);
return ReturnValue(uint32_t{MinIt->maxClockRate});
}
case UR_DEVICE_INFO_MEMORY_BUS_WIDTH: {
// If there are not any memory modules then return 0.
if (Device->ZeDeviceMemoryProperties->first.empty())
return ReturnValue(uint32_t{0});
// If there are multiple memory modules on the device then we have to report
// the value of the slowest memory.
auto Comp = [](const ze_device_memory_properties_t &A,
const ze_device_memory_properties_t &B) -> bool {
return A.maxBusWidth < B.maxBusWidth;
};
auto MinIt =
std::min_element(Device->ZeDeviceMemoryProperties->first.begin(),
Device->ZeDeviceMemoryProperties->first.end(), Comp);
return ReturnValue(uint32_t{MinIt->maxBusWidth});
}
case UR_DEVICE_INFO_MAX_COMPUTE_QUEUE_INDICES: {
if (Device->QueueGroup[ur_device_handle_t_::queue_group_info_t::Compute]
.ZeIndex >= 0)
// Sub-sub-device represents a particular compute index already.
return ReturnValue(int32_t{1});
auto ZeDeviceNumIndices =
Device->QueueGroup[ur_device_handle_t_::queue_group_info_t::Compute]
.ZeProperties.numQueues;
return ReturnValue(int32_t(ZeDeviceNumIndices));
} break;
case UR_DEVICE_INFO_GPU_EU_COUNT: {
uint32_t count = Device->ZeDeviceProperties->numEUsPerSubslice *
Device->ZeDeviceProperties->numSubslicesPerSlice *
Device->ZeDeviceProperties->numSlices;
return ReturnValue(uint32_t{count});
}
case UR_DEVICE_INFO_GPU_EU_SLICES: {
return ReturnValue(uint32_t{Device->ZeDeviceProperties->numSlices});
}
case UR_DEVICE_INFO_GPU_EU_SIMD_WIDTH:
return ReturnValue(
uint32_t{Device->ZeDeviceProperties->physicalEUSimdWidth});
case UR_DEVICE_INFO_GPU_SUBSLICES_PER_SLICE:
return ReturnValue(
uint32_t{Device->ZeDeviceProperties->numSubslicesPerSlice});
case UR_DEVICE_INFO_GPU_EU_COUNT_PER_SUBSLICE:
return ReturnValue(uint32_t{Device->ZeDeviceProperties->numEUsPerSubslice});
case UR_DEVICE_INFO_GPU_HW_THREADS_PER_EU:
return ReturnValue(uint32_t{Device->ZeDeviceProperties->numThreadsPerEU});
case UR_DEVICE_INFO_MAX_MEMORY_BANDWIDTH:
// currently not supported in level zero runtime
return UR_RESULT_ERROR_INVALID_VALUE;
case UR_DEVICE_INFO_BFLOAT16: {
// bfloat16 math functions are not yet supported on Intel GPUs.
return ReturnValue(bool{false});
}
case UR_DEVICE_INFO_ATOMIC_MEMORY_SCOPE_CAPABILITIES: {
// There are no explicit restrictions in L0 programming guide, so assume all
// are supported
ur_memory_scope_capability_flags_t result =
UR_MEMORY_SCOPE_CAPABILITY_FLAG_WORK_ITEM |
UR_MEMORY_SCOPE_CAPABILITY_FLAG_SUB_GROUP |
UR_MEMORY_SCOPE_CAPABILITY_FLAG_WORK_GROUP |
UR_MEMORY_SCOPE_CAPABILITY_FLAG_DEVICE |
UR_MEMORY_SCOPE_CAPABILITY_FLAG_SYSTEM;
return ReturnValue(result);
}
case UR_DEVICE_INFO_ATOMIC_FENCE_ORDER_CAPABILITIES: {
// There are no explicit restrictions in L0 programming guide, so assume all
// are supported
ur_memory_order_capability_flags_t result =
UR_MEMORY_ORDER_CAPABILITY_FLAG_RELAXED |
UR_MEMORY_ORDER_CAPABILITY_FLAG_ACQUIRE |
UR_MEMORY_ORDER_CAPABILITY_FLAG_RELEASE |
UR_MEMORY_ORDER_CAPABILITY_FLAG_ACQ_REL |
UR_MEMORY_ORDER_CAPABILITY_FLAG_SEQ_CST;
return ReturnValue(result);
}
case UR_DEVICE_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES: {
// There are no explicit restrictions in L0 programming guide, so assume all
// are supported
ur_memory_scope_capability_flags_t result =
UR_MEMORY_SCOPE_CAPABILITY_FLAG_WORK_ITEM |
UR_MEMORY_SCOPE_CAPABILITY_FLAG_SUB_GROUP |
UR_MEMORY_SCOPE_CAPABILITY_FLAG_WORK_GROUP |
UR_MEMORY_SCOPE_CAPABILITY_FLAG_DEVICE |
UR_MEMORY_SCOPE_CAPABILITY_FLAG_SYSTEM;
return ReturnValue(result);
}
case UR_DEVICE_INFO_ATOMIC_MEMORY_ORDER_CAPABILITIES: {
ur_memory_order_capability_flags_t capabilities =
UR_MEMORY_ORDER_CAPABILITY_FLAG_RELAXED |
UR_MEMORY_ORDER_CAPABILITY_FLAG_ACQUIRE |
UR_MEMORY_ORDER_CAPABILITY_FLAG_RELEASE |
UR_MEMORY_ORDER_CAPABILITY_FLAG_ACQ_REL |
UR_MEMORY_ORDER_CAPABILITY_FLAG_SEQ_CST;
return ReturnValue(capabilities);
}
case UR_DEVICE_INFO_MEM_CHANNEL_SUPPORT:
return ReturnValue(uint32_t{false});
case UR_DEVICE_INFO_IMAGE_SRGB:
return ReturnValue(uint32_t{false});
case UR_DEVICE_INFO_QUEUE_ON_DEVICE_PROPERTIES:
case UR_DEVICE_INFO_QUEUE_ON_HOST_PROPERTIES: {
ur_queue_flags_t queue_flags = 0;
return ReturnValue(queue_flags);
}
case UR_DEVICE_INFO_MAX_READ_WRITE_IMAGE_ARGS: {
return ReturnValue(static_cast<uint32_t>(
0)); //__read_write attribute currently undefinde in opencl
}
case UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT: {
return ReturnValue(static_cast<uint32_t>(true));
}
case UR_DEVICE_INFO_ESIMD_SUPPORT: {
// ESIMD is only supported by Intel GPUs.
uint32_t result = Device->ZeDeviceProperties->type == ZE_DEVICE_TYPE_GPU &&
Device->ZeDeviceProperties->vendorId == 0x8086;
return ReturnValue(result);
}
case UR_DEVICE_INFO_COMPONENT_DEVICES: {
ze_device_handle_t DevHandle = Device->ZeDevice;
uint32_t SubDeviceCount = 0;
// First call to get SubDeviceCount.
ZE2UR_CALL(zeDeviceGetSubDevices, (DevHandle, &SubDeviceCount, nullptr));
if (SubDeviceCount == 0)
return ReturnValue(0);
std::vector<ze_device_handle_t> SubDevs(SubDeviceCount);
// Second call to get the actual list of devices.
ZE2UR_CALL(zeDeviceGetSubDevices,
(DevHandle, &SubDeviceCount, SubDevs.data()));
size_t SubDeviceCount_s{SubDeviceCount};
auto ResSize =
std::min(SubDeviceCount_s, propSize / sizeof(ur_device_handle_t));
std::vector<ur_device_handle_t> Res;
for (const auto &d : SubDevs) {
// We can only reach this code if ZE_FLAT_DEVICE_HIERARCHY != FLAT,
// because in flat mode we directly get tiles, and those don't have any
// further divisions, so zeDeviceGetSubDevices always will return an empty
// list. Thus, there's only two options left: (a) composite mode, and (b)
// combined mode. In (b), zeDeviceGet returns tiles as devices, and those
// are presented as root devices (i.e. isSubDevice() returns false). In
// contrast, in (a), zeDeviceGet returns cards as devices, so tiles are
// not root devices (i.e. isSubDevice() returns true). Since we only reach
// this code if there are tiles returned by zeDeviceGetSubDevices, we
// can know if we are in (a) or (b) by checking if a tile is root device
// or not.
ur_device_handle_t URDev = Device->Platform->getDeviceFromNativeHandle(d);
if (URDev->isSubDevice())
// We are in COMPOSITE mode, return an empty list.
return ReturnValue(0);
Res.push_back(URDev);
}
if (pSize)
*pSize = SubDeviceCount * sizeof(ur_device_handle_t);
if (ParamValue) {
return ReturnValue(Res.data(), ResSize);
}
return UR_RESULT_SUCCESS;
}
case UR_DEVICE_INFO_COMPOSITE_DEVICE: {
ur_device_handle_t UrRootDev = nullptr;
ze_device_handle_t DevHandle = Device->ZeDevice;
ze_device_handle_t RootDev;
// Query Root Device.
auto errc = ZE_CALL_NOCHECK(zeDeviceGetRootDevice, (DevHandle, &RootDev));
UrRootDev = Device->Platform->getDeviceFromNativeHandle(RootDev);
if (errc != ZE_RESULT_SUCCESS &&
errc != ZE_RESULT_ERROR_UNSUPPORTED_FEATURE)
return ze2urResult(errc);
return ReturnValue(UrRootDev);
}
case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP:
return ReturnValue(true);
case UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_SUPPORT_EXP: {
// TODO: Level Zero API allows to check support for all sub-features:
// ZE_MUTABLE_COMMAND_EXP_FLAG_KERNEL_ARGUMENTS,
// ZE_MUTABLE_COMMAND_EXP_FLAG_GROUP_COUNT,
// ZE_MUTABLE_COMMAND_EXP_FLAG_GROUP_SIZE,
// ZE_MUTABLE_COMMAND_EXP_FLAG_GLOBAL_OFFSET,
// ZE_MUTABLE_COMMAND_EXP_FLAG_SIGNAL_EVENT,
// ZE_MUTABLE_COMMAND_EXP_FLAG_WAIT_EVENTS
// but UR has only one property to check the mutable command lists feature
// support. For now return true if kernel arguments can be updated.
auto KernelArgUpdateSupport =
Device->ZeDeviceMutableCmdListsProperties->mutableCommandFlags &
ZE_MUTABLE_COMMAND_EXP_FLAG_KERNEL_ARGUMENTS;
return ReturnValue(KernelArgUpdateSupport &&
Device->Platform->ZeMutableCmdListExt.Supported);
}
case UR_DEVICE_INFO_BINDLESS_IMAGES_SUPPORT_EXP:
return ReturnValue(true);
case UR_DEVICE_INFO_BINDLESS_IMAGES_SHARED_USM_SUPPORT_EXP:
return ReturnValue(true);
case UR_DEVICE_INFO_BINDLESS_IMAGES_1D_USM_SUPPORT_EXP:
return ReturnValue(false);
case UR_DEVICE_INFO_BINDLESS_IMAGES_2D_USM_SUPPORT_EXP:
return ReturnValue(true);
case UR_DEVICE_INFO_IMAGE_PITCH_ALIGN_EXP:
case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_WIDTH_EXP:
case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_HEIGHT_EXP:
case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_PITCH_EXP:
urPrint("Unsupported ParamName in urGetDeviceInfo\n");
urPrint("ParamName=%d(0x%x)\n", ParamName, ParamName);
return UR_RESULT_ERROR_INVALID_VALUE;
case UR_DEVICE_INFO_MIPMAP_SUPPORT_EXP:
return ReturnValue(true);
case UR_DEVICE_INFO_MIPMAP_ANISOTROPY_SUPPORT_EXP:
return ReturnValue(true);
case UR_DEVICE_INFO_MIPMAP_MAX_ANISOTROPY_EXP:
case UR_DEVICE_INFO_MIPMAP_LEVEL_REFERENCE_SUPPORT_EXP:
case UR_DEVICE_INFO_INTEROP_MEMORY_IMPORT_SUPPORT_EXP:
case UR_DEVICE_INFO_INTEROP_MEMORY_EXPORT_SUPPORT_EXP:
case UR_DEVICE_INFO_INTEROP_SEMAPHORE_IMPORT_SUPPORT_EXP:
case UR_DEVICE_INFO_INTEROP_SEMAPHORE_EXPORT_SUPPORT_EXP:
default:
urPrint("Unsupported ParamName in urGetDeviceInfo\n");
urPrint("ParamName=%d(0x%x)\n", ParamName, ParamName);
return UR_RESULT_ERROR_INVALID_VALUE;
}
return UR_RESULT_SUCCESS;
}
// UR_L0_USE_COPY_ENGINE can be set to an integer value, or
// a pair of integer values of the form "lower_index:upper_index".
// Here, the indices point to copy engines in a list of all available copy
// engines.
// This functions returns this pair of indices.
// If the user specifies only a single integer, a value of 0 indicates that
// the copy engines will not be used at all. A value of 1 indicates that all
// available copy engines can be used.
const std::pair<int, int>
getRangeOfAllowedCopyEngines(const ur_device_handle_t &Device) {
const char *UrRet = std::getenv("UR_L0_USE_COPY_ENGINE");
const char *PiRet = std::getenv("SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE");
static const char *EnvVar = UrRet ? UrRet : (PiRet ? PiRet : nullptr);
// If the environment variable is not set, no copy engines are used when
// immediate commandlists are being used. For standard commandlists all are
// used.
if (!EnvVar) {
if (Device->ImmCommandListUsed)
return std::pair<int, int>(0, 0); // Only main copy engine will be used.
return std::pair<int, int>(0, INT_MAX); // All copy engines will be used.
}
std::string CopyEngineRange = EnvVar;
// Environment variable can be a single integer or a pair of integers
// separated by ":"
auto pos = CopyEngineRange.find(":");
if (pos == std::string::npos) {
bool UseCopyEngine = (std::stoi(CopyEngineRange) != 0);