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
use num_enum::{IntoPrimitive, TryFromPrimitive};
use singe_core::impl_enum_display;
use singe_cuda_sys::driver;
singe_core::native_enum! {
/// Attribute of a compiled kernel function, queried or set per function.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
#[non_exhaustive]
pub enum FunctionAttribute: driver::CUfunction_attribute {
/// The shared memory mode of a function, as a [`SharedMemoryMode`].
SharedMemoryMode = CU_FUNC_ATTRIBUTE_SHARED_MEMORY_MODE,
/// The maximum number of threads per block, beyond which a launch of the function would fail.
///
/// This number depends on both the function and the device on which the function is currently loaded.
MaxThreadsPerBlock = CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK,
/// The size in bytes of statically-allocated shared memory required by this function.
///
/// This does not include dynamically-allocated shared memory requested by the user at runtime.
SharedSizeBytes = CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES,
/// The size in bytes of user-allocated constant memory required by this function.
ConstSizeBytes = CU_FUNC_ATTRIBUTE_CONST_SIZE_BYTES,
/// The size in bytes of local memory used by each thread of this function.
LocalSizeBytes = CU_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES,
/// The number of registers used by each thread of this function.
NumRegs = CU_FUNC_ATTRIBUTE_NUM_REGS,
/// The PTX virtual architecture version for which the function was compiled.
///
/// This value is the major PTX version times 10 plus the minor PTX version, so a PTX version 1.3 function returns 13.
/// Cubins compiled before CUDA 3.0 may report the undefined value 0.
PtxVersion = CU_FUNC_ATTRIBUTE_PTX_VERSION,
/// The binary architecture version for which the function was compiled.
///
/// This value is the major binary version times 10 plus the minor binary version, so a binary version 1.3 function returns 13.
/// Legacy cubins without a properly encoded binary architecture version report 10.
BinaryVersion = CU_FUNC_ATTRIBUTE_BINARY_VERSION,
/// Whether the function was compiled with the `-Xptxas --dlcm=ca` option.
CacheModeCa = CU_FUNC_ATTRIBUTE_CACHE_MODE_CA,
/// The maximum size in bytes of dynamically-allocated shared memory that can be used by this function.
///
/// If the user-specified dynamic shared memory size is larger than this value, the launch will fail.
///
/// The default is [`DeviceAttribute::MaxSharedMemoryPerBlock`](crate::device::DeviceAttribute::MaxSharedMemoryPerBlock) minus [`Self::SharedSizeBytes`], or 0 when the static size exceeds that maximum.
/// It can be raised to [`DeviceAttribute::MaxSharedMemoryPerBlockOptin`](crate::device::DeviceAttribute::MaxSharedMemoryPerBlockOptin) minus [`Self::SharedSizeBytes`].
///
/// This attribute is ignored if the function or launch sets a shared memory mode, such as [`Self::SharedMemoryMode`].
///
/// This attribute cannot be used to access oversized shared memory, which only a shared memory mode enables.
MaxDynamicSharedSizeBytes = CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES,
/// On devices where the L1 cache and shared memory use the same hardware resources, this sets the shared memory carveout preference, in percent of the total shared memory.
///
/// The total is [`DeviceAttribute::MaxSharedMemoryPerMultiprocessor`](crate::device::DeviceAttribute::MaxSharedMemoryPerMultiprocessor).
/// This is only a hint, and the driver can choose a different ratio if required to execute the function.
PreferredSharedMemoryCarveout = CU_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT,
/// If this attribute is set, the kernel must launch with a valid cluster size specified.
ClusterSizeMustBeSet = CU_FUNC_ATTRIBUTE_CLUSTER_SIZE_MUST_BE_SET,
/// The required cluster width in blocks.
///
/// The values must either all be 0 or all be positive.
/// The validity of the cluster dimensions is otherwise checked at launch time.
///
/// If the value is set during compile time, it cannot be set at runtime.
/// Setting it at runtime returns [`Status::NotPermitted`](crate::error::Status::NotPermitted).
RequiredClusterWidth = CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_WIDTH,
/// The required cluster height in blocks.
///
/// The values must either all be 0 or all be positive.
/// The validity of the cluster dimensions is otherwise checked at launch time.
///
/// If the value is set during compile time, it cannot be set at runtime.
/// Setting it at runtime returns [`Status::NotPermitted`](crate::error::Status::NotPermitted).
RequiredClusterHeight = CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_HEIGHT,
/// The required cluster depth in blocks.
///
/// The values must either all be 0 or all be positive.
/// The validity of the cluster dimensions is otherwise checked at launch time.
///
/// If the value is set during compile time, it cannot be set at runtime.
/// Setting it at runtime returns [`Status::NotPermitted`](crate::error::Status::NotPermitted).
RequiredClusterDepth = CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_DEPTH,
/// Whether the function can be launched with non-portable cluster size.
///
/// 1 is allowed, 0 is disallowed.
/// A non-portable cluster size may only function on the specific SKUs the program is tested on.
/// The launch might fail if the program is run on a different hardware platform.
///
/// An occupancy query for the maximum active clusters checks whether a size can launch on the current device.
///
/// A portable cluster size is guaranteed to be functional on all compute capabilities higher than the target compute capability.
/// The portable cluster size for `sm_90` is 8 blocks per cluster.
/// This value may increase for future compute capabilities.
///
/// The specific hardware unit may support higher cluster sizes that are not guaranteed to be portable.
NonPortableClusterSizeAllowed = CU_FUNC_ATTRIBUTE_NON_PORTABLE_CLUSTER_SIZE_ALLOWED,
/// The block scheduling policy of a function, as a [`ClusterSchedulingPolicy`].
ClusterSchedulingPolicyPreference = CU_FUNC_ATTRIBUTE_CLUSTER_SCHEDULING_POLICY_PREFERENCE,
}
}
impl_enum_display!(FunctionAttribute, {
Self::SharedMemoryMode => "CU_FUNC_ATTRIBUTE_SHARED_MEMORY_MODE",
Self::MaxThreadsPerBlock => "CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK",
Self::SharedSizeBytes => "CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES",
Self::ConstSizeBytes => "CU_FUNC_ATTRIBUTE_CONST_SIZE_BYTES",
Self::LocalSizeBytes => "CU_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES",
Self::NumRegs => "CU_FUNC_ATTRIBUTE_NUM_REGS",
Self::PtxVersion => "CU_FUNC_ATTRIBUTE_PTX_VERSION",
Self::BinaryVersion => "CU_FUNC_ATTRIBUTE_BINARY_VERSION",
Self::CacheModeCa => "CU_FUNC_ATTRIBUTE_CACHE_MODE_CA",
Self::MaxDynamicSharedSizeBytes => "CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES",
Self::PreferredSharedMemoryCarveout => "CU_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT",
Self::ClusterSizeMustBeSet => "CU_FUNC_ATTRIBUTE_CLUSTER_SIZE_MUST_BE_SET",
Self::RequiredClusterWidth => "CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_WIDTH",
Self::RequiredClusterHeight => "CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_HEIGHT",
Self::RequiredClusterDepth => "CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_DEPTH",
Self::NonPortableClusterSizeAllowed => "CU_FUNC_ATTRIBUTE_NON_PORTABLE_CLUSTER_SIZE_ALLOWED",
Self::ClusterSchedulingPolicyPreference => "CU_FUNC_ATTRIBUTE_CLUSTER_SCHEDULING_POLICY_PREFERENCE",
});
singe_core::native_enum! {
/// Function cache configurations
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
#[non_exhaustive]
pub enum FunctionCache: driver::CUfunc_cache {
/// no preference for shared memory or L1 (default).
PreferNone = CU_FUNC_CACHE_PREFER_NONE,
/// prefer larger shared memory and smaller L1 cache.
PreferShared = CU_FUNC_CACHE_PREFER_SHARED,
/// prefer larger L1 cache and smaller shared memory.
PreferL1 = CU_FUNC_CACHE_PREFER_L1,
/// prefer equal sized L1 cache and shared memory.
PreferEqual = CU_FUNC_CACHE_PREFER_EQUAL,
}
}
impl_enum_display!(FunctionCache, {
Self::PreferNone => "CU_FUNC_CACHE_PREFER_NONE",
Self::PreferShared => "CU_FUNC_CACHE_PREFER_SHARED",
Self::PreferL1 => "CU_FUNC_CACHE_PREFER_L1",
Self::PreferEqual => "CU_FUNC_CACHE_PREFER_EQUAL",
});
singe_core::native_enum! {
/// Deprecated:
///
/// Shared memory configurations
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
#[deprecated]
#[non_exhaustive]
pub enum SharedMemoryConfig: driver::CUsharedconfig {
/// set default shared memory bank size.
DefaultBankSize = CU_SHARED_MEM_CONFIG_DEFAULT_BANK_SIZE,
/// set shared memory bank width to four bytes.
FourByteBankSize = CU_SHARED_MEM_CONFIG_FOUR_BYTE_BANK_SIZE,
/// set shared memory bank width to eight bytes.
EightByteBankSize = CU_SHARED_MEM_CONFIG_EIGHT_BYTE_BANK_SIZE,
}
}
impl_enum_display!(SharedMemoryConfig, {
Self::DefaultBankSize => "CU_SHARED_MEM_CONFIG_DEFAULT_BANK_SIZE",
Self::FourByteBankSize => "CU_SHARED_MEM_CONFIG_FOUR_BYTE_BANK_SIZE",
Self::EightByteBankSize => "CU_SHARED_MEM_CONFIG_EIGHT_BYTE_BANK_SIZE",
});
singe_core::native_enum! {
/// Shared memory carveout configurations for a function's [`FunctionAttribute::PreferredSharedMemoryCarveout`] attribute.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(i32)]
#[non_exhaustive]
pub enum SharedMemoryCarveout: driver::CUshared_carveout {
/// No preference for shared memory or L1 (default).
Default = CU_SHAREDMEM_CARVEOUT_DEFAULT,
/// Prefer maximum available shared memory, minimum L1 cache.
MaxShared = CU_SHAREDMEM_CARVEOUT_MAX_SHARED,
/// Prefer maximum available L1 cache, minimum shared memory.
MaxL1 = CU_SHAREDMEM_CARVEOUT_MAX_L1,
}
}
impl_enum_display!(SharedMemoryCarveout, {
Self::Default => "CU_SHAREDMEM_CARVEOUT_DEFAULT",
Self::MaxShared => "CU_SHAREDMEM_CARVEOUT_MAX_SHARED",
Self::MaxL1 => "CU_SHAREDMEM_CARVEOUT_MAX_L1",
});
singe_core::native_enum! {
/// Shared memory configuration for a kernel.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
#[non_exhaustive]
pub enum SharedMemoryMode: driver::CUsharedMemoryMode_enum {
/// Uses the function's [`FunctionAttribute::MaxDynamicSharedSizeBytes`] for shared memory on launch.
Default = CU_SHARED_MEMORY_MODE_DEFAULT,
/// Requires the requested dynamic shared memory size to be portable, within [`DeviceAttribute::MaxSharedMemoryPerBlock`](crate::device::DeviceAttribute::MaxSharedMemoryPerBlock).
RequirePortable = CU_SHARED_MEMORY_MODE_REQUIRE_PORTABLE,
/// Allows a non-portable dynamic shared memory size, within [`DeviceAttribute::MaxSharedMemoryPerBlockOptin`](crate::device::DeviceAttribute::MaxSharedMemoryPerBlockOptin).
AllowNonPortable = CU_SHARED_MEMORY_MODE_ALLOW_NON_PORTABLE,
/// Specifies that oversized shared memory configurations may be used (with the limitation of only 8kB L1 cache).
AllowOversizedSharedMemory = CU_SHARED_MEMORY_MODE_ALLOW_OVERSIZED_SHARED_MEMORY,
/// Specifies that oversized shared memory configurations may be used (with the limitation of only 8kB L1 cache), and prefer an oversized shared memory configuration.
PreferOversizedSharedMemory = CU_SHARED_MEMORY_MODE_PREFER_OVERSIZED_SHARED_MEMORY,
}
}
singe_core::native_enum! {
/// Cluster scheduling policy.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
#[non_exhaustive]
pub enum ClusterSchedulingPolicy: driver::CUclusterSchedulingPolicy_enum {
/// the default policy.
Default = CU_CLUSTER_SCHEDULING_POLICY_DEFAULT,
/// spread the blocks within a cluster to the SMs.
Spread = CU_CLUSTER_SCHEDULING_POLICY_SPREAD,
/// allow the hardware to load-balance the blocks in a cluster to the SMs.
LoadBalancing = CU_CLUSTER_SCHEDULING_POLICY_LOAD_BALANCING,
/// Spread the blocks within a cluster to the SMs, and prefer placement that prioritizes Distributed Shared Memory locality for Rubin-class GPUs.
///
/// This is a preference only.
/// The driver may ignore this request when the launch is not eligible, when the device does not support the requested placement behavior, or when other launch constraints take precedence.
///
/// This policy is intended for clustered kernels whose performance depends on communication through Distributed Shared Memory among blocks in the same cluster.
RubinDsmemLocality = CU_CLUSTER_SCHEDULING_POLICY_RUBIN_DSMEM_LOCALITY,
}
}
impl_enum_display!(SharedMemoryMode, {
SharedMemoryMode::Default => "CU_SHARED_MEMORY_MODE_DEFAULT",
SharedMemoryMode::RequirePortable => "CU_SHARED_MEMORY_MODE_REQUIRE_PORTABLE",
SharedMemoryMode::AllowNonPortable => "CU_SHARED_MEMORY_MODE_ALLOW_NON_PORTABLE",
SharedMemoryMode::AllowOversizedSharedMemory => "CU_SHARED_MEMORY_MODE_ALLOW_OVERSIZED_SHARED_MEMORY",
SharedMemoryMode::PreferOversizedSharedMemory => "CU_SHARED_MEMORY_MODE_PREFER_OVERSIZED_SHARED_MEMORY",
});
impl_enum_display!(ClusterSchedulingPolicy, {
ClusterSchedulingPolicy::Default => "CU_CLUSTER_SCHEDULING_POLICY_DEFAULT",
ClusterSchedulingPolicy::Spread => "CU_CLUSTER_SCHEDULING_POLICY_SPREAD",
ClusterSchedulingPolicy::LoadBalancing => "CU_CLUSTER_SCHEDULING_POLICY_LOAD_BALANCING",
ClusterSchedulingPolicy::RubinDsmemLocality => "CU_CLUSTER_SCHEDULING_POLICY_RUBIN_DSMEM_LOCALITY",
});