use std::ffi::c_void;
use std::fmt;
pub type CUresult = u32;
pub type CUdevice = i32;
pub type CUdeviceptr = u64;
macro_rules! define_handle {
($(#[$meta:meta])* $name:ident) => {
$(#[$meta])*
#[repr(transparent)]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct $name(pub *mut c_void);
unsafe impl Send for $name {}
unsafe impl Sync for $name {}
impl fmt::Debug for $name {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}({:p})", stringify!($name), self.0)
}
}
impl Default for $name {
fn default() -> Self {
Self(std::ptr::null_mut())
}
}
impl $name {
#[inline]
pub fn is_null(self) -> bool {
self.0.is_null()
}
}
};
}
define_handle! {
CUcontext
}
define_handle! {
CUmodule
}
define_handle! {
CUfunction
}
define_handle! {
CUstream
}
define_handle! {
CUevent
}
define_handle! {
CUmemoryPool
}
define_handle! {
CUtexref
}
define_handle! {
CUsurfref
}
define_handle! {
CUtexObject
}
define_handle! {
CUsurfObject
}
define_handle! {
CUkernel
}
define_handle! {
CUlibrary
}
define_handle! {
CUmulticastObject
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
#[non_exhaustive]
pub enum CUmemorytype {
Host = 1,
Device = 2,
Array = 3,
Unified = 4,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
#[non_exhaustive]
#[allow(non_camel_case_types)]
pub enum CUpointer_attribute {
Context = 1,
MemoryType = 2,
DevicePointer = 3,
HostPointer = 4,
IsManaged = 9,
DeviceOrdinal = 10,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
#[non_exhaustive]
pub enum CUlimit {
StackSize = 0,
PrintfFifoSize = 1,
MallocHeapSize = 2,
DevRuntimeSyncDepth = 3,
DevRuntimePendingLaunchCount = 4,
MaxL2FetchGranularity = 5,
PersistingL2CacheSize = 6,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i32)]
#[non_exhaustive]
#[allow(non_camel_case_types)]
pub enum CUfunction_attribute {
MaxThreadsPerBlock = 0,
SharedSizeBytes = 1,
ConstSizeBytes = 2,
LocalSizeBytes = 3,
NumRegs = 4,
PtxVersion = 5,
BinaryVersion = 6,
CacheModeCa = 7,
MaxDynamicSharedSizeBytes = 8,
PreferredSharedMemoryCarveout = 9,
}
pub const CUDA_SUCCESS: CUresult = 0;
pub const CUDA_ERROR_INVALID_VALUE: CUresult = 1;
pub const CUDA_ERROR_OUT_OF_MEMORY: CUresult = 2;
pub const CUDA_ERROR_NOT_INITIALIZED: CUresult = 3;
pub const CUDA_ERROR_DEINITIALIZED: CUresult = 4;
pub const CUDA_ERROR_PROFILER_DISABLED: CUresult = 5;
pub const CUDA_ERROR_PROFILER_NOT_INITIALIZED: CUresult = 6;
pub const CUDA_ERROR_PROFILER_ALREADY_STARTED: CUresult = 7;
pub const CUDA_ERROR_PROFILER_ALREADY_STOPPED: CUresult = 8;
pub const CUDA_ERROR_STUB_LIBRARY: CUresult = 34;
pub const CUDA_ERROR_DEVICE_UNAVAILABLE: CUresult = 46;
pub const CUDA_ERROR_NO_DEVICE: CUresult = 100;
pub const CUDA_ERROR_INVALID_DEVICE: CUresult = 101;
pub const CUDA_ERROR_DEVICE_NOT_LICENSED: CUresult = 102;
pub const CUDA_ERROR_INVALID_IMAGE: CUresult = 200;
pub const CUDA_ERROR_INVALID_CONTEXT: CUresult = 201;
pub const CUDA_ERROR_CONTEXT_ALREADY_CURRENT: CUresult = 202;
pub const CUDA_ERROR_MAP_FAILED: CUresult = 205;
pub const CUDA_ERROR_UNMAP_FAILED: CUresult = 206;
pub const CUDA_ERROR_ARRAY_IS_MAPPED: CUresult = 207;
pub const CUDA_ERROR_ALREADY_MAPPED: CUresult = 208;
pub const CUDA_ERROR_NO_BINARY_FOR_GPU: CUresult = 209;
pub const CUDA_ERROR_ALREADY_ACQUIRED: CUresult = 210;
pub const CUDA_ERROR_NOT_MAPPED: CUresult = 211;
pub const CUDA_ERROR_NOT_MAPPED_AS_ARRAY: CUresult = 212;
pub const CUDA_ERROR_NOT_MAPPED_AS_POINTER: CUresult = 213;
pub const CUDA_ERROR_ECC_UNCORRECTABLE: CUresult = 214;
pub const CUDA_ERROR_UNSUPPORTED_LIMIT: CUresult = 215;
pub const CUDA_ERROR_CONTEXT_ALREADY_IN_USE: CUresult = 216;
pub const CUDA_ERROR_PEER_ACCESS_UNSUPPORTED: CUresult = 217;
pub const CUDA_ERROR_INVALID_PTX: CUresult = 218;
pub const CUDA_ERROR_INVALID_GRAPHICS_CONTEXT: CUresult = 219;
pub const CUDA_ERROR_NVLINK_UNCORRECTABLE: CUresult = 220;
pub const CUDA_ERROR_JIT_COMPILER_NOT_FOUND: CUresult = 221;
pub const CUDA_ERROR_UNSUPPORTED_PTX_VERSION: CUresult = 222;
pub const CUDA_ERROR_JIT_COMPILATION_DISABLED: CUresult = 223;
pub const CUDA_ERROR_UNSUPPORTED_EXEC_AFFINITY: CUresult = 224;
pub const CUDA_ERROR_UNSUPPORTED_DEVSIDE_SYNC: CUresult = 225;
pub const CUDA_ERROR_INVALID_SOURCE: CUresult = 300;
pub const CUDA_ERROR_FILE_NOT_FOUND: CUresult = 301;
pub const CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND: CUresult = 302;
pub const CUDA_ERROR_SHARED_OBJECT_INIT_FAILED: CUresult = 303;
pub const CUDA_ERROR_OPERATING_SYSTEM: CUresult = 304;
pub const CUDA_ERROR_INVALID_HANDLE: CUresult = 400;
pub const CUDA_ERROR_ILLEGAL_STATE: CUresult = 401;
pub const CUDA_ERROR_LOSSY_QUERY: CUresult = 402;
pub const CUDA_ERROR_NOT_FOUND: CUresult = 500;
pub const CUDA_ERROR_NOT_READY: CUresult = 600;
pub const CUDA_ERROR_ILLEGAL_ADDRESS: CUresult = 700;
pub const CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES: CUresult = 701;
pub const CUDA_ERROR_LAUNCH_TIMEOUT: CUresult = 702;
pub const CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING: CUresult = 703;
pub const CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED: CUresult = 704;
pub const CUDA_ERROR_PEER_ACCESS_NOT_ENABLED: CUresult = 705;
pub const CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE: CUresult = 708;
pub const CUDA_ERROR_CONTEXT_IS_DESTROYED: CUresult = 709;
pub const CUDA_ERROR_ASSERT: CUresult = 710;
pub const CUDA_ERROR_TOO_MANY_PEERS: CUresult = 711;
pub const CUDA_ERROR_HOST_MEMORY_ALREADY_REGISTERED: CUresult = 712;
pub const CUDA_ERROR_HOST_MEMORY_NOT_REGISTERED: CUresult = 713;
pub const CUDA_ERROR_HARDWARE_STACK_ERROR: CUresult = 714;
pub const CUDA_ERROR_ILLEGAL_INSTRUCTION: CUresult = 715;
pub const CUDA_ERROR_MISALIGNED_ADDRESS: CUresult = 716;
pub const CUDA_ERROR_INVALID_ADDRESS_SPACE: CUresult = 717;
pub const CUDA_ERROR_INVALID_PC: CUresult = 718;
pub const CUDA_ERROR_LAUNCH_FAILED: CUresult = 719;
pub const CUDA_ERROR_COOPERATIVE_LAUNCH_TOO_LARGE: CUresult = 720;
pub const CUDA_ERROR_NOT_PERMITTED: CUresult = 800;
pub const CUDA_ERROR_NOT_SUPPORTED: CUresult = 801;
pub const CUDA_ERROR_SYSTEM_NOT_READY: CUresult = 802;
pub const CUDA_ERROR_SYSTEM_DRIVER_MISMATCH: CUresult = 803;
pub const CUDA_ERROR_COMPAT_NOT_SUPPORTED_ON_DEVICE: CUresult = 804;
pub const CUDA_ERROR_MPS_CONNECTION_FAILED: CUresult = 805;
pub const CUDA_ERROR_MPS_RPC_FAILURE: CUresult = 806;
pub const CUDA_ERROR_MPS_SERVER_NOT_READY: CUresult = 807;
pub const CUDA_ERROR_MPS_MAX_CLIENTS_REACHED: CUresult = 808;
pub const CUDA_ERROR_MPS_MAX_CONNECTIONS_REACHED: CUresult = 809;
pub const CUDA_ERROR_MPS_CLIENT_TERMINATED: CUresult = 810;
pub const CUDA_ERROR_CDP_NOT_SUPPORTED: CUresult = 811;
pub const CUDA_ERROR_CDP_VERSION_MISMATCH: CUresult = 812;
pub const CUDA_ERROR_STREAM_CAPTURE_UNSUPPORTED: CUresult = 900;
pub const CUDA_ERROR_STREAM_CAPTURE_INVALIDATED: CUresult = 901;
pub const CUDA_ERROR_STREAM_CAPTURE_MERGE: CUresult = 902;
pub const CUDA_ERROR_STREAM_CAPTURE_UNMATCHED: CUresult = 903;
pub const CUDA_ERROR_STREAM_CAPTURE_UNJOINED: CUresult = 904;
pub const CUDA_ERROR_STREAM_CAPTURE_ISOLATION: CUresult = 905;
pub const CUDA_ERROR_STREAM_CAPTURE_IMPLICIT: CUresult = 906;
pub const CUDA_ERROR_CAPTURED_EVENT: CUresult = 907;
pub const CUDA_ERROR_STREAM_CAPTURE_WRONG_THREAD: CUresult = 908;
pub const CUDA_ERROR_TIMEOUT: CUresult = 909;
pub const CUDA_ERROR_GRAPH_EXEC_UPDATE_FAILURE: CUresult = 910;
pub const CUDA_ERROR_EXTERNAL_DEVICE: CUresult = 911;
pub const CUDA_ERROR_INVALID_CLUSTER_SIZE: CUresult = 912;
pub const CUDA_ERROR_FUNCTION_NOT_LOADED: CUresult = 913;
pub const CUDA_ERROR_INVALID_RESOURCE_TYPE: CUresult = 914;
pub const CUDA_ERROR_INVALID_RESOURCE_CONFIGURATION: CUresult = 915;
pub const CUDA_ERROR_UNKNOWN: CUresult = 999;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i32)]
#[non_exhaustive]
#[allow(non_camel_case_types)]
pub enum CUdevice_attribute {
MaxThreadsPerBlock = 1,
MaxBlockDimX = 2,
MaxBlockDimY = 3,
MaxBlockDimZ = 4,
MaxGridDimX = 5,
MaxGridDimY = 6,
MaxGridDimZ = 7,
MaxSharedMemoryPerBlock = 8,
TotalConstantMemory = 9,
WarpSize = 10,
MaxPitch = 11,
MaxRegistersPerBlock = 12,
ClockRate = 13,
TextureAlignment = 14,
GpuOverlap = 15,
MultiprocessorCount = 16,
KernelExecTimeout = 17,
Integrated = 18,
CanMapHostMemory = 19,
ComputeMode = 20,
MaxTexture1DWidth = 21,
MaxTexture2DWidth = 22,
MaxTexture2DHeight = 23,
MaxTexture3DWidth = 24,
MaxTexture3DHeight = 25,
MaxTexture3DDepth = 26,
MaxTexture2DLayeredWidth = 27,
MaxTexture2DLayeredHeight = 28,
MaxTexture2DLayeredLayers = 29,
SurfaceAlignment = 30,
ConcurrentKernels = 31,
EccEnabled = 32,
PciBusId = 33,
PciDeviceId = 34,
TccDriver = 35,
MemoryClockRate = 36,
GlobalMemoryBusWidth = 37,
L2CacheSize = 38,
MaxThreadsPerMultiprocessor = 39,
AsyncEngineCount = 40,
UnifiedAddressing = 41,
MaxTexture1DLayeredWidth = 42,
MaxTexture1DLayeredLayers = 43,
MaxTexture2DGatherWidth = 44,
MaxTexture2DGatherHeight = 45,
MaxTexture3DWidthAlt = 47,
MaxTexture3DHeightAlt = 48,
MaxTexture3DDepthAlt = 49,
PciDomainId = 50,
TexturePitchAlignment = 51,
MaxTexture1DMipmappedWidth2 = 52,
MaxTextureCubemapWidth = 54,
MaxTextureCubemapLayeredWidth = 55,
MaxTextureCubemapLayeredLayers = 56,
MaxSurface1DWidth = 57,
MaxSurface2DWidth = 58,
MaxSurface2DHeight = 59,
MaxSurface3DWidth = 60,
MaxSurface3DHeight = 61,
MaxSurface3DDepth = 62,
MaxSurfaceCubemapWidth = 63,
MaxSurface1DLayeredWidth = 64,
MaxSurface1DLayeredLayers = 65,
MaxSurface2DLayeredWidth = 66,
MaxSurface2DLayeredHeight = 67,
MaxSurface2DLayeredLayers = 68,
MaxSurfaceCubemapLayeredWidth = 69,
MaxSurfaceCubemapLayeredLayers = 70,
MaxTexture1DLinearWidth = 71,
MaxTexture2DLinearWidth = 72,
MaxTexture2DLinearHeight = 73,
MaxTexture2DLinearPitch = 74,
ComputeCapabilityMajor = 75,
ComputeCapabilityMinor = 76,
MaxTexture2DMipmappedWidth = 77,
MaxTexture2DMipmappedHeight = 78,
MaxTexture1DMipmappedWidth = 79,
StreamPrioritiesSupported = 80,
MaxSharedMemoryPerMultiprocessor = 81,
MaxRegistersPerMultiprocessor = 82,
ManagedMemory = 83,
IsMultiGpuBoard = 84,
MultiGpuBoardGroupId = 85,
HostNativeAtomicSupported = 86,
SingleToDoublePrecisionPerfRatio = 87,
PageableMemoryAccess = 88,
ConcurrentManagedAccess = 89,
ComputePreemptionSupported = 90,
CanUseHostPointerForRegisteredMem = 91,
Reserved92 = 92,
Reserved93 = 93,
Reserved94 = 94,
CooperativeLaunch = 95,
CooperativeMultiDeviceLaunch = 96,
MaxSharedMemoryPerBlockOptin = 97,
CanFlushRemoteWrites = 98,
HostRegisterSupported = 99,
PageableMemoryAccessUsesHostPageTables = 100,
DirectManagedMemAccessFromHost = 101,
VirtualMemoryManagementSupported = 102,
HandleTypePosixFileDescriptorSupported = 103,
HandleTypeWin32HandleSupported = 104,
HandleTypeWin32KmtHandleSupported = 105,
MaxBlocksPerMultiprocessor = 106,
GenericCompressionSupported = 107,
MaxPersistingL2CacheSize = 108,
MaxAccessPolicyWindowSize = 109,
GpuDirectRdmaWithCudaVmmSupported = 110,
AccessPolicyMaxWindowSize = 111,
ReservedSharedMemoryPerBlock = 112,
TimelineSemaphoreInteropSupported = 113,
MemoryPoolsSupported = 115,
GpuDirectRdmaSupported = 116,
GpuDirectRdmaFlushWritesOptions = 117,
GpuDirectRdmaWritesOrdering = 118,
MemoryPoolSupportedHandleTypes = 119,
ClusterLaunch = 120,
DeferredMappingCudaArraySupported = 121,
IpcEventSupported = 122,
MemSyncDomainCount = 123,
TensorMapAccessSupported = 124,
UnifiedFunctionPointers = 125,
NumaConfig = 127,
NumaId = 128,
MaxTimelineSemaphoreInteropSupported = 129,
MemSyncDomainSupported = 130,
GpuDirectRdmaFabricSupported = 131,
MulticastSupported = 132,
MpsEnabled = 133,
HostNumaId = 134,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
#[non_exhaustive]
#[allow(non_camel_case_types)]
pub enum CUjit_option {
MaxRegisters = 0,
ThreadsPerBlock = 1,
WallTime = 2,
InfoLogBuffer = 3,
InfoLogBufferSizeBytes = 4,
ErrorLogBuffer = 5,
ErrorLogBufferSizeBytes = 6,
OptimizationLevel = 7,
TargetFromCuContext = 8,
Target = 9,
FallbackStrategy = 10,
GenerateDebugInfo = 11,
LogVerbose = 12,
GenerateLineInfo = 13,
CacheMode = 14,
Sm3xOpt = 15,
FastCompile = 16,
GlobalSymbolNames = 17,
GlobalSymbolAddresses = 18,
GlobalSymbolCount = 19,
Lto = 20,
Ftz = 21,
PrecDiv = 22,
PrecSqrt = 23,
Fma = 24,
ReferencedKernelNames = 25,
ReferencedKernelCount = 26,
ReferencedVariableNames = 27,
ReferencedVariableCount = 28,
OptimizeUnusedDeviceVariables = 29,
PositionIndependentCode = 30,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
#[non_exhaustive]
pub enum CUjitInputType {
Ptx = 1,
Cubin = 2,
Fatbin = 3,
Object = 4,
Library = 5,
}
pub const CU_STREAM_DEFAULT: u32 = 0;
pub const CU_STREAM_NON_BLOCKING: u32 = 1;
pub const CU_MEMPOOL_ATTR_REUSE_FOLLOW_EVENT_DEPENDENCIES: u32 = 1;
pub const CU_MEMPOOL_ATTR_REUSE_ALLOW_OPPORTUNISTIC: u32 = 2;
pub const CU_MEMPOOL_ATTR_REUSE_ALLOW_INTERNAL_DEPENDENCIES: u32 = 3;
pub const CU_MEMPOOL_ATTR_RELEASE_THRESHOLD: u32 = 4;
pub const CU_MEMPOOL_ATTR_RESERVED_MEM_CURRENT: u32 = 5;
pub const CU_MEMPOOL_ATTR_RESERVED_MEM_HIGH: u32 = 6;
pub const CU_MEMPOOL_ATTR_USED_MEM_CURRENT: u32 = 7;
pub const CU_MEMPOOL_ATTR_USED_MEM_HIGH: u32 = 8;
pub const CU_EVENT_DEFAULT: u32 = 0;
pub const CU_EVENT_BLOCKING_SYNC: u32 = 1;
pub const CU_EVENT_DISABLE_TIMING: u32 = 2;
pub const CU_EVENT_INTERPROCESS: u32 = 4;
pub const CU_MEM_ATTACH_GLOBAL: u32 = 1;
pub const CU_MEM_ATTACH_HOST: u32 = 2;
pub const CU_MEM_ATTACH_SINGLE: u32 = 4;
pub const CU_MEMHOSTREGISTER_PORTABLE: u32 = 0x01;
pub const CU_MEMHOSTREGISTER_DEVICEMAP: u32 = 0x02;
pub const CU_MEMHOSTREGISTER_IOMEMORY: u32 = 0x04;
pub const CU_MEMHOSTREGISTER_READ_ONLY: u32 = 0x08;
pub const CU_POINTER_ATTRIBUTE_CONTEXT: u32 = 1;
pub const CU_POINTER_ATTRIBUTE_MEMORY_TYPE: u32 = 2;
pub const CU_POINTER_ATTRIBUTE_DEVICE_POINTER: u32 = 3;
pub const CU_POINTER_ATTRIBUTE_HOST_POINTER: u32 = 4;
pub const CU_POINTER_ATTRIBUTE_IS_MANAGED: u32 = 7;
pub const CU_MEMORYTYPE_HOST: u32 = 1;
pub const CU_MEMORYTYPE_DEVICE: u32 = 2;
pub const CU_MEMORYTYPE_ARRAY: u32 = 3;
pub const CU_MEMORYTYPE_UNIFIED: u32 = 4;
pub const CU_CTX_SCHED_AUTO: u32 = 0;
pub const CU_CTX_SCHED_SPIN: u32 = 1;
pub const CU_CTX_SCHED_YIELD: u32 = 2;
pub const CU_CTX_SCHED_BLOCKING_SYNC: u32 = 4;
pub const CU_CTX_SCHED_MASK: u32 = 0x07;
pub const CU_CTX_MAP_HOST: u32 = 0x08;
pub const CU_CTX_LMEM_RESIZE_TO_MAX: u32 = 0x10;
pub const CU_CTX_COREDUMP_ENABLE: u32 = 0x20;
pub const CU_CTX_USER_COREDUMP_ENABLE: u32 = 0x40;
pub const CU_CTX_SYNC_MEMOPS: u32 = 0x80;
pub const CU_CTX_FLAGS_MASK: u32 = 0xFF;
pub const CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK: i32 = 0;
pub const CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES: i32 = 1;
pub const CU_FUNC_ATTRIBUTE_CONST_SIZE_BYTES: i32 = 2;
pub const CU_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES: i32 = 3;
pub const CU_FUNC_ATTRIBUTE_NUM_REGS: i32 = 4;
pub const CU_FUNC_ATTRIBUTE_PTX_VERSION: i32 = 5;
pub const CU_FUNC_ATTRIBUTE_BINARY_VERSION: i32 = 6;
pub const CU_FUNC_ATTRIBUTE_CACHE_MODE_CA: i32 = 7;
pub const CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES: i32 = 8;
pub const CU_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT: i32 = 9;
pub const CU_FUNC_ATTRIBUTE_CLUSTER_SIZE_MUST_BE_SET: i32 = 10;
pub const CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_WIDTH: i32 = 11;
pub const CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_HEIGHT: i32 = 12;
pub const CU_FUNC_ATTRIBUTE_REQUIRED_CLUSTER_DEPTH: i32 = 13;
pub const CU_FUNC_ATTRIBUTE_NON_PORTABLE_CLUSTER_SIZE_ALLOWED: i32 = 14;
pub const CU_FUNC_ATTRIBUTE_CLUSTER_SCHEDULING_POLICY_PREFERENCE: i32 = 15;
pub const CU_MEM_ADVISE_SET_READ_MOSTLY: u32 = 1;
pub const CU_MEM_ADVISE_UNSET_READ_MOSTLY: u32 = 2;
pub const CU_MEM_ADVISE_SET_PREFERRED_LOCATION: u32 = 3;
pub const CU_MEM_ADVISE_UNSET_PREFERRED_LOCATION: u32 = 4;
pub const CU_MEM_ADVISE_SET_ACCESSED_BY: u32 = 5;
pub const CU_MEM_ADVISE_UNSET_ACCESSED_BY: u32 = 6;
pub const CU_LIMIT_STACK_SIZE: u32 = 0;
pub const CU_LIMIT_PRINTF_FIFO_SIZE: u32 = 1;
pub const CU_LIMIT_MALLOC_HEAP_SIZE: u32 = 2;
pub const CU_LIMIT_DEV_RUNTIME_SYNC_DEPTH: u32 = 3;
pub const CU_LIMIT_DEV_RUNTIME_PENDING_LAUNCH_COUNT: u32 = 4;
pub const CU_LIMIT_MAX_L2_FETCH_GRANULARITY: u32 = 5;
pub const CU_LIMIT_PERSISTING_L2_CACHE_SIZE: u32 = 6;
pub const CU_OCCUPANCY_DEFAULT: u32 = 0;
pub const CU_OCCUPANCY_DISABLE_CACHING_OVERRIDE: u32 = 1;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
pub enum CuLaunchAttributeId {
IgnoreSharedMemoryReuse = 1,
ClusterDimension = 2,
ClusterSchedulingPolicyPreference = 3,
ProgrammaticStreamSerialization = 4,
ProgrammaticEvent = 5,
Priority = 6,
MemSyncDomainMap = 7,
MemSyncDomain = 8,
LaunchCompletionEvent = 9,
DeviceUpdatableKernelNode = 10,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(C)]
pub struct CuLaunchAttributeClusterDim {
pub x: u32,
pub y: u32,
pub z: u32,
}
#[repr(C)]
pub union CuLaunchAttributeValue {
pub cluster_dim: CuLaunchAttributeClusterDim,
pub value_u32: u32,
pub pad: [u8; 64],
}
impl Copy for CuLaunchAttributeValue {}
impl Clone for CuLaunchAttributeValue {
fn clone(&self) -> Self {
*self
}
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct CuLaunchAttribute {
pub id: CuLaunchAttributeId,
pub pad: [u8; 4],
pub value: CuLaunchAttributeValue,
}
#[repr(C)]
pub struct CuLaunchConfig {
pub grid_dim_x: u32,
pub grid_dim_y: u32,
pub grid_dim_z: u32,
pub block_dim_x: u32,
pub block_dim_y: u32,
pub block_dim_z: u32,
pub shared_mem_bytes: u32,
pub stream: CUstream,
pub attrs: *const CuLaunchAttribute,
pub num_attrs: u32,
}
unsafe impl Send for CuLaunchConfig {}
unsafe impl Sync for CuLaunchConfig {}
define_handle! {
CUarray
}
define_handle! {
CUmipmappedArray
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
#[non_exhaustive]
#[allow(non_camel_case_types)]
pub enum CUarray_format {
UnsignedInt8 = 0x01,
UnsignedInt16 = 0x02,
UnsignedInt32 = 0x03,
SignedInt8 = 0x08,
SignedInt16 = 0x09,
SignedInt32 = 0x0a,
Half = 0x10,
Float = 0x20,
Nv12 = 0xb0,
UnormInt8X1 = 0xc0,
UnormInt8X2 = 0xc1,
UnormInt8X4 = 0xc2,
UnormInt16X1 = 0xc3,
UnormInt16X2 = 0xc4,
UnormInt16X4 = 0xc5,
SnormInt8X1 = 0xc6,
SnormInt8X2 = 0xc7,
SnormInt8X4 = 0xc8,
SnormInt16X1 = 0xc9,
SnormInt16X2 = 0xca,
SnormInt16X4 = 0xcb,
Bc1Unorm = 0x91,
Bc1UnormSrgb = 0x92,
Bc2Unorm = 0x93,
Bc2UnormSrgb = 0x94,
Bc3Unorm = 0x95,
Bc3UnormSrgb = 0x96,
Bc4Unorm = 0x97,
Bc4Snorm = 0x98,
Bc5Unorm = 0x99,
Bc5Snorm = 0x9a,
Bc6hUf16 = 0x9b,
Bc6hSf16 = 0x9c,
Bc7Unorm = 0x9d,
Bc7UnormSrgb = 0x9e,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
#[non_exhaustive]
pub enum CUresourcetype {
Array = 0x00,
MipmappedArray = 0x01,
Linear = 0x02,
Pitch2d = 0x03,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
#[allow(non_camel_case_types)]
pub enum CUaddress_mode {
Wrap = 0,
Clamp = 1,
Mirror = 2,
Border = 3,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
#[allow(non_camel_case_types)]
pub enum CUfilter_mode {
Point = 0,
Linear = 1,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
#[non_exhaustive]
pub enum CUresourceViewFormat {
None = 0x00,
Uint1x8 = 0x01,
Uint2x8 = 0x02,
Uint4x8 = 0x03,
Sint1x8 = 0x04,
Sint2x8 = 0x05,
Sint4x8 = 0x06,
Uint1x16 = 0x07,
Uint2x16 = 0x08,
Uint4x16 = 0x09,
Sint1x16 = 0x0a,
Sint2x16 = 0x0b,
Sint4x16 = 0x0c,
Uint1x32 = 0x0d,
Uint2x32 = 0x0e,
Uint4x32 = 0x0f,
Sint1x32 = 0x10,
Sint2x32 = 0x11,
Sint4x32 = 0x12,
Float1x16 = 0x13,
Float2x16 = 0x14,
Float4x16 = 0x15,
Float1x32 = 0x16,
Float2x32 = 0x17,
Float4x32 = 0x18,
UnsignedBc1 = 0x19,
UnsignedBc2 = 0x1a,
UnsignedBc3 = 0x1b,
UnsignedBc4 = 0x1c,
SignedBc4 = 0x1d,
UnsignedBc5 = 0x1e,
SignedBc5 = 0x1f,
UnsignedBc6h = 0x20,
SignedBc6h = 0x21,
UnsignedBc7 = 0x22,
Nv12 = 0x23,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub struct CUDA_ARRAY_DESCRIPTOR {
pub width: usize,
pub height: usize,
pub format: CUarray_format,
pub num_channels: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub struct CUDA_ARRAY3D_DESCRIPTOR {
pub width: usize,
pub height: usize,
pub depth: usize,
pub format: CUarray_format,
pub num_channels: u32,
pub flags: u32,
}
pub const CUDA_ARRAY3D_LAYERED: u32 = 0x01;
pub const CUDA_ARRAY3D_SURFACE_LDST: u32 = 0x02;
pub const CUDA_ARRAY3D_CUBEMAP: u32 = 0x04;
pub const CUDA_ARRAY3D_TEXTURE_GATHER: u32 = 0x08;
#[derive(Clone, Copy)]
#[repr(C)]
pub struct CudaResourceDescArray {
pub h_array: CUarray,
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct CudaResourceDescMipmap {
pub h_mipmapped_array: CUmipmappedArray,
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct CudaResourceDescLinear {
pub dev_ptr: CUdeviceptr,
pub format: CUarray_format,
pub num_channels: u32,
pub size_in_bytes: usize,
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct CudaResourceDescPitch2d {
pub dev_ptr: CUdeviceptr,
pub format: CUarray_format,
pub num_channels: u32,
pub width_in_elements: usize,
pub height: usize,
pub pitch_in_bytes: usize,
}
#[repr(C)]
pub union CudaResourceDescRes {
pub array: CudaResourceDescArray,
pub mipmap: CudaResourceDescMipmap,
pub linear: CudaResourceDescLinear,
pub pitch2d: CudaResourceDescPitch2d,
pub reserved: [i32; 32],
}
#[repr(C)]
pub struct CUDA_RESOURCE_DESC {
pub res_type: CUresourcetype,
pub res: CudaResourceDescRes,
pub flags: u32,
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct CUDA_TEXTURE_DESC {
pub address_mode: [CUaddress_mode; 3],
pub filter_mode: CUfilter_mode,
pub flags: u32,
pub max_anisotropy: u32,
pub mipmap_filter_mode: CUfilter_mode,
pub mipmap_level_bias: f32,
pub min_mipmap_level_clamp: f32,
pub max_mipmap_level_clamp: f32,
pub border_color: [f32; 4],
pub reserved: [i32; 12],
}
pub const CU_TRSF_READ_AS_INTEGER: u32 = 0x01;
pub const CU_TRSF_NORMALIZED_COORDINATES: u32 = 0x02;
pub const CU_TRSF_SRGB: u32 = 0x10;
pub const CU_TRSF_DISABLE_TRILINEAR_OPTIMIZATION: u32 = 0x20;
#[derive(Clone, Copy)]
#[repr(C)]
pub struct CUDA_RESOURCE_VIEW_DESC {
pub format: CUresourceViewFormat,
pub width: usize,
pub height: usize,
pub depth: usize,
pub first_mipmap_level: u32,
pub last_mipmap_level: u32,
pub first_layer: u32,
pub last_layer: u32,
pub reserved: [u32; 16],
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cuda_success_is_zero() {
assert_eq!(CUDA_SUCCESS, 0);
}
#[test]
fn test_opaque_types_are_pointer_sized() {
assert_eq!(
std::mem::size_of::<CUcontext>(),
std::mem::size_of::<*mut c_void>()
);
assert_eq!(
std::mem::size_of::<CUmodule>(),
std::mem::size_of::<*mut c_void>()
);
assert_eq!(
std::mem::size_of::<CUstream>(),
std::mem::size_of::<*mut c_void>()
);
assert_eq!(
std::mem::size_of::<CUevent>(),
std::mem::size_of::<*mut c_void>()
);
assert_eq!(
std::mem::size_of::<CUfunction>(),
std::mem::size_of::<*mut c_void>()
);
assert_eq!(
std::mem::size_of::<CUmemoryPool>(),
std::mem::size_of::<*mut c_void>()
);
}
#[test]
fn test_handle_default_is_null() {
assert!(CUcontext::default().is_null());
assert!(CUmodule::default().is_null());
assert!(CUfunction::default().is_null());
assert!(CUstream::default().is_null());
assert!(CUevent::default().is_null());
assert!(CUmemoryPool::default().is_null());
}
#[test]
fn test_device_attribute_repr() {
assert_eq!(CUdevice_attribute::MaxThreadsPerBlock as i32, 1);
assert_eq!(CUdevice_attribute::WarpSize as i32, 10);
assert_eq!(CUdevice_attribute::MultiprocessorCount as i32, 16);
assert_eq!(CUdevice_attribute::ComputeCapabilityMajor as i32, 75);
assert_eq!(CUdevice_attribute::ComputeCapabilityMinor as i32, 76);
assert_eq!(CUdevice_attribute::MaxBlocksPerMultiprocessor as i32, 106);
assert_eq!(CUdevice_attribute::L2CacheSize as i32, 38);
assert_eq!(
CUdevice_attribute::MaxSharedMemoryPerMultiprocessor as i32,
81
);
assert_eq!(CUdevice_attribute::ManagedMemory as i32, 83);
assert_eq!(CUdevice_attribute::MaxTexture2DGatherWidth as i32, 44);
assert_eq!(CUdevice_attribute::MaxTexture2DGatherHeight as i32, 45);
assert_eq!(CUdevice_attribute::MaxTexture3DWidthAlt as i32, 47);
assert_eq!(CUdevice_attribute::MaxTexture3DHeightAlt as i32, 48);
assert_eq!(CUdevice_attribute::MaxTexture3DDepthAlt as i32, 49);
assert_eq!(CUdevice_attribute::MaxTexture1DMipmappedWidth2 as i32, 52);
assert_eq!(CUdevice_attribute::Reserved92 as i32, 92);
assert_eq!(CUdevice_attribute::Reserved93 as i32, 93);
assert_eq!(CUdevice_attribute::Reserved94 as i32, 94);
assert_eq!(
CUdevice_attribute::VirtualMemoryManagementSupported as i32,
102
);
assert_eq!(
CUdevice_attribute::HandleTypePosixFileDescriptorSupported as i32,
103
);
assert_eq!(
CUdevice_attribute::HandleTypeWin32HandleSupported as i32,
104
);
assert_eq!(
CUdevice_attribute::HandleTypeWin32KmtHandleSupported as i32,
105
);
assert_eq!(CUdevice_attribute::AccessPolicyMaxWindowSize as i32, 111);
assert_eq!(CUdevice_attribute::ReservedSharedMemoryPerBlock as i32, 112);
assert_eq!(
CUdevice_attribute::TimelineSemaphoreInteropSupported as i32,
113
);
assert_eq!(CUdevice_attribute::MemoryPoolsSupported as i32, 115);
assert_eq!(CUdevice_attribute::ClusterLaunch as i32, 120);
assert_eq!(CUdevice_attribute::UnifiedFunctionPointers as i32, 125);
assert_eq!(
CUdevice_attribute::MaxTimelineSemaphoreInteropSupported as i32,
129
);
assert_eq!(CUdevice_attribute::MemSyncDomainSupported as i32, 130);
assert_eq!(CUdevice_attribute::GpuDirectRdmaFabricSupported as i32, 131);
}
#[test]
fn test_jit_option_repr() {
assert_eq!(CUjit_option::MaxRegisters as u32, 0);
assert_eq!(CUjit_option::ThreadsPerBlock as u32, 1);
assert_eq!(CUjit_option::WallTime as u32, 2);
assert_eq!(CUjit_option::InfoLogBuffer as u32, 3);
assert_eq!(CUjit_option::InfoLogBufferSizeBytes as u32, 4);
assert_eq!(CUjit_option::ErrorLogBuffer as u32, 5);
assert_eq!(CUjit_option::ErrorLogBufferSizeBytes as u32, 6);
assert_eq!(CUjit_option::OptimizationLevel as u32, 7);
assert_eq!(CUjit_option::Target as u32, 9);
assert_eq!(CUjit_option::FallbackStrategy as u32, 10);
}
#[test]
fn test_stream_and_event_flags() {
assert_eq!(CU_STREAM_DEFAULT, 0);
assert_eq!(CU_STREAM_NON_BLOCKING, 1);
assert_eq!(CU_EVENT_DEFAULT, 0);
assert_eq!(CU_EVENT_BLOCKING_SYNC, 1);
assert_eq!(CU_EVENT_DISABLE_TIMING, 2);
assert_eq!(CU_EVENT_INTERPROCESS, 4);
}
#[test]
fn test_context_scheduling_flags() {
assert_eq!(CU_CTX_SCHED_AUTO, 0);
assert_eq!(CU_CTX_SCHED_SPIN, 1);
assert_eq!(CU_CTX_SCHED_YIELD, 2);
assert_eq!(CU_CTX_SCHED_BLOCKING_SYNC, 4);
}
#[test]
fn test_mem_attach_flags() {
assert_eq!(CU_MEM_ATTACH_GLOBAL, 1);
assert_eq!(CU_MEM_ATTACH_HOST, 2);
assert_eq!(CU_MEM_ATTACH_SINGLE, 4);
}
#[test]
#[allow(clippy::assertions_on_constants)]
fn test_error_code_ranges() {
assert!(CUDA_ERROR_INVALID_VALUE < 10);
assert!((100..=102).contains(&CUDA_ERROR_NO_DEVICE));
assert!((100..=102).contains(&CUDA_ERROR_INVALID_DEVICE));
assert!((100..=102).contains(&CUDA_ERROR_DEVICE_NOT_LICENSED));
assert!(CUDA_ERROR_INVALID_IMAGE >= 200);
assert!(CUDA_ERROR_LAUNCH_FAILED >= 700);
assert!(CUDA_ERROR_ILLEGAL_ADDRESS >= 700);
assert!(CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES >= 700);
assert!(CUDA_ERROR_STREAM_CAPTURE_UNSUPPORTED >= 900);
assert_eq!(CUDA_ERROR_UNKNOWN, 999);
}
#[test]
fn test_func_attribute_constants() {
assert_eq!(CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK, 0);
assert_eq!(CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES, 1);
assert_eq!(CU_FUNC_ATTRIBUTE_NUM_REGS, 4);
}
#[test]
fn test_limit_constants() {
assert_eq!(CU_LIMIT_STACK_SIZE, 0);
assert_eq!(CU_LIMIT_PRINTF_FIFO_SIZE, 1);
assert_eq!(CU_LIMIT_MALLOC_HEAP_SIZE, 2);
}
#[test]
fn test_memory_type_constants() {
assert_eq!(CU_MEMORYTYPE_HOST, 1);
assert_eq!(CU_MEMORYTYPE_DEVICE, 2);
assert_eq!(CU_MEMORYTYPE_ARRAY, 3);
assert_eq!(CU_MEMORYTYPE_UNIFIED, 4);
}
#[test]
fn test_handle_debug_format() {
let ctx = CUcontext::default();
let debug_str = format!("{ctx:?}");
assert!(debug_str.starts_with("CUcontext("));
}
#[test]
fn test_handle_equality() {
let a = CUcontext::default();
let b = CUcontext::default();
assert_eq!(a, b);
}
#[test]
fn test_new_handle_types_are_pointer_sized() {
assert_eq!(
std::mem::size_of::<CUtexref>(),
std::mem::size_of::<*mut c_void>()
);
assert_eq!(
std::mem::size_of::<CUsurfref>(),
std::mem::size_of::<*mut c_void>()
);
assert_eq!(
std::mem::size_of::<CUtexObject>(),
std::mem::size_of::<*mut c_void>()
);
assert_eq!(
std::mem::size_of::<CUsurfObject>(),
std::mem::size_of::<*mut c_void>()
);
}
#[test]
fn test_new_handle_defaults_are_null() {
assert!(CUtexref::default().is_null());
assert!(CUsurfref::default().is_null());
assert!(CUtexObject::default().is_null());
assert!(CUsurfObject::default().is_null());
}
#[test]
fn test_memory_type_enum() {
assert_eq!(CUmemorytype::Host as u32, 1);
assert_eq!(CUmemorytype::Device as u32, 2);
assert_eq!(CUmemorytype::Array as u32, 3);
assert_eq!(CUmemorytype::Unified as u32, 4);
}
#[test]
fn test_pointer_attribute_enum() {
assert_eq!(CUpointer_attribute::Context as u32, 1);
assert_eq!(CUpointer_attribute::MemoryType as u32, 2);
assert_eq!(CUpointer_attribute::DevicePointer as u32, 3);
assert_eq!(CUpointer_attribute::HostPointer as u32, 4);
assert_eq!(CUpointer_attribute::IsManaged as u32, 9);
assert_eq!(CUpointer_attribute::DeviceOrdinal as u32, 10);
}
#[test]
fn test_limit_enum() {
assert_eq!(CUlimit::StackSize as u32, 0);
assert_eq!(CUlimit::PrintfFifoSize as u32, 1);
assert_eq!(CUlimit::MallocHeapSize as u32, 2);
assert_eq!(CUlimit::DevRuntimeSyncDepth as u32, 3);
assert_eq!(CUlimit::DevRuntimePendingLaunchCount as u32, 4);
assert_eq!(CUlimit::MaxL2FetchGranularity as u32, 5);
assert_eq!(CUlimit::PersistingL2CacheSize as u32, 6);
}
#[test]
fn test_function_attribute_enum() {
assert_eq!(CUfunction_attribute::MaxThreadsPerBlock as i32, 0);
assert_eq!(CUfunction_attribute::SharedSizeBytes as i32, 1);
assert_eq!(CUfunction_attribute::NumRegs as i32, 4);
assert_eq!(CUfunction_attribute::PtxVersion as i32, 5);
assert_eq!(CUfunction_attribute::BinaryVersion as i32, 6);
assert_eq!(CUfunction_attribute::MaxDynamicSharedSizeBytes as i32, 8);
assert_eq!(
CUfunction_attribute::PreferredSharedMemoryCarveout as i32,
9
);
}
}