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,
}
#[path = "ffi_constants.rs"]
mod ffi_constants;
pub use ffi_constants::*;
#[path = "ffi_launch.rs"]
mod ffi_launch;
pub use ffi_launch::*;
#[path = "ffi_descriptors.rs"]
mod ffi_descriptors;
pub use ffi_descriptors::*;
#[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]
#[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_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
);
}
}