-
Notifications
You must be signed in to change notification settings - Fork 769
/
Copy pathdevice.cpp
1352 lines (1259 loc) · 51 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 - CUDA 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 <array>
#include <cassert>
#include <sstream>
#include "adapter.hpp"
#include "context.hpp"
#include "device.hpp"
#include "logger/ur_logger.hpp"
#include "platform.hpp"
#include "ur_util.hpp"
#include <nvml.h>
int getAttribute(ur_device_handle_t device, CUdevice_attribute attribute) {
int value;
UR_CHECK_ERROR(cuDeviceGetAttribute(&value, attribute, device->get()));
return value;
}
uint64_t ur_device_handle_t_::getElapsedTime(CUevent ev) const {
float Milliseconds = 0.0f;
// cuEventSynchronize waits till the event is ready for call to
// cuEventElapsedTime.
UR_CHECK_ERROR(cuEventSynchronize(EvBase));
UR_CHECK_ERROR(cuEventSynchronize(ev));
UR_CHECK_ERROR(cuEventElapsedTime(&Milliseconds, EvBase, ev));
return static_cast<uint64_t>(Milliseconds * 1.0e6);
}
UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
ur_device_info_t propName,
size_t propSize,
void *pPropValue,
size_t *pPropSizeRet) try {
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
static constexpr uint32_t MaxWorkItemDimensions = 3u;
ScopedContext Active(hDevice);
switch ((uint32_t)propName) {
case UR_DEVICE_INFO_TYPE: {
return ReturnValue(UR_DEVICE_TYPE_GPU);
}
case UR_DEVICE_INFO_VENDOR_ID: {
return ReturnValue(4318u);
}
case UR_DEVICE_INFO_NUM_COMPUTE_UNITS:
case UR_DEVICE_INFO_MAX_COMPUTE_UNITS: {
return ReturnValue(hDevice->getNumComputeUnits());
}
case UR_DEVICE_INFO_MAX_WORK_ITEM_DIMENSIONS: {
return ReturnValue(MaxWorkItemDimensions);
}
case UR_DEVICE_INFO_MAX_WORK_ITEM_SIZES: {
struct {
size_t Sizes[MaxWorkItemDimensions];
} ReturnSizes;
int MaxX = 0, MaxY = 0, MaxZ = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&MaxX, CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_X, hDevice->get()));
assert(MaxX >= 0);
UR_CHECK_ERROR(cuDeviceGetAttribute(
&MaxY, CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Y, hDevice->get()));
assert(MaxY >= 0);
UR_CHECK_ERROR(cuDeviceGetAttribute(
&MaxZ, CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Z, hDevice->get()));
assert(MaxZ >= 0);
ReturnSizes.Sizes[0] = size_t(MaxX);
ReturnSizes.Sizes[1] = size_t(MaxY);
ReturnSizes.Sizes[2] = size_t(MaxZ);
return ReturnValue(ReturnSizes);
}
case UR_DEVICE_INFO_MAX_WORK_GROUPS_3D: {
struct {
size_t Sizes[MaxWorkItemDimensions];
} ReturnSizes;
int MaxX = 0, MaxY = 0, MaxZ = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&MaxX, CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_X, hDevice->get()));
assert(MaxX >= 0);
UR_CHECK_ERROR(cuDeviceGetAttribute(
&MaxY, CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Y, hDevice->get()));
assert(MaxY >= 0);
UR_CHECK_ERROR(cuDeviceGetAttribute(
&MaxZ, CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Z, hDevice->get()));
assert(MaxZ >= 0);
ReturnSizes.Sizes[0] = size_t(MaxX);
ReturnSizes.Sizes[1] = size_t(MaxY);
ReturnSizes.Sizes[2] = size_t(MaxZ);
return ReturnValue(ReturnSizes);
}
case UR_DEVICE_INFO_MAX_WORK_GROUP_SIZE: {
int MaxWorkGroupSize = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&MaxWorkGroupSize, CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK,
hDevice->get()));
assert(MaxWorkGroupSize >= 0);
return ReturnValue(size_t(MaxWorkGroupSize));
}
case UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_CHAR: {
return ReturnValue(1u);
}
case UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_SHORT: {
return ReturnValue(1u);
}
case UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_INT: {
return ReturnValue(1u);
}
case UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_LONG: {
return ReturnValue(1u);
}
case UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_FLOAT: {
return ReturnValue(1u);
}
case UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_DOUBLE: {
return ReturnValue(1u);
}
case UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_HALF: {
return ReturnValue(0u);
}
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_CHAR: {
return ReturnValue(1u);
}
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_SHORT: {
return ReturnValue(1u);
}
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_INT: {
return ReturnValue(1u);
}
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_LONG: {
return ReturnValue(1u);
}
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_FLOAT: {
return ReturnValue(1u);
}
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_DOUBLE: {
return ReturnValue(1u);
}
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_HALF: {
return ReturnValue(0u);
}
case UR_DEVICE_INFO_MAX_NUM_SUB_GROUPS: {
// Number of sub-groups = max block size / warp size + possible remainder
int MaxThreads = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&MaxThreads, CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK,
hDevice->get()));
int WarpSize = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&WarpSize, CU_DEVICE_ATTRIBUTE_WARP_SIZE, hDevice->get()));
int MaxWarps = (MaxThreads + WarpSize - 1) / WarpSize;
return ReturnValue(MaxWarps);
}
case UR_DEVICE_INFO_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS: {
// Volta provides independent thread scheduling
// TODO: Revisit for previous generation GPUs
int Major = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, hDevice->get()));
bool IFP = (Major >= 7);
return ReturnValue(IFP);
}
case UR_DEVICE_INFO_ATOMIC_64: {
int Major = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, hDevice->get()));
bool Atomic64 = (Major >= 6) ? true : false;
return ReturnValue(Atomic64);
}
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;
int Major = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, hDevice->get()));
if (Major >= 7)
Capabilities |= UR_MEMORY_ORDER_CAPABILITY_FLAG_SEQ_CST;
return ReturnValue(Capabilities);
}
case UR_DEVICE_INFO_ATOMIC_MEMORY_SCOPE_CAPABILITIES: {
int Major = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, hDevice->get()));
ur_memory_scope_capability_flags_t Capabilities =
(Major >= 7) ? 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
: 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;
return ReturnValue(Capabilities);
}
case UR_DEVICE_INFO_ATOMIC_FENCE_ORDER_CAPABILITIES: {
// SYCL2020 4.6.4.2 minimum mandated capabilities for
// atomic_fence_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;
int Major = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, hDevice->get()));
if (Major >= 7)
Capabilities |= UR_MEMORY_ORDER_CAPABILITY_FLAG_SEQ_CST;
return ReturnValue(Capabilities);
}
case UR_DEVICE_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES: {
// SYCL2020 4.6.4.2 minimum mandated capabilities for
// atomic_fence/memory_scope_capabilities.
// Because scopes are hierarchical, wider scopes support all narrower
// scopes. At a minimum, each device must support WORK_ITEM, SUB_GROUP and
// WORK_GROUP. (https://github.com/KhronosGroup/SYCL-Docs/pull/382)
ur_memory_scope_capability_flags_t Capabilities =
UR_MEMORY_SCOPE_CAPABILITY_FLAG_WORK_ITEM |
UR_MEMORY_SCOPE_CAPABILITY_FLAG_SUB_GROUP |
UR_MEMORY_SCOPE_CAPABILITY_FLAG_WORK_GROUP;
return ReturnValue(Capabilities);
}
case UR_DEVICE_INFO_BFLOAT16_CONVERSIONS_NATIVE:
return ReturnValue(false);
case UR_DEVICE_INFO_SUB_GROUP_SIZES_INTEL: {
// NVIDIA devices only support one sub-group size (the warp size)
int WarpSize = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&WarpSize, CU_DEVICE_ATTRIBUTE_WARP_SIZE, hDevice->get()));
uint32_t Sizes[1] = {static_cast<uint32_t>(WarpSize)};
return ReturnValue(Sizes, 1);
}
case UR_DEVICE_INFO_MAX_CLOCK_FREQUENCY: {
int ClockFreq = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&ClockFreq, CU_DEVICE_ATTRIBUTE_CLOCK_RATE, hDevice->get()));
assert(ClockFreq >= 0);
return ReturnValue(static_cast<uint32_t>(ClockFreq) / 1000u);
}
case UR_DEVICE_INFO_ADDRESS_BITS: {
auto Bits = uint32_t{std::numeric_limits<uintptr_t>::digits};
return ReturnValue(Bits);
}
case UR_DEVICE_INFO_MAX_MEM_ALLOC_SIZE: {
return ReturnValue(uint64_t{hDevice->getMaxAllocSize()});
}
case UR_DEVICE_INFO_IMAGE_SUPPORT: {
bool Enabled = false;
if (std::getenv("UR_CUDA_ENABLE_IMAGE_SUPPORT") != nullptr) {
std::cerr << "UR_CUDA_ENABLE_IMAGE_SUPPORT is deprecated, please use "
"SYCL_UR_CUDA_ENABLE_IMAGE_SUPPORT instead.";
} else if (std::getenv("SYCL_UR_CUDA_ENABLE_IMAGE_SUPPORT") != nullptr) {
Enabled = true;
} else {
UR_LOG(
QUIET,
"Images are not fully supported by the CUDA BE, their support is "
"disabled by default. Their partial support can be activated by "
"setting SYCL_UR_CUDA_ENABLE_IMAGE_SUPPORT environment variable at "
"runtime.");
}
return ReturnValue(Enabled);
}
case UR_DEVICE_INFO_MAX_READ_IMAGE_ARGS: {
// This call doesn't match to CUDA as it doesn't have images, but instead
// surfaces and textures. No clear call in the CUDA API to determine this,
// but some searching found as of SM 2.x 128 are supported.
return ReturnValue(128u);
}
case UR_DEVICE_INFO_MAX_WRITE_IMAGE_ARGS: {
// This call doesn't match to CUDA as it doesn't have images, but instead
// surfaces and textures. No clear call in the CUDA API to determine this,
// but some searching found as of SM 2.x 128 are supported.
return ReturnValue(128u);
}
case UR_DEVICE_INFO_IMAGE2D_MAX_HEIGHT: {
// Take the smaller of maximum surface and maximum texture height.
int TexHeight = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&TexHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_HEIGHT,
hDevice->get()));
assert(TexHeight >= 0);
int SurfHeight = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&SurfHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_HEIGHT,
hDevice->get()));
assert(SurfHeight >= 0);
int Min = std::min(TexHeight, SurfHeight);
return ReturnValue(static_cast<size_t>(Min));
}
case UR_DEVICE_INFO_IMAGE2D_MAX_WIDTH: {
// Take the smaller of maximum surface and maximum texture width.
int TexWidth = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&TexWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_WIDTH,
hDevice->get()));
assert(TexWidth >= 0);
int SurfWidth = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&SurfWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_WIDTH,
hDevice->get()));
assert(SurfWidth >= 0);
int Min = std::min(TexWidth, SurfWidth);
return ReturnValue(static_cast<size_t>(Min));
}
case UR_DEVICE_INFO_IMAGE3D_MAX_HEIGHT: {
// Take the smaller of maximum surface and maximum texture height.
int TexHeight = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&TexHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_HEIGHT,
hDevice->get()));
assert(TexHeight >= 0);
int SurfHeight = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&SurfHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_HEIGHT,
hDevice->get()));
assert(SurfHeight >= 0);
int Min = std::min(TexHeight, SurfHeight);
return ReturnValue(static_cast<size_t>(Min));
}
case UR_DEVICE_INFO_IMAGE3D_MAX_WIDTH: {
// Take the smaller of maximum surface and maximum texture width.
int TexWidth = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&TexWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_WIDTH,
hDevice->get()));
assert(TexWidth >= 0);
int SurfWidth = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&SurfWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_WIDTH,
hDevice->get()));
assert(SurfWidth >= 0);
int Min = std::min(TexWidth, SurfWidth);
return ReturnValue(static_cast<size_t>(Min));
}
case UR_DEVICE_INFO_IMAGE3D_MAX_DEPTH: {
// Take the smaller of maximum surface and maximum texture depth.
int TexDepth = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&TexDepth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_DEPTH,
hDevice->get()));
assert(TexDepth >= 0);
int SurfDepth = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&SurfDepth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_DEPTH,
hDevice->get()));
assert(SurfDepth >= 0);
int Min = std::min(TexDepth, SurfDepth);
return ReturnValue(static_cast<size_t>(Min));
}
case UR_DEVICE_INFO_IMAGE_MAX_BUFFER_SIZE: {
// Take the smaller of maximum surface and maximum texture width.
int TexWidth = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&TexWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_WIDTH,
hDevice->get()));
assert(TexWidth >= 0);
int SurfWidth = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&SurfWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE1D_WIDTH,
hDevice->get()));
assert(SurfWidth >= 0);
int Min = std::min(TexWidth, SurfWidth);
return ReturnValue(static_cast<size_t>(Min));
}
case UR_DEVICE_INFO_IMAGE_MAX_ARRAY_SIZE: {
return ReturnValue(size_t(0));
}
case UR_DEVICE_INFO_MAX_SAMPLERS: {
// This call is kind of meaningless for cuda, as samplers don't exist.
// Closest thing is textures, which is 128.
return ReturnValue(128u);
}
case UR_DEVICE_INFO_MAX_PARAMETER_SIZE: {
// https://docs.nvidia.com/cuda/cuda-c-programming-guide/#function-parameters
// __global__ function parameters are passed to the device via constant
// memory and are limited to 4 KB.
return ReturnValue(size_t(4000));
}
case UR_DEVICE_INFO_MEM_BASE_ADDR_ALIGN: {
int MemBaseAddrAlign = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(&MemBaseAddrAlign,
CU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT,
hDevice->get()));
// Multiply by 8 as clGetDeviceInfo returns this value in bits
MemBaseAddrAlign *= 8;
return ReturnValue(MemBaseAddrAlign);
}
case UR_DEVICE_INFO_HALF_FP_CONFIG: {
// TODO: is this config consistent across all NVIDIA GPUs?
return ReturnValue(0u);
}
case UR_DEVICE_INFO_SINGLE_FP_CONFIG: {
// TODO: is this config consistent across all NVIDIA GPUs?
ur_device_fp_capability_flags_t Config =
UR_DEVICE_FP_CAPABILITY_FLAG_DENORM |
UR_DEVICE_FP_CAPABILITY_FLAG_INF_NAN |
UR_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_NEAREST |
UR_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_ZERO |
UR_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_INF |
UR_DEVICE_FP_CAPABILITY_FLAG_FMA |
UR_DEVICE_FP_CAPABILITY_FLAG_CORRECTLY_ROUNDED_DIVIDE_SQRT;
return ReturnValue(Config);
}
case UR_DEVICE_INFO_DOUBLE_FP_CONFIG: {
// TODO: is this config consistent across all NVIDIA GPUs?
ur_device_fp_capability_flags_t Config =
UR_DEVICE_FP_CAPABILITY_FLAG_DENORM |
UR_DEVICE_FP_CAPABILITY_FLAG_INF_NAN |
UR_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_NEAREST |
UR_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_ZERO |
UR_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_INF |
UR_DEVICE_FP_CAPABILITY_FLAG_FMA;
return ReturnValue(Config);
}
case UR_DEVICE_INFO_GLOBAL_MEM_CACHE_TYPE: {
// TODO: is this config consistent across all NVIDIA GPUs?
return ReturnValue(UR_DEVICE_MEM_CACHE_TYPE_READ_WRITE_CACHE);
}
case UR_DEVICE_INFO_GLOBAL_MEM_CACHELINE_SIZE: {
// The value is documented for all existing GPUs in the CUDA programming
// guidelines, section "H.3.2. Global Memory".
return ReturnValue(128u);
}
case UR_DEVICE_INFO_GLOBAL_MEM_CACHE_SIZE: {
int CacheSize = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&CacheSize, CU_DEVICE_ATTRIBUTE_L2_CACHE_SIZE, hDevice->get()));
assert(CacheSize >= 0);
// The L2 cache is global to the GPU.
return ReturnValue(static_cast<uint64_t>(CacheSize));
}
case UR_DEVICE_INFO_GLOBAL_MEM_SIZE: {
size_t Bytes = 0;
// Runtime API has easy access to this value, driver API info is scarse.
UR_CHECK_ERROR(cuDeviceTotalMem(&Bytes, hDevice->get()));
return ReturnValue(uint64_t{Bytes});
}
case UR_DEVICE_INFO_MAX_CONSTANT_BUFFER_SIZE: {
int ConstantMemory = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&ConstantMemory, CU_DEVICE_ATTRIBUTE_TOTAL_CONSTANT_MEMORY,
hDevice->get()));
assert(ConstantMemory >= 0);
return ReturnValue(static_cast<uint64_t>(ConstantMemory));
}
case UR_DEVICE_INFO_MAX_CONSTANT_ARGS: {
// TODO: is there a way to retrieve this from CUDA driver API?
// Hard coded to value returned by clinfo for OpenCL 1.2 CUDA | GeForce GTX
// 1060 3GB
return ReturnValue(9u);
}
case UR_DEVICE_INFO_LOCAL_MEM_TYPE: {
return ReturnValue(UR_DEVICE_LOCAL_MEM_TYPE_LOCAL);
}
case UR_DEVICE_INFO_LOCAL_MEM_SIZE: {
// OpenCL's "local memory" maps most closely to CUDA's "shared memory".
// CUDA has its own definition of "local memory", which maps to OpenCL's
// "private memory".
if (hDevice->maxLocalMemSizeChosen()) {
return ReturnValue(
static_cast<uint64_t>(hDevice->getMaxChosenLocalMem()));
} else {
return ReturnValue(
static_cast<uint64_t>(hDevice->getMaxCapacityLocalMem()));
}
}
case UR_DEVICE_INFO_ERROR_CORRECTION_SUPPORT: {
int ECCEnabled = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&ECCEnabled, CU_DEVICE_ATTRIBUTE_ECC_ENABLED, hDevice->get()));
assert((ECCEnabled == 0) | (ECCEnabled == 1));
auto Result = static_cast<bool>(ECCEnabled);
return ReturnValue(Result);
}
case UR_DEVICE_INFO_HOST_UNIFIED_MEMORY: {
int IsIntegrated = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&IsIntegrated, CU_DEVICE_ATTRIBUTE_INTEGRATED, hDevice->get()));
assert((IsIntegrated == 0) | (IsIntegrated == 1));
auto result = static_cast<bool>(IsIntegrated);
return ReturnValue(result);
}
case UR_DEVICE_INFO_PROFILING_TIMER_RESOLUTION: {
// Hard coded to value returned by clinfo for OpenCL 1.2 CUDA | GeForce GTX
// 1060 3GB
return ReturnValue(size_t(1000));
}
case UR_DEVICE_INFO_ENDIAN_LITTLE: {
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_AVAILABLE: {
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_BUILD_ON_SUBDEVICE: {
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_COMPILER_AVAILABLE: {
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_LINKER_AVAILABLE: {
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_EXECUTION_CAPABILITIES: {
auto Capability = ur_device_exec_capability_flags_t{
UR_DEVICE_EXEC_CAPABILITY_FLAG_KERNEL};
return ReturnValue(Capability);
}
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_QUEUE_ON_DEVICE_PROPERTIES: {
return ReturnValue(0);
}
case UR_DEVICE_INFO_QUEUE_ON_HOST_PROPERTIES: {
// The mandated minimum capability:
ur_queue_flags_t Capability = UR_QUEUE_FLAG_PROFILING_ENABLE;
return ReturnValue(Capability);
}
case UR_DEVICE_INFO_BUILT_IN_KERNELS: {
// An empty string is returned if no built-in kernels are supported by the
// device.
return ReturnValue("");
}
case UR_DEVICE_INFO_PLATFORM: {
return ReturnValue(hDevice->getPlatform());
}
case UR_DEVICE_INFO_NAME: {
static constexpr size_t MaxDeviceNameLength = 256u;
char Name[MaxDeviceNameLength];
UR_CHECK_ERROR(cuDeviceGetName(Name, MaxDeviceNameLength, hDevice->get()));
return ReturnValue(Name, strlen(Name) + 1);
}
case UR_DEVICE_INFO_VENDOR: {
return ReturnValue("NVIDIA Corporation");
}
case UR_DEVICE_INFO_DRIVER_VERSION: {
auto Version = getCudaVersionString();
return ReturnValue(Version.c_str());
}
case UR_DEVICE_INFO_PROFILE: {
return ReturnValue("CUDA");
}
case UR_DEVICE_INFO_REFERENCE_COUNT: {
return ReturnValue(hDevice->getReferenceCount());
}
case UR_DEVICE_INFO_VERSION: {
std::stringstream SS;
int Major;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, hDevice->get()));
SS << Major;
int Minor;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&Minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, hDevice->get()));
SS << "." << Minor;
return ReturnValue(SS.str().c_str());
}
case UR_EXT_DEVICE_INFO_OPENCL_C_VERSION: {
return ReturnValue("");
}
case UR_DEVICE_INFO_EXTENSIONS: {
std::string SupportedExtensions = "cl_khr_fp64 ";
int Major = 0;
int Minor = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, hDevice->get()));
UR_CHECK_ERROR(cuDeviceGetAttribute(
&Minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, hDevice->get()));
if ((Major >= 6) || ((Major == 5) && (Minor >= 3))) {
SupportedExtensions += "cl_khr_fp16 ";
}
return ReturnValue(SupportedExtensions.c_str());
}
case UR_DEVICE_INFO_PRINTF_BUFFER_SIZE: {
// The minimum value for the FULL profile is 1 MB.
return ReturnValue(size_t(1024));
}
case UR_DEVICE_INFO_PREFERRED_INTEROP_USER_SYNC: {
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_PARENT_DEVICE: {
return ReturnValue(nullptr);
}
case UR_DEVICE_INFO_PARTITION_MAX_SUB_DEVICES: {
return ReturnValue(0u);
}
case UR_DEVICE_INFO_SUPPORTED_PARTITIONS: {
if (pPropSizeRet) {
*pPropSizeRet = 0;
}
return UR_RESULT_SUCCESS;
}
case UR_DEVICE_INFO_PARTITION_AFFINITY_DOMAIN: {
return ReturnValue(0u);
}
case UR_DEVICE_INFO_PARTITION_TYPE: {
if (pPropSizeRet) {
*pPropSizeRet = 0;
}
return UR_RESULT_SUCCESS;
}
// Intel USM extensions
case UR_DEVICE_INFO_USM_HOST_SUPPORT: {
// from cl_intel_unified_shared_memory: "The host memory access capabilities
// apply to any host allocation."
//
// query if/how the device can access page-locked host memory, possibly
// through PCIe, using the same pointer as the host
uint32_t Value = {};
if (getAttribute(hDevice, CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING)) {
// the device shares a unified address space with the host
if (getAttribute(hDevice, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR) >=
6) {
// compute capability 6.x introduces operations that are atomic with
// respect to other CPUs and GPUs in the system
Value = UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS |
UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ATOMIC_ACCESS |
UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_CONCURRENT_ACCESS;
} else {
// on GPU architectures with compute capability lower than 6.x, atomic
// operations from the GPU to CPU memory will not be atomic with respect
// to CPU initiated atomic operations
Value = UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS |
UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_CONCURRENT_ACCESS;
}
}
return ReturnValue(Value);
}
case UR_DEVICE_INFO_USM_DEVICE_SUPPORT: {
// from cl_intel_unified_shared_memory:
// "The device memory access capabilities apply to any device allocation
// associated with this device."
//
// query how the device can access memory allocated on the device itself (?)
uint32_t Value =
UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS |
UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ATOMIC_ACCESS |
UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_CONCURRENT_ACCESS |
UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ATOMIC_CONCURRENT_ACCESS;
return ReturnValue(Value);
}
case UR_DEVICE_INFO_USM_SINGLE_SHARED_SUPPORT: {
// from cl_intel_unified_shared_memory:
// "The single device shared memory access capabilities apply to any shared
// allocation associated with this device."
//
// query if/how the device can access managed memory associated to it
uint32_t Value = {};
if (getAttribute(hDevice, CU_DEVICE_ATTRIBUTE_MANAGED_MEMORY)) {
// the device can allocate managed memory on this system
Value = UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS |
UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ATOMIC_ACCESS;
}
if (getAttribute(hDevice, CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS)) {
// the device can coherently access managed memory concurrently with the
// CPU
Value |= UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_CONCURRENT_ACCESS;
if (getAttribute(hDevice, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR) >=
6) {
// compute capability 6.x introduces operations that are atomic with
// respect to other CPUs and GPUs in the system
Value |= UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ATOMIC_CONCURRENT_ACCESS;
}
}
return ReturnValue(Value);
}
case UR_DEVICE_INFO_USM_CROSS_SHARED_SUPPORT: {
// from cl_intel_unified_shared_memory:
// "The cross-device shared memory access capabilities apply to any shared
// allocation associated with this device, or to any shared memory
// allocation on another device that also supports the same cross-device
// shared memory access capability."
//
// query if/how the device can access managed memory associated to other
// devices
uint32_t Value = {};
if (getAttribute(hDevice, CU_DEVICE_ATTRIBUTE_MANAGED_MEMORY)) {
// the device can allocate managed memory on this system
Value |= UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS;
}
if (getAttribute(hDevice, CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS)) {
// all devices with the CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS
// attribute can coherently access managed memory concurrently with the
// CPU
Value |= UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_CONCURRENT_ACCESS;
}
if (getAttribute(hDevice, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR) >=
6) {
// compute capability 6.x introduces operations that are atomic with
// respect to other CPUs and GPUs in the system
if (Value & UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS)
Value |= UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ATOMIC_ACCESS;
if (Value & UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_CONCURRENT_ACCESS)
Value |= UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ATOMIC_CONCURRENT_ACCESS;
}
return ReturnValue(Value);
}
case UR_DEVICE_INFO_USM_SYSTEM_SHARED_SUPPORT: {
// from cl_intel_unified_shared_memory:
// "The shared system memory access capabilities apply to any allocations
// made by a system allocator, such as malloc or new."
//
// query if/how the device can access pageable host memory allocated by the
// system allocator
uint32_t Value = {};
if (getAttribute(hDevice, CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS)) {
// the device suppports coherently accessing pageable memory without
// calling cuMemHostRegister/cudaHostRegister on it
if (getAttribute(hDevice,
CU_DEVICE_ATTRIBUTE_HOST_NATIVE_ATOMIC_SUPPORTED)) {
// the link between the device and the host supports native atomic
// operations
Value = UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS |
UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ATOMIC_ACCESS |
UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_CONCURRENT_ACCESS |
UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ATOMIC_CONCURRENT_ACCESS;
} else {
// the link between the device and the host does not support native
// atomic operations
Value = UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS |
UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_CONCURRENT_ACCESS;
}
}
return ReturnValue(Value);
}
case UR_DEVICE_INFO_ASYNC_BARRIER: {
int Value = getAttribute(hDevice,
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR) >= 8;
return ReturnValue(static_cast<bool>(Value));
}
case UR_DEVICE_INFO_BACKEND_RUNTIME_VERSION: {
int Major =
getAttribute(hDevice, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR);
int Minor =
getAttribute(hDevice, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR);
std::string Result = std::to_string(Major) + "." + std::to_string(Minor);
return ReturnValue(Result.c_str());
}
case UR_DEVICE_INFO_GLOBAL_MEM_FREE: {
size_t FreeMemory = 0;
size_t TotalMemory = 0;
UR_CHECK_ERROR(cuMemGetInfo(&FreeMemory, &TotalMemory));
return ReturnValue(FreeMemory);
}
case UR_DEVICE_INFO_MEMORY_CLOCK_RATE: {
int Value = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&Value, CU_DEVICE_ATTRIBUTE_MEMORY_CLOCK_RATE, hDevice->get()));
assert(Value >= 0);
// Convert kilohertz to megahertz when returning.
return ReturnValue(Value / 1000);
}
case UR_DEVICE_INFO_MEMORY_BUS_WIDTH: {
int Value = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&Value, CU_DEVICE_ATTRIBUTE_GLOBAL_MEMORY_BUS_WIDTH, hDevice->get()));
assert(Value >= 0);
return ReturnValue(Value);
}
case UR_DEVICE_INFO_MAX_COMPUTE_QUEUE_INDICES: {
return ReturnValue(int32_t{1});
}
case UR_DEVICE_INFO_BINDLESS_IMAGES_SUPPORT_EXP: {
// On CUDA bindless images are supported.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_BINDLESS_IMAGES_SHARED_USM_SUPPORT_EXP: {
// On CUDA bindless images can be backed by shared (managed) USM.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_BINDLESS_IMAGES_1D_USM_SUPPORT_EXP: {
// On CUDA 1D bindless image USM is supported, but sampling is not.
// More specifically, linear filtering is not supported.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_BINDLESS_IMAGES_2D_USM_SUPPORT_EXP: {
// On CUDA 2D bindless image USM is supported.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_IMAGE_PITCH_ALIGN_EXP: {
int32_t tex_pitch_align = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&tex_pitch_align, CU_DEVICE_ATTRIBUTE_TEXTURE_PITCH_ALIGNMENT,
hDevice->get()));
return ReturnValue(tex_pitch_align);
}
case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_WIDTH_EXP: {
int32_t tex_max_linear_width = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&tex_max_linear_width,
CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_WIDTH, hDevice->get()));
return ReturnValue(static_cast<size_t>(tex_max_linear_width));
}
case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_HEIGHT_EXP: {
int32_t tex_max_linear_height = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&tex_max_linear_height,
CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_HEIGHT, hDevice->get()));
return ReturnValue(static_cast<size_t>(tex_max_linear_height));
}
case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_PITCH_EXP: {
int32_t tex_max_linear_pitch = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&tex_max_linear_pitch,
CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_PITCH, hDevice->get()));
return ReturnValue(static_cast<size_t>(tex_max_linear_pitch));
}
case UR_DEVICE_INFO_MIPMAP_SUPPORT_EXP: {
// CUDA supports mipmaps.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_MIPMAP_ANISOTROPY_SUPPORT_EXP: {
// CUDA supports anisotropic filtering.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_MIPMAP_MAX_ANISOTROPY_EXP: {
// CUDA has no query for this, but documentation states max value is 16.
return ReturnValue(16.f);
}
case UR_DEVICE_INFO_MIPMAP_LEVEL_REFERENCE_SUPPORT_EXP: {
// CUDA supports creation of images from individual mipmap levels.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_EXTERNAL_MEMORY_IMPORT_SUPPORT_EXP: {
// CUDA supports importing external memory.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_EXTERNAL_SEMAPHORE_IMPORT_SUPPORT_EXP: {
// CUDA supports importing external semaphores.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_CUBEMAP_SUPPORT_EXP: {
// CUDA supports cubemaps.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_CUBEMAP_SEAMLESS_FILTERING_SUPPORT_EXP: {
// CUDA supports cubemap seamless filtering.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_1D_USM_SUPPORT_EXP: {
// CUDA does support fetching 1D USM sampled image data.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_1D_SUPPORT_EXP: {
// CUDA does not support fetching 1D non-USM sampled image data.
return ReturnValue(static_cast<ur_bool_t>(false));
}
case UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_2D_USM_SUPPORT_EXP: {
// CUDA does support fetching 2D USM sampled image data.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_2D_SUPPORT_EXP: {
// CUDA does support fetching 2D non-USM sampled image data.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_3D_SUPPORT_EXP: {
// CUDA does support fetching 3D non-USM sampled image data.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_IMAGE_ARRAY_SUPPORT_EXP: {
// CUDA does support image arrays
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_BINDLESS_UNIQUE_ADDRESSING_PER_DIM_SUPPORT_EXP: {
// CUDA does support unique addressing per dimension
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_BINDLESS_SAMPLE_1D_USM_SUPPORT_EXP: {
// CUDA does not support sampling 1D USM sampled image data.
return ReturnValue(static_cast<ur_bool_t>(false));
}
case UR_DEVICE_INFO_BINDLESS_SAMPLE_2D_USM_SUPPORT_EXP: {
// CUDA does support sampling 1D USM sampled image data.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_BINDLESS_IMAGES_GATHER_SUPPORT_EXP: {
// CUDA does support sampled image gather.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_TIMESTAMP_RECORDING_SUPPORT_EXP: {
// CUDA supports recording timestamp events.
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_ENQUEUE_NATIVE_COMMAND_SUPPORT_EXP: {
// CUDA supports enqueueing native work through the urNativeEnqueueExp
return ReturnValue(static_cast<ur_bool_t>(true));
}
case UR_DEVICE_INFO_DEVICE_ID: {
int Value = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&Value, CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID, hDevice->get()));
assert(Value >= 0);
return ReturnValue(Value);
}
case UR_DEVICE_INFO_UUID: {
CUuuid UUID;
#if (CUDA_VERSION >= 11040)
UR_CHECK_ERROR(cuDeviceGetUuid_v2(&UUID, hDevice->get()));
#else
UR_CHECK_ERROR(cuDeviceGetUuid(&UUID, hDevice->get()));
#endif
std::array<unsigned char, 16> Name;
std::copy(UUID.bytes, UUID.bytes + 16, Name.begin());
return ReturnValue(Name.data(), 16);
}
case UR_DEVICE_INFO_MAX_MEMORY_BANDWIDTH: {
int Major = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, hDevice->get()));
int Minor = 0;
UR_CHECK_ERROR(cuDeviceGetAttribute(
&Minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, hDevice->get()));
// Some specific devices seem to need special handling. See reference
// https://github.com/jeffhammond/HPCInfo/blob/master/cuda/gpu-detect.cu
bool IsXavierAGX = Major == 7 && Minor == 2;
bool IsOrinAGX = Major == 8 && Minor == 7;
int MemoryClockKHz = 0;
if (IsXavierAGX) {
MemoryClockKHz = 2133000;
} else if (IsOrinAGX) {
MemoryClockKHz = 3200000;
} else {
UR_CHECK_ERROR(cuDeviceGetAttribute(&MemoryClockKHz,
CU_DEVICE_ATTRIBUTE_MEMORY_CLOCK_RATE,
hDevice->get()));
}
int MemoryBusWidth = 0;
if (IsOrinAGX) {
MemoryBusWidth = 256;
} else {
UR_CHECK_ERROR(cuDeviceGetAttribute(
&MemoryBusWidth, CU_DEVICE_ATTRIBUTE_GLOBAL_MEMORY_BUS_WIDTH,
hDevice->get()));
}