77from typing import Union
88from warnings import warn
99
10+ from cuda .core .experimental ._device import Device
1011from cuda .core .experimental ._launch_config import LaunchConfig , _to_native_launch_config
1112from cuda .core .experimental ._stream import Stream
1213from cuda .core .experimental ._utils .clear_error_support import (
@@ -73,8 +74,9 @@ def _init(cls, kernel):
7374 self ._loader = _backend [self ._backend_version ]
7475 return self
7576
76- def _get_cached_attribute (self , device_id : int , attribute : driver .CUfunction_attribute ) -> int :
77+ def _get_cached_attribute (self , device_id : Device | int , attribute : driver .CUfunction_attribute ) -> int :
7778 """Helper function to get a cached attribute or fetch and cache it if not present."""
79+ device_id = Device (device_id ).device_id
7880 cache_key = device_id , attribute
7981 result = self ._cache .get (cache_key , cache_key )
8082 if result is not cache_key :
@@ -94,62 +96,62 @@ def _get_cached_attribute(self, device_id: int, attribute: driver.CUfunction_att
9496 self ._cache [cache_key ] = result
9597 return result
9698
97- def max_threads_per_block (self , device_id : int = None ) -> int :
99+ def max_threads_per_block (self , device_id : Device | int = None ) -> int :
98100 """int : The maximum number of threads per block.
99101 This attribute is read-only."""
100102 return self ._get_cached_attribute (
101103 device_id , driver .CUfunction_attribute .CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK
102104 )
103105
104- def shared_size_bytes (self , device_id : int = None ) -> int :
106+ def shared_size_bytes (self , device_id : Device | int = None ) -> int :
105107 """int : The size in bytes of statically-allocated shared memory required by this function.
106108 This attribute is read-only."""
107109 return self ._get_cached_attribute (device_id , driver .CUfunction_attribute .CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES )
108110
109- def const_size_bytes (self , device_id : int = None ) -> int :
111+ def const_size_bytes (self , device_id : Device | int = None ) -> int :
110112 """int : The size in bytes of user-allocated constant memory required by this function.
111113 This attribute is read-only."""
112114 return self ._get_cached_attribute (device_id , driver .CUfunction_attribute .CU_FUNC_ATTRIBUTE_CONST_SIZE_BYTES )
113115
114- def local_size_bytes (self , device_id : int = None ) -> int :
116+ def local_size_bytes (self , device_id : Device | int = None ) -> int :
115117 """int : The size in bytes of local memory used by each thread of this function.
116118 This attribute is read-only."""
117119 return self ._get_cached_attribute (device_id , driver .CUfunction_attribute .CU_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES )
118120
119- def num_regs (self , device_id : int = None ) -> int :
121+ def num_regs (self , device_id : Device | int = None ) -> int :
120122 """int : The number of registers used by each thread of this function.
121123 This attribute is read-only."""
122124 return self ._get_cached_attribute (device_id , driver .CUfunction_attribute .CU_FUNC_ATTRIBUTE_NUM_REGS )
123125
124- def ptx_version (self , device_id : int = None ) -> int :
126+ def ptx_version (self , device_id : Device | int = None ) -> int :
125127 """int : The PTX virtual architecture version for which the function was compiled.
126128 This attribute is read-only."""
127129 return self ._get_cached_attribute (device_id , driver .CUfunction_attribute .CU_FUNC_ATTRIBUTE_PTX_VERSION )
128130
129- def binary_version (self , device_id : int = None ) -> int :
131+ def binary_version (self , device_id : Device | int = None ) -> int :
130132 """int : The binary architecture version for which the function was compiled.
131133 This attribute is read-only."""
132134 return self ._get_cached_attribute (device_id , driver .CUfunction_attribute .CU_FUNC_ATTRIBUTE_BINARY_VERSION )
133135
134- def cache_mode_ca (self , device_id : int = None ) -> bool :
136+ def cache_mode_ca (self , device_id : Device | int = None ) -> bool :
135137 """bool : Whether the function has been compiled with user specified option "-Xptxas --dlcm=ca" set.
136138 This attribute is read-only."""
137139 return bool (self ._get_cached_attribute (device_id , driver .CUfunction_attribute .CU_FUNC_ATTRIBUTE_CACHE_MODE_CA ))
138140
139- def max_dynamic_shared_size_bytes (self , device_id : int = None ) -> int :
141+ def max_dynamic_shared_size_bytes (self , device_id : Device | int = None ) -> int :
140142 """int : The maximum size in bytes of dynamically-allocated shared memory that can be used
141143 by this function."""
142144 return self ._get_cached_attribute (
143145 device_id , driver .CUfunction_attribute .CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES
144146 )
145147
146- def preferred_shared_memory_carveout (self , device_id : int = None ) -> int :
148+ def preferred_shared_memory_carveout (self , device_id : Device | int = None ) -> int :
147149 """int : The shared memory carveout preference, in percent of the total shared memory."""
148150 return self ._get_cached_attribute (
149151 device_id , driver .CUfunction_attribute .CU_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT
150152 )
151153
152- def cluster_size_must_be_set (self , device_id : int = None ) -> bool :
154+ def cluster_size_must_be_set (self , device_id : Device | int = None ) -> bool :
153155 """bool : The kernel must launch with a valid cluster size specified.
154156 This attribute is read-only."""
155157 return bool (
@@ -158,33 +160,33 @@ def cluster_size_must_be_set(self, device_id: int = None) -> bool:
158160 )
159161 )
160162
161- def required_cluster_width (self , device_id : int = None ) -> int :
163+ def required_cluster_width (self , device_id : Device | int = None ) -> int :
162164 """int : The required cluster width in blocks."""
163165 return self ._get_cached_attribute (
164166 device_id , driver .CUfunction_attribute .CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_WIDTH
165167 )
166168
167- def required_cluster_height (self , device_id : int = None ) -> int :
169+ def required_cluster_height (self , device_id : Device | int = None ) -> int :
168170 """int : The required cluster height in blocks."""
169171 return self ._get_cached_attribute (
170172 device_id , driver .CUfunction_attribute .CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_HEIGHT
171173 )
172174
173- def required_cluster_depth (self , device_id : int = None ) -> int :
175+ def required_cluster_depth (self , device_id : Device | int = None ) -> int :
174176 """int : The required cluster depth in blocks."""
175177 return self ._get_cached_attribute (
176178 device_id , driver .CUfunction_attribute .CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_DEPTH
177179 )
178180
179- def non_portable_cluster_size_allowed (self , device_id : int = None ) -> bool :
181+ def non_portable_cluster_size_allowed (self , device_id : Device | int = None ) -> bool :
180182 """bool : Whether the function can be launched with non-portable cluster size."""
181183 return bool (
182184 self ._get_cached_attribute (
183185 device_id , driver .CUfunction_attribute .CU_FUNC_ATTRIBUTE_NON_PORTABLE_CLUSTER_SIZE_ALLOWED
184186 )
185187 )
186188
187- def cluster_scheduling_policy_preference (self , device_id : int = None ) -> int :
189+ def cluster_scheduling_policy_preference (self , device_id : Device | int = None ) -> int :
188190 """int : The block scheduling policy of a function."""
189191 return self ._get_cached_attribute (
190192 device_id , driver .CUfunction_attribute .CU_FUNC_ATTRIBUTE_CLUSTER_SCHEDULING_POLICY_PREFERENCE
0 commit comments