Skip to main content

singe_cuda/
types.rs

1#![allow(deprecated, non_camel_case_types)]
2
3use std::ptr;
4
5pub use num_complex::{Complex, Complex32, Complex64};
6use num_enum::{IntoPrimitive, TryFromPrimitive};
7use singe_cuda_sys::{driver, library_types};
8
9pub use half::{bf16, f16};
10
11use singe_core::{impl_enum_conversion, impl_enum_display};
12
13macro_rules! impl_float_storage {
14    ($name:ident, $bits:ty) => {
15        #[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash)]
16        #[repr(transparent)]
17        pub struct $name(pub $bits);
18
19        impl $name {
20            pub const fn from_bits(bits: $bits) -> Self {
21                Self(bits)
22            }
23
24            pub const fn to_bits(self) -> $bits {
25                self.0
26            }
27        }
28    };
29}
30
31impl_float_storage!(f8e4m3, u8);
32impl_float_storage!(f8e5m2, u8);
33impl_float_storage!(f8ue8m0, u8);
34impl_float_storage!(f6e2m3, u8);
35impl_float_storage!(f6e3m2, u8);
36impl_float_storage!(f4e2m1, u8);
37
38#[derive(Debug, Clone, Copy)]
39#[repr(transparent)]
40/// CUDA host callback function pointer.
41///
42/// This is a borrowed function pointer value, not an owned CUDA resource.
43pub struct HostFunction(driver::CUhostFn);
44
45#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
46#[repr(transparent)]
47/// CUDA device function handle.
48///
49/// CUDA owns the underlying function as part of a module, library, or runtime
50/// registration. This wrapper is a copyable handle value and does not unload or
51/// destroy the function.
52pub struct DeviceFunction(driver::CUfunction);
53
54#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
55#[repr(transparent)]
56pub struct DevicePtr(*mut ());
57
58impl HostFunction {
59    /// Wraps a raw CUDA host callback function pointer.
60    ///
61    /// # Safety
62    ///
63    /// `raw` must be a callback function pointer with the ABI and lifetime
64    /// required by CUDA for every operation that uses the returned handle.
65    pub const unsafe fn new(raw: driver::CUhostFn) -> Self {
66        Self(raw)
67    }
68
69    /// Wraps a raw CUDA host callback function pointer.
70    ///
71    /// # Safety
72    ///
73    /// `raw` must be a callback function pointer with the ABI and lifetime
74    /// required by CUDA for every operation that uses the returned handle.
75    pub const unsafe fn from_raw(raw: driver::CUhostFn) -> Self {
76        unsafe { Self::new(raw) }
77    }
78
79    pub const fn as_raw(self) -> driver::CUhostFn {
80        self.0
81    }
82}
83
84impl DeviceFunction {
85    /// Wraps a raw CUDA device function handle.
86    ///
87    /// # Safety
88    ///
89    /// `raw` must be a valid CUDA function handle whose owning module,
90    /// library, or runtime registration remains loaded for every operation that
91    /// uses the returned handle.
92    pub const unsafe fn new(raw: driver::CUfunction) -> Self {
93        Self(raw)
94    }
95
96    /// Wraps a raw CUDA device function handle.
97    ///
98    /// # Safety
99    ///
100    /// `raw` must be a valid CUDA function handle whose owning module,
101    /// library, or runtime registration remains loaded for every operation that
102    /// uses the returned handle.
103    pub const unsafe fn from_raw(raw: driver::CUfunction) -> Self {
104        unsafe { Self::new(raw) }
105    }
106
107    pub const fn as_raw(self) -> driver::CUfunction {
108        self.0
109    }
110
111    pub const fn is_null(self) -> bool {
112        self.0.is_null()
113    }
114}
115
116impl DevicePtr {
117    pub const fn null() -> Self {
118        Self(ptr::null_mut())
119    }
120
121    /// Wraps a raw CUDA device pointer value.
122    ///
123    /// # Safety
124    ///
125    /// `raw` must be either null or a pointer value that is valid for the CUDA
126    /// operation it is passed to. This wrapper does not prove allocation
127    /// ownership, size, lifetime, context association, or access permissions.
128    pub const unsafe fn new(raw: *mut ()) -> Self {
129        Self(raw)
130    }
131
132    /// Wraps a raw CUDA device pointer value.
133    ///
134    /// # Safety
135    ///
136    /// `raw` must be either null or a pointer value that is valid for the CUDA
137    /// operation it is passed to. This wrapper does not prove allocation
138    /// ownership, size, lifetime, context association, or access permissions.
139    pub const unsafe fn from_raw(raw: *mut ()) -> Self {
140        unsafe { Self::new(raw.cast()) }
141    }
142
143    pub const fn as_raw(self) -> *mut () {
144        self.0.cast()
145    }
146
147    pub const fn as_ptr(self) -> *mut () {
148        self.0
149    }
150
151    pub const fn as_const_ptr(self) -> *const () {
152        self.0.cast_const()
153    }
154
155    pub const fn is_null(self) -> bool {
156        self.0.is_null()
157    }
158
159    pub const fn cast<T>(self) -> *mut T {
160        self.0.cast()
161    }
162}
163
164impl From<HostFunction> for driver::CUhostFn {
165    fn from(value: HostFunction) -> Self {
166        value.as_raw()
167    }
168}
169
170impl From<DeviceFunction> for driver::CUfunction {
171    fn from(value: DeviceFunction) -> Self {
172        value.as_raw()
173    }
174}
175
176impl From<DevicePtr> for *mut () {
177    fn from(value: DevicePtr) -> Self {
178        value.as_raw()
179    }
180}
181
182bitflags::bitflags! {
183    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
184    pub struct GraphicsRegisterFlags: u32 {
185        const NONE = driver::CUgraphicsRegisterFlags::CU_GRAPHICS_REGISTER_FLAGS_NONE as _;
186        const READ_ONLY = driver::CUgraphicsRegisterFlags::CU_GRAPHICS_REGISTER_FLAGS_READ_ONLY as _;
187        const WRITE_DISCARD = driver::CUgraphicsRegisterFlags::CU_GRAPHICS_REGISTER_FLAGS_WRITE_DISCARD as _;
188        const SURFACE_LDST = driver::CUgraphicsRegisterFlags::CU_GRAPHICS_REGISTER_FLAGS_SURFACE_LDST as _;
189        const TEXTURE_GATHER = driver::CUgraphicsRegisterFlags::CU_GRAPHICS_REGISTER_FLAGS_TEXTURE_GATHER as _;
190    }
191}
192
193bitflags::bitflags! {
194    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
195    pub struct GraphicsMapResourceFlags: u32 {
196        const NONE = driver::CUgraphicsMapResourceFlags::CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE as _;
197        const READ_ONLY = driver::CUgraphicsMapResourceFlags::CU_GRAPHICS_MAP_RESOURCE_FLAGS_READ_ONLY as _;
198        const WRITE_DISCARD = driver::CUgraphicsMapResourceFlags::CU_GRAPHICS_MAP_RESOURCE_FLAGS_WRITE_DISCARD as _;
199    }
200}
201
202#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
203#[repr(u32)]
204#[non_exhaustive]
205pub enum LibraryProperty {
206    Major = library_types::libraryPropertyType::MAJOR_VERSION as _,
207    Minor = library_types::libraryPropertyType::MINOR_VERSION as _,
208    Patch = library_types::libraryPropertyType::PATCH_LEVEL as _,
209}
210
211impl_enum_conversion!(library_types::libraryPropertyType, LibraryProperty);
212
213impl_enum_display!(LibraryProperty, {
214    Self::Major => "MAJOR_VERSION",
215    Self::Minor => "MINOR_VERSION",
216    Self::Patch => "PATCH_LEVEL",
217});
218
219#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
220#[repr(u32)]
221#[non_exhaustive]
222pub enum EmulationStrategy {
223    Default = library_types::cudaEmulationStrategy::CUDA_EMULATION_STRATEGY_DEFAULT as _,
224    Performant = library_types::cudaEmulationStrategy::CUDA_EMULATION_STRATEGY_PERFORMANT as _,
225    Eager = library_types::cudaEmulationStrategy::CUDA_EMULATION_STRATEGY_EAGER as _,
226}
227
228impl_enum_conversion!(library_types::cudaEmulationStrategy, EmulationStrategy);
229
230impl_enum_display!(EmulationStrategy, {
231    Self::Default => "CUDA_EMULATION_STRATEGY_DEFAULT",
232    Self::Performant => "CUDA_EMULATION_STRATEGY_PERFORMANT",
233    Self::Eager => "CUDA_EMULATION_STRATEGY_EAGER",
234});
235
236#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
237#[repr(u32)]
238#[non_exhaustive]
239pub enum EmulationMantissaControl {
240    Dynamic =
241        library_types::cudaEmulationMantissaControl::CUDA_EMULATION_MANTISSA_CONTROL_DYNAMIC as _,
242    Fixed = library_types::cudaEmulationMantissaControl::CUDA_EMULATION_MANTISSA_CONTROL_FIXED as _,
243}
244
245impl_enum_conversion!(
246    library_types::cudaEmulationMantissaControl,
247    EmulationMantissaControl
248);
249
250impl_enum_display!(EmulationMantissaControl, {
251    Self::Dynamic => "CUDA_EMULATION_MANTISSA_CONTROL_DYNAMIC",
252    Self::Fixed => "CUDA_EMULATION_MANTISSA_CONTROL_FIXED",
253});
254
255bitflags::bitflags! {
256    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
257    pub struct EmulationSpecialValuesSupport: u32 {
258        const NONE = library_types::cudaEmulationSpecialValuesSupport::CUDA_EMULATION_SPECIAL_VALUES_SUPPORT_NONE as _;
259        const INFINITY = library_types::cudaEmulationSpecialValuesSupport::CUDA_EMULATION_SPECIAL_VALUES_SUPPORT_INFINITY as _;
260        const NAN = library_types::cudaEmulationSpecialValuesSupport::CUDA_EMULATION_SPECIAL_VALUES_SUPPORT_NAN as _;
261        const DEFAULT = library_types::cudaEmulationSpecialValuesSupport::CUDA_EMULATION_SPECIAL_VALUES_SUPPORT_DEFAULT as _;
262    }
263}
264
265impl From<library_types::cudaEmulationSpecialValuesSupport> for EmulationSpecialValuesSupport {
266    fn from(value: library_types::cudaEmulationSpecialValuesSupport) -> Self {
267        Self::from_bits_retain(value as u32)
268    }
269}
270
271impl From<EmulationSpecialValuesSupport> for library_types::cudaEmulationSpecialValuesSupport {
272    fn from(value: EmulationSpecialValuesSupport) -> Self {
273        unsafe {
274            core::mem::transmute::<u32, library_types::cudaEmulationSpecialValuesSupport>(
275                value.bits(),
276            )
277        }
278    }
279}
280
281#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
282#[repr(u32)]
283#[non_exhaustive]
284pub enum PointerAttribute {
285    Context = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_CONTEXT as _,
286    MemoryType = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_MEMORY_TYPE as _,
287    DevicePointer = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_DEVICE_POINTER as _,
288    HostPointer = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_HOST_POINTER as _,
289    P2pTokens = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_P2P_TOKENS as _,
290    SyncMemops = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_SYNC_MEMOPS as _,
291    BufferId = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_BUFFER_ID as _,
292    IsManaged = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_IS_MANAGED as _,
293    DeviceOrdinal = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL as _,
294    IsLegacyCudaIpcCapable =
295        driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_IS_LEGACY_CUDA_IPC_CAPABLE as _,
296    RangeStartAddr = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_RANGE_START_ADDR as _,
297    RangeSize = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_RANGE_SIZE as _,
298    Mapped = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_MAPPED as _,
299    AllowedHandleTypes =
300        driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_ALLOWED_HANDLE_TYPES as _,
301    IsGpuDirectRdmaCapable =
302        driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_IS_GPU_DIRECT_RDMA_CAPABLE as _,
303    AccessFlags = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_ACCESS_FLAGS as _,
304    MempoolHandle = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_MEMPOOL_HANDLE as _,
305    MappingSize = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_MAPPING_SIZE as _,
306    MappingBaseAddr = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_MAPPING_BASE_ADDR as _,
307    MemoryBlockId = driver::CUpointer_attribute_enum::CU_POINTER_ATTRIBUTE_MEMORY_BLOCK_ID as _,
308}
309
310impl_enum_conversion!(u32, driver::CUpointer_attribute, PointerAttribute);
311
312impl_enum_display!(PointerAttribute, {
313    Self::Context => "CU_POINTER_ATTRIBUTE_CONTEXT",
314    Self::MemoryType => "CU_POINTER_ATTRIBUTE_MEMORY_TYPE",
315    Self::DevicePointer => "CU_POINTER_ATTRIBUTE_DEVICE_POINTER",
316    Self::HostPointer => "CU_POINTER_ATTRIBUTE_HOST_POINTER",
317    Self::P2pTokens => "CU_POINTER_ATTRIBUTE_P2P_TOKENS",
318    Self::SyncMemops => "CU_POINTER_ATTRIBUTE_SYNC_MEMOPS",
319    Self::BufferId => "CU_POINTER_ATTRIBUTE_BUFFER_ID",
320    Self::IsManaged => "CU_POINTER_ATTRIBUTE_IS_MANAGED",
321    Self::DeviceOrdinal => "CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL",
322    Self::IsLegacyCudaIpcCapable => "CU_POINTER_ATTRIBUTE_IS_LEGACY_CUDA_IPC_CAPABLE",
323    Self::RangeStartAddr => "CU_POINTER_ATTRIBUTE_RANGE_START_ADDR",
324    Self::RangeSize => "CU_POINTER_ATTRIBUTE_RANGE_SIZE",
325    Self::Mapped => "CU_POINTER_ATTRIBUTE_MAPPED",
326    Self::AllowedHandleTypes => "CU_POINTER_ATTRIBUTE_ALLOWED_HANDLE_TYPES",
327    Self::IsGpuDirectRdmaCapable => "CU_POINTER_ATTRIBUTE_IS_GPU_DIRECT_RDMA_CAPABLE",
328    Self::AccessFlags => "CU_POINTER_ATTRIBUTE_ACCESS_FLAGS",
329    Self::MempoolHandle => "CU_POINTER_ATTRIBUTE_MEMPOOL_HANDLE",
330    Self::MappingSize => "CU_POINTER_ATTRIBUTE_MAPPING_SIZE",
331    Self::MappingBaseAddr => "CU_POINTER_ATTRIBUTE_MAPPING_BASE_ADDR",
332    Self::MemoryBlockId => "CU_POINTER_ATTRIBUTE_MEMORY_BLOCK_ID",
333});
334
335#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
336#[repr(u32)]
337#[non_exhaustive]
338pub enum FunctionAttribute {
339    MaxThreadsPerBlock =
340        driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK as _,
341    SharedSizeBytes = driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES as _,
342    ConstSizeBytes = driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_CONST_SIZE_BYTES as _,
343    LocalSizeBytes = driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES as _,
344    NumRegs = driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_NUM_REGS as _,
345    PtxVersion = driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_PTX_VERSION as _,
346    BinaryVersion = driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_BINARY_VERSION as _,
347    CacheModeCa = driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_CACHE_MODE_CA as _,
348    MaxDynamicSharedSizeBytes =
349        driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES as _,
350    PreferredSharedMemoryCarveout =
351        driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT as _,
352    ClusterSizeMustBeSet =
353        driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_CLUSTER_SIZE_MUST_BE_SET as _,
354    RequiredClusterWidth =
355        driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_WIDTH as _,
356    RequiredClusterHeight =
357        driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_HEIGHT as _,
358    RequiredClusterDepth =
359        driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_DEPTH as _,
360    NonPortableClusterSizeAllowed =
361        driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_NON_PORTABLE_CLUSTER_SIZE_ALLOWED as _,
362    ClusterSchedulingPolicyPreference =
363        driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_CLUSTER_SCHEDULING_POLICY_PREFERENCE
364            as _,
365    Max = driver::CUfunction_attribute_enum::CU_FUNC_ATTRIBUTE_MAX as _,
366}
367
368impl_enum_conversion!(u32, driver::CUfunction_attribute, FunctionAttribute);
369
370impl_enum_display!(FunctionAttribute, {
371    Self::MaxThreadsPerBlock => "CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK",
372    Self::SharedSizeBytes => "CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES",
373    Self::ConstSizeBytes => "CU_FUNC_ATTRIBUTE_CONST_SIZE_BYTES",
374    Self::LocalSizeBytes => "CU_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES",
375    Self::NumRegs => "CU_FUNC_ATTRIBUTE_NUM_REGS",
376    Self::PtxVersion => "CU_FUNC_ATTRIBUTE_PTX_VERSION",
377    Self::BinaryVersion => "CU_FUNC_ATTRIBUTE_BINARY_VERSION",
378    Self::CacheModeCa => "CU_FUNC_ATTRIBUTE_CACHE_MODE_CA",
379    Self::MaxDynamicSharedSizeBytes => "CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES",
380    Self::PreferredSharedMemoryCarveout => "CU_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT",
381    Self::ClusterSizeMustBeSet => "CU_FUNC_ATTRIBUTE_CLUSTER_SIZE_MUST_BE_SET",
382    Self::RequiredClusterWidth => "CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_WIDTH",
383    Self::RequiredClusterHeight => "CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_HEIGHT",
384    Self::RequiredClusterDepth => "CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_DEPTH",
385    Self::NonPortableClusterSizeAllowed => "CU_FUNC_ATTRIBUTE_NON_PORTABLE_CLUSTER_SIZE_ALLOWED",
386    Self::ClusterSchedulingPolicyPreference => "CU_FUNC_ATTRIBUTE_CLUSTER_SCHEDULING_POLICY_PREFERENCE",
387    Self::Max => "CU_FUNC_ATTRIBUTE_MAX",
388});
389
390#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
391#[repr(u32)]
392#[non_exhaustive]
393pub enum FunctionCache {
394    PreferNone = driver::CUfunc_cache_enum::CU_FUNC_CACHE_PREFER_NONE as _,
395    PreferShared = driver::CUfunc_cache_enum::CU_FUNC_CACHE_PREFER_SHARED as _,
396    PreferL1 = driver::CUfunc_cache_enum::CU_FUNC_CACHE_PREFER_L1 as _,
397    PreferEqual = driver::CUfunc_cache_enum::CU_FUNC_CACHE_PREFER_EQUAL as _,
398}
399
400impl_enum_conversion!(u32, driver::CUfunc_cache, FunctionCache);
401
402impl_enum_display!(FunctionCache, {
403    Self::PreferNone => "CU_FUNC_CACHE_PREFER_NONE",
404    Self::PreferShared => "CU_FUNC_CACHE_PREFER_SHARED",
405    Self::PreferL1 => "CU_FUNC_CACHE_PREFER_L1",
406    Self::PreferEqual => "CU_FUNC_CACHE_PREFER_EQUAL",
407});
408
409#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
410#[repr(u32)]
411#[deprecated]
412#[non_exhaustive]
413pub enum SharedMemoryConfig {
414    DefaultBankSize = driver::CUsharedconfig_enum::CU_SHARED_MEM_CONFIG_DEFAULT_BANK_SIZE as _,
415    FourByteBankSize = driver::CUsharedconfig_enum::CU_SHARED_MEM_CONFIG_FOUR_BYTE_BANK_SIZE as _,
416    EightByteBankSize = driver::CUsharedconfig_enum::CU_SHARED_MEM_CONFIG_EIGHT_BYTE_BANK_SIZE as _,
417}
418
419impl_enum_conversion!(u32, driver::CUsharedconfig, SharedMemoryConfig);
420
421impl_enum_display!(SharedMemoryConfig, {
422    Self::DefaultBankSize => "CU_SHARED_MEM_CONFIG_DEFAULT_BANK_SIZE",
423    Self::FourByteBankSize => "CU_SHARED_MEM_CONFIG_FOUR_BYTE_BANK_SIZE",
424    Self::EightByteBankSize => "CU_SHARED_MEM_CONFIG_EIGHT_BYTE_BANK_SIZE",
425});
426
427#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
428#[repr(i32)]
429#[non_exhaustive]
430pub enum SharedMemoryCarveout {
431    Default = driver::CUshared_carveout_enum::CU_SHAREDMEM_CARVEOUT_DEFAULT as _,
432    MaxShared = driver::CUshared_carveout_enum::CU_SHAREDMEM_CARVEOUT_MAX_SHARED as _,
433    MaxL1 = driver::CUshared_carveout_enum::CU_SHAREDMEM_CARVEOUT_MAX_L1 as _,
434}
435
436impl_enum_conversion!(i32, driver::CUshared_carveout, SharedMemoryCarveout);
437
438impl_enum_display!(SharedMemoryCarveout, {
439    Self::Default => "CU_SHAREDMEM_CARVEOUT_DEFAULT",
440    Self::MaxShared => "CU_SHAREDMEM_CARVEOUT_MAX_SHARED",
441    Self::MaxL1 => "CU_SHAREDMEM_CARVEOUT_MAX_L1",
442});
443
444#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
445#[repr(u32)]
446#[non_exhaustive]
447pub enum MemoryType {
448    Host = driver::CUmemorytype_enum::CU_MEMORYTYPE_HOST as _,
449    Device = driver::CUmemorytype_enum::CU_MEMORYTYPE_DEVICE as _,
450    Array = driver::CUmemorytype_enum::CU_MEMORYTYPE_ARRAY as _,
451    Unified = driver::CUmemorytype_enum::CU_MEMORYTYPE_UNIFIED as _,
452}
453
454impl_enum_conversion!(u32, driver::CUmemorytype, MemoryType);
455
456impl_enum_display!(MemoryType, {
457    Self::Host => "CU_MEMORYTYPE_HOST",
458    Self::Device => "CU_MEMORYTYPE_DEVICE",
459    Self::Array => "CU_MEMORYTYPE_ARRAY",
460    Self::Unified => "CU_MEMORYTYPE_UNIFIED",
461});
462
463#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
464#[repr(u32)]
465#[non_exhaustive]
466pub enum ComputeMode {
467    Default = driver::CUcomputemode_enum::CU_COMPUTEMODE_DEFAULT as _,
468    Prohibited = driver::CUcomputemode_enum::CU_COMPUTEMODE_PROHIBITED as _,
469    ExclusiveProcess = driver::CUcomputemode_enum::CU_COMPUTEMODE_EXCLUSIVE_PROCESS as _,
470}
471
472impl_enum_conversion!(u32, driver::CUcomputemode, ComputeMode);
473
474impl_enum_display!(ComputeMode, {
475    Self::Default => "CU_COMPUTEMODE_DEFAULT",
476    Self::Prohibited => "CU_COMPUTEMODE_PROHIBITED",
477    Self::ExclusiveProcess => "CU_COMPUTEMODE_EXCLUSIVE_PROCESS",
478});
479
480#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
481#[repr(u32)]
482#[non_exhaustive]
483pub enum MemoryAdvise {
484    SetReadMostly = driver::CUmem_advise_enum::CU_MEM_ADVISE_SET_READ_MOSTLY as _,
485    UnsetReadMostly = driver::CUmem_advise_enum::CU_MEM_ADVISE_UNSET_READ_MOSTLY as _,
486    SetPreferredLocation = driver::CUmem_advise_enum::CU_MEM_ADVISE_SET_PREFERRED_LOCATION as _,
487    UnsetPreferredLocation = driver::CUmem_advise_enum::CU_MEM_ADVISE_UNSET_PREFERRED_LOCATION as _,
488    SetAccessedBy = driver::CUmem_advise_enum::CU_MEM_ADVISE_SET_ACCESSED_BY as _,
489    UnsetAccessedBy = driver::CUmem_advise_enum::CU_MEM_ADVISE_UNSET_ACCESSED_BY as _,
490}
491
492impl_enum_conversion!(u32, driver::CUmem_advise, MemoryAdvise);
493
494impl_enum_display!(MemoryAdvise, {
495    Self::SetReadMostly => "CU_MEM_ADVISE_SET_READ_MOSTLY",
496    Self::UnsetReadMostly => "CU_MEM_ADVISE_UNSET_READ_MOSTLY",
497    Self::SetPreferredLocation => "CU_MEM_ADVISE_SET_PREFERRED_LOCATION",
498    Self::UnsetPreferredLocation => "CU_MEM_ADVISE_UNSET_PREFERRED_LOCATION",
499    Self::SetAccessedBy => "CU_MEM_ADVISE_SET_ACCESSED_BY",
500    Self::UnsetAccessedBy => "CU_MEM_ADVISE_UNSET_ACCESSED_BY",
501});
502
503#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
504#[repr(u32)]
505#[non_exhaustive]
506pub enum MemoryRangeAttribute {
507    ReadMostly = driver::CUmem_range_attribute_enum::CU_MEM_RANGE_ATTRIBUTE_READ_MOSTLY as _,
508    PreferredLocation =
509        driver::CUmem_range_attribute_enum::CU_MEM_RANGE_ATTRIBUTE_PREFERRED_LOCATION as _,
510    AccessedBy = driver::CUmem_range_attribute_enum::CU_MEM_RANGE_ATTRIBUTE_ACCESSED_BY as _,
511    LastPrefetchLocation =
512        driver::CUmem_range_attribute_enum::CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION as _,
513}
514
515impl_enum_conversion!(u32, driver::CUmem_range_attribute, MemoryRangeAttribute);
516
517impl_enum_display!(MemoryRangeAttribute, {
518    Self::ReadMostly => "CU_MEM_RANGE_ATTRIBUTE_READ_MOSTLY",
519    Self::PreferredLocation => "CU_MEM_RANGE_ATTRIBUTE_PREFERRED_LOCATION",
520    Self::AccessedBy => "CU_MEM_RANGE_ATTRIBUTE_ACCESSED_BY",
521    Self::LastPrefetchLocation => "CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION",
522});
523
524#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
525#[repr(u32)]
526#[non_exhaustive]
527pub enum CubemapFace {
528    PositiveX = driver::CUarray_cubemap_face_enum::CU_CUBEMAP_FACE_POSITIVE_X as _,
529    NegativeX = driver::CUarray_cubemap_face_enum::CU_CUBEMAP_FACE_NEGATIVE_X as _,
530    PositiveY = driver::CUarray_cubemap_face_enum::CU_CUBEMAP_FACE_POSITIVE_Y as _,
531    NegativeY = driver::CUarray_cubemap_face_enum::CU_CUBEMAP_FACE_NEGATIVE_Y as _,
532    PositiveZ = driver::CUarray_cubemap_face_enum::CU_CUBEMAP_FACE_POSITIVE_Z as _,
533    NegativeZ = driver::CUarray_cubemap_face_enum::CU_CUBEMAP_FACE_NEGATIVE_Z as _,
534}
535
536impl_enum_conversion!(u32, driver::CUarray_cubemap_face, CubemapFace);
537
538impl_enum_display!(CubemapFace, {
539    Self::PositiveX => "CU_CUBEMAP_FACE_POSITIVE_X",
540    Self::NegativeX => "CU_CUBEMAP_FACE_NEGATIVE_X",
541    Self::PositiveY => "CU_CUBEMAP_FACE_POSITIVE_Y",
542    Self::NegativeY => "CU_CUBEMAP_FACE_NEGATIVE_Y",
543    Self::PositiveZ => "CU_CUBEMAP_FACE_POSITIVE_Z",
544    Self::NegativeZ => "CU_CUBEMAP_FACE_NEGATIVE_Z",
545});
546
547#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
548#[repr(u32)]
549#[non_exhaustive]
550pub enum Limit {
551    StackSize = driver::CUlimit_enum::CU_LIMIT_STACK_SIZE as _,
552    PrintfFifoSize = driver::CUlimit_enum::CU_LIMIT_PRINTF_FIFO_SIZE as _,
553    MallocHeapSize = driver::CUlimit_enum::CU_LIMIT_MALLOC_HEAP_SIZE as _,
554    DevRuntimeSyncDepth = driver::CUlimit_enum::CU_LIMIT_DEV_RUNTIME_SYNC_DEPTH as _,
555    DevRuntimePendingLaunchCount =
556        driver::CUlimit_enum::CU_LIMIT_DEV_RUNTIME_PENDING_LAUNCH_COUNT as _,
557    MaxL2FetchGranularity = driver::CUlimit_enum::CU_LIMIT_MAX_L2_FETCH_GRANULARITY as _,
558    PersistingL2CacheSize = driver::CUlimit_enum::CU_LIMIT_PERSISTING_L2_CACHE_SIZE as _,
559    Max = driver::CUlimit_enum::CU_LIMIT_MAX as _,
560}
561
562impl_enum_conversion!(u32, driver::CUlimit, Limit);
563
564impl_enum_display!(Limit, {
565    Self::StackSize => "CU_LIMIT_STACK_SIZE",
566    Self::PrintfFifoSize => "CU_LIMIT_PRINTF_FIFO_SIZE",
567    Self::MallocHeapSize => "CU_LIMIT_MALLOC_HEAP_SIZE",
568    Self::DevRuntimeSyncDepth => "CU_LIMIT_DEV_RUNTIME_SYNC_DEPTH",
569    Self::DevRuntimePendingLaunchCount => "CU_LIMIT_DEV_RUNTIME_PENDING_LAUNCH_COUNT",
570    Self::MaxL2FetchGranularity => "CU_LIMIT_MAX_L2_FETCH_GRANULARITY",
571    Self::PersistingL2CacheSize => "CU_LIMIT_PERSISTING_L2_CACHE_SIZE",
572    Self::Max => "CU_LIMIT_MAX",
573});
574
575#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
576#[repr(u32)]
577#[non_exhaustive]
578pub enum ResourceType {
579    Array = driver::CUresourcetype_enum::CU_RESOURCE_TYPE_ARRAY as _,
580    MipmappedArray = driver::CUresourcetype_enum::CU_RESOURCE_TYPE_MIPMAPPED_ARRAY as _,
581    Linear = driver::CUresourcetype_enum::CU_RESOURCE_TYPE_LINEAR as _,
582    Pitch2d = driver::CUresourcetype_enum::CU_RESOURCE_TYPE_PITCH2D as _,
583}
584
585impl_enum_conversion!(u32, driver::CUresourcetype, ResourceType);
586
587impl_enum_display!(ResourceType, {
588    Self::Array => "CU_RESOURCE_TYPE_ARRAY",
589    Self::MipmappedArray => "CU_RESOURCE_TYPE_MIPMAPPED_ARRAY",
590    Self::Linear => "CU_RESOURCE_TYPE_LINEAR",
591    Self::Pitch2d => "CU_RESOURCE_TYPE_PITCH2D",
592});
593
594#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
595#[repr(u32)]
596#[non_exhaustive]
597pub enum AccessProperty {
598    Normal = driver::CUaccessProperty_enum::CU_ACCESS_PROPERTY_NORMAL as _,
599    Streaming = driver::CUaccessProperty_enum::CU_ACCESS_PROPERTY_STREAMING as _,
600    Persisting = driver::CUaccessProperty_enum::CU_ACCESS_PROPERTY_PERSISTING as _,
601}
602
603impl_enum_conversion!(u32, driver::CUaccessProperty, AccessProperty);
604
605impl_enum_display!(AccessProperty, {
606    Self::Normal => "CU_ACCESS_PROPERTY_NORMAL",
607    Self::Streaming => "CU_ACCESS_PROPERTY_STREAMING",
608    Self::Persisting => "CU_ACCESS_PROPERTY_PERSISTING",
609});