-
Notifications
You must be signed in to change notification settings - Fork 277
Expand file tree
/
Copy path_device.pyx
More file actions
1477 lines (1210 loc) · 58.6 KB
/
_device.pyx
File metadata and controls
1477 lines (1210 loc) · 58.6 KB
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
# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
cimport cpython
from libc.stdint cimport uintptr_t
from cuda.bindings cimport cydriver
from cuda.core._utils.cuda_utils cimport HANDLE_RETURN
import threading
from cuda.core._context cimport Context
from cuda.core._context import ContextOptions
from cuda.core._event cimport Event as cyEvent
from cuda.core._event import Event, EventOptions
from cuda.core._resource_handles cimport (
ContextHandle,
create_context_handle_ref,
get_primary_context,
as_cu,
)
from cuda.core._graph import GraphBuilder
from cuda.core._stream import IsStreamT, Stream, StreamOptions
from cuda.core._utils.clear_error_support import assert_type
from cuda.core._utils.cuda_utils import (
ComputeCapability,
CUDAError,
driver,
handle_return,
runtime,
)
from cuda.core._stream cimport default_stream
# TODO: I prefer to type these as "cdef object" and avoid accessing them from within Python,
# but it seems it is very convenient to expose them for testing purposes...
_tls = threading.local()
_lock = threading.Lock()
cdef bint _is_cuInit = False
cdef class DeviceProperties:
"""
A class to query various attributes of a CUDA device.
Attributes are read-only and provide information about the device.
"""
cdef:
int _handle
dict _cache
def __init__(self, *args, **kwargs):
raise RuntimeError("DeviceProperties cannot be instantiated directly. Please use Device APIs.")
@classmethod
def _init(cls, handle):
cdef DeviceProperties self = DeviceProperties.__new__(cls)
self._handle = handle
self._cache = {}
return self
cdef inline int _get_attribute(self, cydriver.CUdevice_attribute attr, default=0) except? -2:
"""Retrieve the attribute value directly from the driver."""
cdef int val
cdef cydriver.CUresult err
with nogil:
err = cydriver.cuDeviceGetAttribute(&val, attr, self._handle)
if err == cydriver.CUresult.CUDA_ERROR_INVALID_VALUE and default is not None:
return <int>default
HANDLE_RETURN(err)
return val
cdef inline int _get_cached_attribute(self, attr, default=0) except? -2:
"""Retrieve the attribute value, using cache if applicable."""
if attr not in self._cache:
self._cache[attr] = self._get_attribute(attr, default)
return self._cache[attr]
@property
def max_threads_per_block(self) -> int:
"""int: Maximum number of threads per block."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK)
@property
def max_block_dim_x(self) -> int:
"""int: Maximum block dimension X."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_X)
@property
def max_block_dim_y(self) -> int:
"""int: Maximum block dimension Y."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Y)
@property
def max_block_dim_z(self) -> int:
"""int: Maximum block dimension Z."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Z)
@property
def max_grid_dim_x(self) -> int:
"""int: Maximum grid dimension X."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_X)
@property
def max_grid_dim_y(self) -> int:
"""int: Maximum grid dimension Y."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Y)
@property
def max_grid_dim_z(self) -> int:
"""int: Maximum grid dimension Z."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Z)
@property
def max_shared_memory_per_block(self) -> int:
"""int: Maximum shared memory available per block in bytes."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK)
@property
def total_constant_memory(self) -> int:
"""int: Memory available on device for constant variables in a CUDA C kernel in bytes."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_TOTAL_CONSTANT_MEMORY)
@property
def warp_size(self) -> int:
"""int: Warp size in threads."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_WARP_SIZE)
@property
def max_pitch(self) -> int:
"""int: Maximum pitch in bytes allowed by memory copies."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_PITCH)
@property
def maximum_texture1d_width(self) -> int:
"""int: Maximum 1D texture width."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_WIDTH)
@property
def maximum_texture1d_linear_width(self) -> int:
"""int: Maximum width for a 1D texture bound to linear memory."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_LINEAR_WIDTH)
@property
def maximum_texture1d_mipmapped_width(self) -> int:
"""int: Maximum mipmapped 1D texture width."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_MIPMAPPED_WIDTH
)
@property
def maximum_texture2d_width(self) -> int:
"""int: Maximum 2D texture width."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_WIDTH)
@property
def maximum_texture2d_height(self) -> int:
"""int: Maximum 2D texture height."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_HEIGHT)
@property
def maximum_texture2d_linear_width(self) -> int:
"""int: Maximum width for a 2D texture bound to linear memory."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_WIDTH)
@property
def maximum_texture2d_linear_height(self) -> int:
"""int: Maximum height for a 2D texture bound to linear memory."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_HEIGHT)
@property
def maximum_texture2d_linear_pitch(self) -> int:
"""int: Maximum pitch in bytes for a 2D texture bound to linear memory."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_PITCH)
@property
def maximum_texture2d_mipmapped_width(self) -> int:
"""int: Maximum mipmapped 2D texture width."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_MIPMAPPED_WIDTH
)
@property
def maximum_texture2d_mipmapped_height(self) -> int:
"""int: Maximum mipmapped 2D texture height."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_MIPMAPPED_HEIGHT
)
@property
def maximum_texture3d_width(self) -> int:
"""int: Maximum 3D texture width."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_WIDTH)
@property
def maximum_texture3d_height(self) -> int:
"""int: Maximum 3D texture height."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_HEIGHT)
@property
def maximum_texture3d_depth(self) -> int:
"""int: Maximum 3D texture depth."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_DEPTH)
@property
def maximum_texture3d_width_alternate(self) -> int:
"""int: Alternate maximum 3D texture width, 0 if no alternate maximum 3D texture size is supported."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_WIDTH_ALTERNATE
)
@property
def maximum_texture3d_height_alternate(self) -> int:
"""int: Alternate maximum 3D texture height, 0 if no alternate maximum 3D texture size is supported."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_HEIGHT_ALTERNATE
)
@property
def maximum_texture3d_depth_alternate(self) -> int:
"""int: Alternate maximum 3D texture depth, 0 if no alternate maximum 3D texture size is supported."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_DEPTH_ALTERNATE
)
@property
def maximum_texturecubemap_width(self) -> int:
"""int: Maximum cubemap texture width or height."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURECUBEMAP_WIDTH)
@property
def maximum_texture1d_layered_width(self) -> int:
"""int: Maximum 1D layered texture width."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_LAYERED_WIDTH)
@property
def maximum_texture1d_layered_layers(self) -> int:
"""int: Maximum layers in a 1D layered texture."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_LAYERED_LAYERS
)
@property
def maximum_texture2d_layered_width(self) -> int:
"""int: Maximum 2D layered texture width."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LAYERED_WIDTH)
@property
def maximum_texture2d_layered_height(self) -> int:
"""int: Maximum 2D layered texture height."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LAYERED_HEIGHT
)
@property
def maximum_texture2d_layered_layers(self) -> int:
"""int: Maximum layers in a 2D layered texture."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LAYERED_LAYERS
)
@property
def maximum_texturecubemap_layered_width(self) -> int:
"""int: Maximum cubemap layered texture width or height."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURECUBEMAP_LAYERED_WIDTH
)
@property
def maximum_texturecubemap_layered_layers(self) -> int:
"""int: Maximum layers in a cubemap layered texture."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURECUBEMAP_LAYERED_LAYERS
)
@property
def maximum_surface1d_width(self) -> int:
"""int: Maximum 1D surface width."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE1D_WIDTH)
@property
def maximum_surface2d_width(self) -> int:
"""int: Maximum 2D surface width."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_WIDTH)
@property
def maximum_surface2d_height(self) -> int:
"""int: Maximum 2D surface height."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_HEIGHT)
@property
def maximum_surface3d_width(self) -> int:
"""int: Maximum 3D surface width."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_WIDTH)
@property
def maximum_surface3d_height(self) -> int:
"""int: Maximum 3D surface height."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_HEIGHT)
@property
def maximum_surface3d_depth(self) -> int:
"""int: Maximum 3D surface depth."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_DEPTH)
@property
def maximum_surface1d_layered_width(self) -> int:
"""int: Maximum 1D layered surface width."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE1D_LAYERED_WIDTH)
@property
def maximum_surface1d_layered_layers(self) -> int:
"""int: Maximum layers in a 1D layered surface."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE1D_LAYERED_LAYERS
)
@property
def maximum_surface2d_layered_width(self) -> int:
"""int: Maximum 2D layered surface width."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_LAYERED_WIDTH)
@property
def maximum_surface2d_layered_height(self) -> int:
"""int: Maximum 2D layered surface height."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_LAYERED_HEIGHT
)
@property
def maximum_surface2d_layered_layers(self) -> int:
"""int: Maximum layers in a 2D layered surface."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_LAYERED_LAYERS
)
@property
def maximum_surfacecubemap_width(self) -> int:
"""int: Maximum cubemap surface width."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACECUBEMAP_WIDTH)
@property
def maximum_surfacecubemap_layered_width(self) -> int:
"""int: Maximum cubemap layered surface width."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACECUBEMAP_LAYERED_WIDTH
)
@property
def maximum_surfacecubemap_layered_layers(self) -> int:
"""int: Maximum layers in a cubemap layered surface."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACECUBEMAP_LAYERED_LAYERS
)
@property
def max_registers_per_block(self) -> int:
"""int: Maximum number of 32-bit registers available to a thread block."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_BLOCK)
@property
def clock_rate(self) -> int:
"""int: Typical clock frequency in kilohertz."""
return self._get_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_CLOCK_RATE)
@property
def texture_alignment(self) -> int:
"""int: Alignment requirement for textures."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT)
@property
def texture_pitch_alignment(self) -> int:
"""int: Pitch alignment requirement for textures."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_TEXTURE_PITCH_ALIGNMENT)
@property
def gpu_overlap(self) -> bool:
"""bool: Device can possibly copy memory and execute a kernel concurrently. Deprecated. Use instead async_engine_count."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_GPU_OVERLAP))
@property
def multiprocessor_count(self) -> int:
"""int: Number of multiprocessors on device."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT)
@property
def kernel_exec_timeout(self) -> bool:
"""bool: Specifies whether there is a run time limit on kernels."""
return bool(self._get_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_KERNEL_EXEC_TIMEOUT))
@property
def integrated(self) -> bool:
"""bool: Device is integrated with host memory."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_INTEGRATED))
@property
def can_map_host_memory(self) -> bool:
"""bool: Device can map host memory into CUDA address space."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_CAN_MAP_HOST_MEMORY))
@property
def compute_mode(self) -> int:
"""int: Compute mode (See CUcomputemode for details)."""
return self._get_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_COMPUTE_MODE)
@property
def concurrent_kernels(self) -> bool:
"""bool: Device can possibly execute multiple kernels concurrently."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_CONCURRENT_KERNELS))
@property
def ecc_enabled(self) -> bool:
"""bool: Device has ECC support enabled."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_ECC_ENABLED))
@property
def pci_bus_id(self) -> int:
"""int: PCI bus ID of the device."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_PCI_BUS_ID)
@property
def pci_device_id(self) -> int:
"""int: PCI device ID of the device."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID)
@property
def pci_domain_id(self) -> int:
"""int: PCI domain ID of the device."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_PCI_DOMAIN_ID)
@property
def tcc_driver(self) -> bool:
"""bool: Device is using TCC driver model."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_TCC_DRIVER))
@property
def memory_clock_rate(self) -> int:
"""int: Peak memory clock frequency in kilohertz."""
return self._get_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MEMORY_CLOCK_RATE)
@property
def global_memory_bus_width(self) -> int:
"""int: Global memory bus width in bits."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_GLOBAL_MEMORY_BUS_WIDTH)
@property
def l2_cache_size(self) -> int:
"""int: Size of L2 cache in bytes."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_L2_CACHE_SIZE)
@property
def max_threads_per_multiprocessor(self) -> int:
"""int: Maximum resident threads per multiprocessor."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_MULTIPROCESSOR)
@property
def unified_addressing(self) -> bool:
"""bool: Device shares a unified address space with the host."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING))
@property
def compute_capability_major(self) -> int:
"""int: Major compute capability version number."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR)
@property
def compute_capability_minor(self) -> int:
"""int: Minor compute capability version number."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR)
@property
def global_l1_cache_supported(self) -> bool:
"""bool: Device supports caching globals in L1."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_GLOBAL_L1_CACHE_SUPPORTED))
@property
def local_l1_cache_supported(self) -> bool:
"""bool: Device supports caching locals in L1."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_LOCAL_L1_CACHE_SUPPORTED))
@property
def max_shared_memory_per_multiprocessor(self) -> int:
"""int: Maximum shared memory available per multiprocessor in bytes."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_MULTIPROCESSOR
)
@property
def max_registers_per_multiprocessor(self) -> int:
"""int: Maximum number of 32-bit registers available per multiprocessor."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_MULTIPROCESSOR
)
@property
def managed_memory(self) -> bool:
"""bool: Device can allocate managed memory on this system."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MANAGED_MEMORY))
@property
def multi_gpu_board(self) -> bool:
"""bool: Device is on a multi-GPU board."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MULTI_GPU_BOARD))
@property
def multi_gpu_board_group_id(self) -> int:
"""int: Unique id for a group of devices on the same multi-GPU board."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MULTI_GPU_BOARD_GROUP_ID)
@property
def host_native_atomic_supported(self) -> bool:
"""bool: Link between the device and the host supports all native atomic operations."""
return bool(
self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_HOST_NATIVE_ATOMIC_SUPPORTED)
)
@property
def single_to_double_precision_perf_ratio(self) -> int:
"""int: Ratio of single precision performance (in floating-point operations per second) to double precision performance."""
return self._get_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_SINGLE_TO_DOUBLE_PRECISION_PERF_RATIO)
@property
def pageable_memory_access(self) -> bool:
"""bool: Device supports coherently accessing pageable memory without calling cudaHostRegister on it."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS))
@property
def concurrent_managed_access(self) -> bool:
"""bool: Device can coherently access managed memory concurrently with the CPU."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS))
@property
def compute_preemption_supported(self) -> bool:
"""bool: Device supports compute preemption."""
return bool(
self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_COMPUTE_PREEMPTION_SUPPORTED)
)
@property
def can_use_host_pointer_for_registered_mem(self) -> bool:
"""bool: Device can access host registered memory at the same virtual address as the CPU."""
return bool(
self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_CAN_USE_HOST_POINTER_FOR_REGISTERED_MEM
)
)
# TODO: A few attrs are missing here (NVIDIA/cuda-python#675)
@property
def cooperative_launch(self) -> bool:
"""bool: Device supports launching cooperative kernels via cuLaunchCooperativeKernel."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_COOPERATIVE_LAUNCH))
# TODO: A few attrs are missing here (NVIDIA/cuda-python#675)
@property
def max_shared_memory_per_block_optin(self) -> int:
"""int: Maximum optin shared memory per block."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK_OPTIN
)
@property
def pageable_memory_access_uses_host_page_tables(self) -> bool:
"""bool: Device accesses pageable memory via the host's page tables."""
return bool(
self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS_USES_HOST_PAGE_TABLES
)
)
@property
def direct_managed_mem_access_from_host(self) -> bool:
"""bool: The host can directly access managed memory on the device without migration."""
return bool(
self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_DIRECT_MANAGED_MEM_ACCESS_FROM_HOST
)
)
@property
def virtual_memory_management_supported(self) -> bool:
"""bool: Device supports virtual memory management APIs like cuMemAddressReserve, cuMemCreate, cuMemMap and related APIs."""
return bool(
self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_VIRTUAL_MEMORY_MANAGEMENT_SUPPORTED
)
)
@property
def handle_type_posix_file_descriptor_supported(self) -> bool:
"""bool: Device supports exporting memory to a posix file descriptor with cuMemExportToShareableHandle, if requested via cuMemCreate."""
return bool(
self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR_SUPPORTED
)
)
@property
def handle_type_win32_handle_supported(self) -> bool:
"""bool: Device supports exporting memory to a Win32 NT handle with cuMemExportToShareableHandle, if requested via cuMemCreate."""
return bool(
self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_HANDLE_TYPE_WIN32_HANDLE_SUPPORTED)
)
@property
def handle_type_win32_kmt_handle_supported(self) -> bool:
"""bool: Device supports exporting memory to a Win32 KMT handle with cuMemExportToShareableHandle, if requested via cuMemCreate."""
return bool(
self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_HANDLE_TYPE_WIN32_KMT_HANDLE_SUPPORTED
)
)
@property
def max_blocks_per_multiprocessor(self) -> int:
"""int: Maximum number of blocks per multiprocessor."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_BLOCKS_PER_MULTIPROCESSOR)
@property
def generic_compression_supported(self) -> bool:
"""bool: Device supports compression of memory."""
return bool(
self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_GENERIC_COMPRESSION_SUPPORTED)
)
@property
def max_persisting_l2_cache_size(self) -> int:
"""int: Maximum L2 persisting lines capacity setting in bytes."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_PERSISTING_L2_CACHE_SIZE)
@property
def max_access_policy_window_size(self) -> int:
"""int: Maximum value of CUaccessPolicyWindow.num_bytes."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_ACCESS_POLICY_WINDOW_SIZE)
@property
def gpu_direct_rdma_with_cuda_vmm_supported(self) -> bool:
"""bool: Device supports specifying the GPUDirect RDMA flag with cuMemCreate."""
return bool(
self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_GPU_DIRECT_RDMA_WITH_CUDA_VMM_SUPPORTED
)
)
@property
def reserved_shared_memory_per_block(self) -> int:
"""int: Shared memory reserved by CUDA driver per block in bytes."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_RESERVED_SHARED_MEMORY_PER_BLOCK
)
@property
def sparse_cuda_array_supported(self) -> bool:
"""bool: Device supports sparse CUDA arrays and sparse CUDA mipmapped arrays."""
return bool(
self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_SPARSE_CUDA_ARRAY_SUPPORTED)
)
@property
def read_only_host_register_supported(self) -> bool:
"""bool: True if device supports using the cuMemHostRegister flag CU_MEMHOSTERGISTER_READ_ONLY to register memory that must be mapped as read-only to the GPU, False if not."""
return bool(
self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_READ_ONLY_HOST_REGISTER_SUPPORTED)
)
@property
def memory_pools_supported(self) -> bool:
"""bool: Device supports using the cuMemAllocAsync and cuMemPool family of APIs."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MEMORY_POOLS_SUPPORTED))
@property
def gpu_direct_rdma_supported(self) -> bool:
"""bool: Device supports GPUDirect RDMA APIs, like nvidia_p2p_get_pages (see https://docs.nvidia.com/cuda/gpudirect-rdma for more information)."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_GPU_DIRECT_RDMA_SUPPORTED))
@property
def gpu_direct_rdma_flush_writes_options(self) -> int:
"""int: The returned attribute shall be interpreted as a bitmask, where the individual bits are described by the CUflushGPUDirectRDMAWritesOptions enum."""
return self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_GPU_DIRECT_RDMA_FLUSH_WRITES_OPTIONS
)
@property
def gpu_direct_rdma_writes_ordering(self) -> int:
"""int: GPUDirect RDMA writes to the device do not need to be flushed for consumers within the scope indicated by the returned attribute. See CUGPUDirectRDMAWritesOrdering for the numerical values returned here."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_GPU_DIRECT_RDMA_WRITES_ORDERING)
@property
def mempool_supported_handle_types(self) -> int:
"""int: Handle types supported with mempool based IPC."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MEMPOOL_SUPPORTED_HANDLE_TYPES)
@property
def deferred_mapping_cuda_array_supported(self) -> bool:
"""bool: Device supports deferred mapping CUDA arrays and CUDA mipmapped arrays."""
return bool(
self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_DEFERRED_MAPPING_CUDA_ARRAY_SUPPORTED
)
)
@property
def numa_config(self) -> int:
"""int: NUMA configuration of a device: value is of type CUdeviceNumaConfig enum."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_NUMA_CONFIG)
@property
def numa_id(self) -> int:
"""int: NUMA node ID of the GPU memory."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_NUMA_ID)
@property
def multicast_supported(self) -> bool:
"""bool: Device supports switch multicast and reduction operations."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MULTICAST_SUPPORTED))
@property
def surface_alignment(self) -> int:
"""int: Surface alignment requirement in bytes."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_SURFACE_ALIGNMENT)
@property
def async_engine_count(self) -> int:
"""int: Number of asynchronous engines."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT)
@property
def can_tex2d_gather(self) -> bool:
"""bool: True if device supports 2D texture gather operations, False if not."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_CAN_TEX2D_GATHER))
@property
def maximum_texture2d_gather_width(self) -> int:
"""int: Maximum 2D texture gather width."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_GATHER_WIDTH)
@property
def maximum_texture2d_gather_height(self) -> int:
"""int: Maximum 2D texture gather height."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_GATHER_HEIGHT)
@property
def stream_priorities_supported(self) -> bool:
"""bool: True if device supports stream priorities, False if not."""
return bool(
self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_STREAM_PRIORITIES_SUPPORTED)
)
@property
def can_flush_remote_writes(self) -> bool:
"""bool: The CU_STREAM_WAIT_VALUE_FLUSH flag and the CU_STREAM_MEM_OP_FLUSH_REMOTE_WRITES MemOp are supported on the device. See Stream Memory Operations for additional details."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_CAN_FLUSH_REMOTE_WRITES))
@property
def host_register_supported(self) -> bool:
"""bool: Device supports host memory registration via cudaHostRegister."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_HOST_REGISTER_SUPPORTED))
@property
def timeline_semaphore_interop_supported(self) -> bool:
"""bool: External timeline semaphore interop is supported on the device."""
return bool(
self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_TIMELINE_SEMAPHORE_INTEROP_SUPPORTED
)
)
@property
def cluster_launch(self) -> bool:
"""bool: Indicates device supports cluster launch."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_CLUSTER_LAUNCH))
@property
def can_use_64_bit_stream_mem_ops(self) -> bool:
"""bool: 64-bit operations are supported in cuStreamBatchMemOp and related MemOp APIs."""
return bool(
self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_CAN_USE_64_BIT_STREAM_MEM_OPS)
)
@property
def can_use_stream_wait_value_nor(self) -> bool:
"""bool: CU_STREAM_WAIT_VALUE_NOR is supported by MemOp APIs."""
return bool(
self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_CAN_USE_STREAM_WAIT_VALUE_NOR)
)
@property
def dma_buf_supported(self) -> bool:
"""bool: Device supports buffer sharing with dma_buf mechanism."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_DMA_BUF_SUPPORTED))
# Start of CUDA 12 device attributes
@property
def ipc_event_supported(self) -> bool:
"""bool: Device supports IPC Events."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_IPC_EVENT_SUPPORTED))
@property
def mem_sync_domain_count(self) -> int:
"""int: Number of memory domains the device supports."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MEM_SYNC_DOMAIN_COUNT, default=1)
@property
def tensor_map_access_supported(self) -> bool:
"""bool: Device supports accessing memory using Tensor Map."""
return bool(
self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_TENSOR_MAP_ACCESS_SUPPORTED)
)
@property
def handle_type_fabric_supported(self) -> bool:
"""bool: Device supports exporting memory to a fabric handle with cuMemExportToShareableHandle() or requested with cuMemCreate()."""
return bool(
self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_HANDLE_TYPE_FABRIC_SUPPORTED)
)
@property
def unified_function_pointers(self) -> bool:
"""bool: Device supports unified function pointers."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_UNIFIED_FUNCTION_POINTERS))
@property
def mps_enabled(self) -> bool:
"""bool: Indicates if contexts created on this device will be shared via MPS."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MPS_ENABLED))
@property
def host_numa_id(self) -> int:
"""int: NUMA ID of the host node closest to the device. Returns -1 when system does not support NUMA."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_HOST_NUMA_ID, default=-1)
@property
def d3d12_cig_supported(self) -> bool:
"""bool: Device supports CIG with D3D12."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_D3D12_CIG_SUPPORTED))
@property
def mem_decompress_algorithm_mask(self) -> int:
"""int: The returned valued shall be interpreted as a bitmask, where the individual bits are described by the CUmemDecompressAlgorithm enum."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MEM_DECOMPRESS_ALGORITHM_MASK)
@property
def mem_decompress_maximum_length(self) -> int:
"""int: The returned valued is the maximum length in bytes of a single decompress operation that is allowed."""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MEM_DECOMPRESS_MAXIMUM_LENGTH)
@property
def vulkan_cig_supported(self) -> bool:
"""bool: Device supports CIG with Vulkan."""
return bool(self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_VULKAN_CIG_SUPPORTED))
@property
def gpu_pci_device_id(self) -> int:
"""int: The combined 16-bit PCI device ID and 16-bit PCI vendor ID.
Returns 0 if the driver does not support this query.
"""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_GPU_PCI_DEVICE_ID)
@property
def gpu_pci_subsystem_id(self) -> int:
"""int: The combined 16-bit PCI subsystem ID and 16-bit PCI subsystem vendor ID.
Returns 0 if the driver does not support this query.
"""
return self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_GPU_PCI_SUBSYSTEM_ID)
@property
def host_numa_virtual_memory_management_supported(self) -> bool:
"""bool: Device supports HOST_NUMA location with the virtual memory management APIs like cuMemCreate, cuMemMap and related APIs."""
return bool(
self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_HOST_NUMA_VIRTUAL_MEMORY_MANAGEMENT_SUPPORTED
)
)
@property
def host_numa_memory_pools_supported(self) -> bool:
"""bool: Device supports HOST_NUMA location with the cuMemAllocAsync and cuMemPool family of APIs."""
return bool(
self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_HOST_NUMA_MEMORY_POOLS_SUPPORTED)
)
# Start of CUDA 13 device attributes
@property
def host_numa_multinode_ipc_supported(self) -> bool:
"""bool: Device supports HOST_NUMA location IPC between nodes in a multi-node system."""
return bool(
self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_HOST_NUMA_MULTINODE_IPC_SUPPORTED)
)
@property
def host_memory_pools_supported(self) -> bool:
"""bool: Device suports HOST location with the cuMemAllocAsync and cuMemPool family of APIs."""
return bool(
self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_HOST_MEMORY_POOLS_SUPPORTED)
)
@property
def host_virtual_memory_management_supported(self) -> bool:
"""bool: Device supports HOST location with the virtual memory management APIs like cuMemCreate, cuMemMap and related APIs."""
return bool(
self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_HOST_VIRTUAL_MEMORY_MANAGEMENT_SUPPORTED
)
)
@property
def host_alloc_dma_buf_supported(self) -> bool:
"""bool: Device supports page-locked host memory buffer sharing with dma_buf mechanism."""
return bool(
self._get_cached_attribute(driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_HOST_ALLOC_DMA_BUF_SUPPORTED)
)
@property
def only_partial_host_native_atomic_supported(self) -> bool:
"""bool: Link between the device and the host supports only some native atomic operations."""
return bool(
self._get_cached_attribute(
driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_ONLY_PARTIAL_HOST_NATIVE_ATOMIC_SUPPORTED
)
)
class Device:
"""Represent a GPU and act as an entry point for cuda.core features.
This is a singleton object that helps ensure interoperability
across multiple libraries imported in the process to both see
and use the same GPU device.
While acting as the entry point, many other CUDA resources can be
allocated such as streams and buffers. Any :obj:`~_context.Context` dependent
resource created through this device, will continue to refer to
this device's context.
Newly returned :obj:`~_device.Device` objects are thread-local singletons
for a specified device.
Note
----
Will not initialize the GPU.
Parameters
----------
device_id : int, optional
Device ordinal to return a :obj:`~_device.Device` object for.
Default value of `None` return the currently used device.
"""
__slots__ = ("_device_id", "_memory_resource", "_has_inited", "_properties", "_uuid", "_context", "__weakref__")
def __new__(cls, device_id: Device | int | None = None):
if isinstance(device_id, Device):
return device_id
Device_ensure_cuda_initialized()
device_id = Device_resolve_device_id(device_id)
devices = Device_ensure_tls_devices(cls)
try:
return devices[device_id]
except IndexError:
raise ValueError(f"device_id must be within [0, {len(devices)}), got {device_id}") from None
def _check_context_initialized(self):
if not self._has_inited:
raise CUDAError(
f"Device {self._device_id} is not yet initialized, perhaps you forgot to call .set_current() first?"
)
@classmethod
def get_all_devices(cls):
"""
Query the available device instances.
Returns
-------
tuple of Device
A tuple containing instances of available devices.
"""
from cuda.core import system
total = system.get_num_devices()
return tuple(cls(device_id) for device_id in range(total))
def to_system_device(self) -> 'cuda.core.system.Device':
"""
Get the corresponding :class:`cuda.core.system.Device` (which is used
for NVIDIA Machine Library (NVML) access) for this
:class:`cuda.core.Device` (which is used for CUDA access).
The devices are mapped to one another by their UUID.