1use std::ffi::c_void;
15use std::fmt;
16
17pub type CUresult = u32;
26
27pub type CUdevice = i32;
29
30pub type CUdeviceptr = u64;
32
33macro_rules! define_handle {
38 ($(#[$meta:meta])* $name:ident) => {
39 $(#[$meta])*
40 #[repr(transparent)]
41 #[derive(Clone, Copy, PartialEq, Eq, Hash)]
42 pub struct $name(pub *mut c_void);
43
44 unsafe impl Send for $name {}
47 unsafe impl Sync for $name {}
48
49 impl fmt::Debug for $name {
50 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51 write!(f, "{}({:p})", stringify!($name), self.0)
52 }
53 }
54
55 impl Default for $name {
56 fn default() -> Self {
57 Self(std::ptr::null_mut())
58 }
59 }
60
61 impl $name {
62 #[inline]
64 pub fn is_null(self) -> bool {
65 self.0.is_null()
66 }
67 }
68 };
69}
70
71define_handle! {
76 CUcontext
78}
79
80define_handle! {
81 CUmodule
83}
84
85define_handle! {
86 CUfunction
88}
89
90define_handle! {
91 CUstream
93}
94
95define_handle! {
96 CUevent
98}
99
100define_handle! {
101 CUmemoryPool
103}
104
105define_handle! {
106 CUtexref
108}
109
110define_handle! {
111 CUsurfref
113}
114
115define_handle! {
116 CUtexObject
118}
119
120define_handle! {
121 CUsurfObject
123}
124
125define_handle! {
126 CUkernel
131}
132
133define_handle! {
134 CUlibrary
139}
140
141define_handle! {
142 CUmulticastObject
147}
148
149#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
155#[repr(u32)]
156#[non_exhaustive]
157pub enum CUmemorytype {
158 Host = 1,
160 Device = 2,
162 Array = 3,
164 Unified = 4,
166}
167
168#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
174#[repr(u32)]
175#[non_exhaustive]
176#[allow(non_camel_case_types)]
177pub enum CUpointer_attribute {
178 Context = 1,
180 MemoryType = 2,
182 DevicePointer = 3,
184 HostPointer = 4,
186 IsManaged = 9,
188 DeviceOrdinal = 10,
190}
191
192#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
198#[repr(u32)]
199#[non_exhaustive]
200pub enum CUlimit {
201 StackSize = 0,
203 PrintfFifoSize = 1,
205 MallocHeapSize = 2,
207 DevRuntimeSyncDepth = 3,
209 DevRuntimePendingLaunchCount = 4,
211 MaxL2FetchGranularity = 5,
213 PersistingL2CacheSize = 6,
215}
216
217#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
223#[repr(i32)]
224#[non_exhaustive]
225#[allow(non_camel_case_types)]
226pub enum CUfunction_attribute {
227 MaxThreadsPerBlock = 0,
229 SharedSizeBytes = 1,
231 ConstSizeBytes = 2,
233 LocalSizeBytes = 3,
235 NumRegs = 4,
237 PtxVersion = 5,
239 BinaryVersion = 6,
241 CacheModeCa = 7,
243 MaxDynamicSharedSizeBytes = 8,
245 PreferredSharedMemoryCarveout = 9,
247}
248
249pub const CUDA_SUCCESS: CUresult = 0;
255
256pub const CUDA_ERROR_INVALID_VALUE: CUresult = 1;
258
259pub const CUDA_ERROR_OUT_OF_MEMORY: CUresult = 2;
261
262pub const CUDA_ERROR_NOT_INITIALIZED: CUresult = 3;
264
265pub const CUDA_ERROR_DEINITIALIZED: CUresult = 4;
267
268pub const CUDA_ERROR_PROFILER_DISABLED: CUresult = 5;
270
271pub const CUDA_ERROR_PROFILER_NOT_INITIALIZED: CUresult = 6;
273
274pub const CUDA_ERROR_PROFILER_ALREADY_STARTED: CUresult = 7;
276
277pub const CUDA_ERROR_PROFILER_ALREADY_STOPPED: CUresult = 8;
279
280pub const CUDA_ERROR_STUB_LIBRARY: CUresult = 34;
282
283pub const CUDA_ERROR_DEVICE_UNAVAILABLE: CUresult = 46;
285
286pub const CUDA_ERROR_NO_DEVICE: CUresult = 100;
288
289pub const CUDA_ERROR_INVALID_DEVICE: CUresult = 101;
291
292pub const CUDA_ERROR_DEVICE_NOT_LICENSED: CUresult = 102;
294
295pub const CUDA_ERROR_INVALID_IMAGE: CUresult = 200;
297
298pub const CUDA_ERROR_INVALID_CONTEXT: CUresult = 201;
300
301pub const CUDA_ERROR_CONTEXT_ALREADY_CURRENT: CUresult = 202;
303
304pub const CUDA_ERROR_MAP_FAILED: CUresult = 205;
306
307pub const CUDA_ERROR_UNMAP_FAILED: CUresult = 206;
309
310pub const CUDA_ERROR_ARRAY_IS_MAPPED: CUresult = 207;
312
313pub const CUDA_ERROR_ALREADY_MAPPED: CUresult = 208;
315
316pub const CUDA_ERROR_NO_BINARY_FOR_GPU: CUresult = 209;
318
319pub const CUDA_ERROR_ALREADY_ACQUIRED: CUresult = 210;
321
322pub const CUDA_ERROR_NOT_MAPPED: CUresult = 211;
324
325pub const CUDA_ERROR_NOT_MAPPED_AS_ARRAY: CUresult = 212;
327
328pub const CUDA_ERROR_NOT_MAPPED_AS_POINTER: CUresult = 213;
330
331pub const CUDA_ERROR_ECC_UNCORRECTABLE: CUresult = 214;
333
334pub const CUDA_ERROR_UNSUPPORTED_LIMIT: CUresult = 215;
336
337pub const CUDA_ERROR_CONTEXT_ALREADY_IN_USE: CUresult = 216;
339
340pub const CUDA_ERROR_PEER_ACCESS_UNSUPPORTED: CUresult = 217;
342
343pub const CUDA_ERROR_INVALID_PTX: CUresult = 218;
345
346pub const CUDA_ERROR_INVALID_GRAPHICS_CONTEXT: CUresult = 219;
348
349pub const CUDA_ERROR_NVLINK_UNCORRECTABLE: CUresult = 220;
351
352pub const CUDA_ERROR_JIT_COMPILER_NOT_FOUND: CUresult = 221;
354
355pub const CUDA_ERROR_UNSUPPORTED_PTX_VERSION: CUresult = 222;
357
358pub const CUDA_ERROR_JIT_COMPILATION_DISABLED: CUresult = 223;
360
361pub const CUDA_ERROR_UNSUPPORTED_EXEC_AFFINITY: CUresult = 224;
363
364pub const CUDA_ERROR_UNSUPPORTED_DEVSIDE_SYNC: CUresult = 225;
366
367pub const CUDA_ERROR_INVALID_SOURCE: CUresult = 300;
369
370pub const CUDA_ERROR_FILE_NOT_FOUND: CUresult = 301;
372
373pub const CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND: CUresult = 302;
375
376pub const CUDA_ERROR_SHARED_OBJECT_INIT_FAILED: CUresult = 303;
378
379pub const CUDA_ERROR_OPERATING_SYSTEM: CUresult = 304;
381
382pub const CUDA_ERROR_INVALID_HANDLE: CUresult = 400;
384
385pub const CUDA_ERROR_ILLEGAL_STATE: CUresult = 401;
387
388pub const CUDA_ERROR_LOSSY_QUERY: CUresult = 402;
390
391pub const CUDA_ERROR_NOT_FOUND: CUresult = 500;
393
394pub const CUDA_ERROR_NOT_READY: CUresult = 600;
396
397pub const CUDA_ERROR_ILLEGAL_ADDRESS: CUresult = 700;
399
400pub const CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES: CUresult = 701;
402
403pub const CUDA_ERROR_LAUNCH_TIMEOUT: CUresult = 702;
405
406pub const CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING: CUresult = 703;
408
409pub const CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED: CUresult = 704;
411
412pub const CUDA_ERROR_PEER_ACCESS_NOT_ENABLED: CUresult = 705;
414
415pub const CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE: CUresult = 708;
417
418pub const CUDA_ERROR_CONTEXT_IS_DESTROYED: CUresult = 709;
420
421pub const CUDA_ERROR_ASSERT: CUresult = 710;
423
424pub const CUDA_ERROR_TOO_MANY_PEERS: CUresult = 711;
426
427pub const CUDA_ERROR_HOST_MEMORY_ALREADY_REGISTERED: CUresult = 712;
429
430pub const CUDA_ERROR_HOST_MEMORY_NOT_REGISTERED: CUresult = 713;
432
433pub const CUDA_ERROR_HARDWARE_STACK_ERROR: CUresult = 714;
435
436pub const CUDA_ERROR_ILLEGAL_INSTRUCTION: CUresult = 715;
438
439pub const CUDA_ERROR_MISALIGNED_ADDRESS: CUresult = 716;
441
442pub const CUDA_ERROR_INVALID_ADDRESS_SPACE: CUresult = 717;
444
445pub const CUDA_ERROR_INVALID_PC: CUresult = 718;
447
448pub const CUDA_ERROR_LAUNCH_FAILED: CUresult = 719;
450
451pub const CUDA_ERROR_COOPERATIVE_LAUNCH_TOO_LARGE: CUresult = 720;
453
454pub const CUDA_ERROR_NOT_PERMITTED: CUresult = 800;
456
457pub const CUDA_ERROR_NOT_SUPPORTED: CUresult = 801;
459
460pub const CUDA_ERROR_SYSTEM_NOT_READY: CUresult = 802;
462
463pub const CUDA_ERROR_SYSTEM_DRIVER_MISMATCH: CUresult = 803;
465
466pub const CUDA_ERROR_COMPAT_NOT_SUPPORTED_ON_DEVICE: CUresult = 804;
468
469pub const CUDA_ERROR_MPS_CONNECTION_FAILED: CUresult = 805;
471
472pub const CUDA_ERROR_MPS_RPC_FAILURE: CUresult = 806;
474
475pub const CUDA_ERROR_MPS_SERVER_NOT_READY: CUresult = 807;
477
478pub const CUDA_ERROR_MPS_MAX_CLIENTS_REACHED: CUresult = 808;
480
481pub const CUDA_ERROR_MPS_MAX_CONNECTIONS_REACHED: CUresult = 809;
483
484pub const CUDA_ERROR_MPS_CLIENT_TERMINATED: CUresult = 810;
486
487pub const CUDA_ERROR_CDP_NOT_SUPPORTED: CUresult = 811;
489
490pub const CUDA_ERROR_CDP_VERSION_MISMATCH: CUresult = 812;
492
493pub const CUDA_ERROR_STREAM_CAPTURE_UNSUPPORTED: CUresult = 900;
495
496pub const CUDA_ERROR_STREAM_CAPTURE_INVALIDATED: CUresult = 901;
498
499pub const CUDA_ERROR_STREAM_CAPTURE_MERGE: CUresult = 902;
501
502pub const CUDA_ERROR_STREAM_CAPTURE_UNMATCHED: CUresult = 903;
504
505pub const CUDA_ERROR_STREAM_CAPTURE_UNJOINED: CUresult = 904;
507
508pub const CUDA_ERROR_STREAM_CAPTURE_ISOLATION: CUresult = 905;
510
511pub const CUDA_ERROR_STREAM_CAPTURE_IMPLICIT: CUresult = 906;
513
514pub const CUDA_ERROR_CAPTURED_EVENT: CUresult = 907;
516
517pub const CUDA_ERROR_STREAM_CAPTURE_WRONG_THREAD: CUresult = 908;
519
520pub const CUDA_ERROR_TIMEOUT: CUresult = 909;
522
523pub const CUDA_ERROR_GRAPH_EXEC_UPDATE_FAILURE: CUresult = 910;
525
526pub const CUDA_ERROR_EXTERNAL_DEVICE: CUresult = 911;
528
529pub const CUDA_ERROR_INVALID_CLUSTER_SIZE: CUresult = 912;
531
532pub const CUDA_ERROR_FUNCTION_NOT_LOADED: CUresult = 913;
534
535pub const CUDA_ERROR_INVALID_RESOURCE_TYPE: CUresult = 914;
537
538pub const CUDA_ERROR_INVALID_RESOURCE_CONFIGURATION: CUresult = 915;
540
541pub const CUDA_ERROR_UNKNOWN: CUresult = 999;
543
544#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
550#[repr(i32)]
551#[non_exhaustive]
552#[allow(non_camel_case_types)]
553pub enum CUdevice_attribute {
554 MaxThreadsPerBlock = 1,
556 MaxBlockDimX = 2,
558 MaxBlockDimY = 3,
560 MaxBlockDimZ = 4,
562 MaxGridDimX = 5,
564 MaxGridDimY = 6,
566 MaxGridDimZ = 7,
568 MaxSharedMemoryPerBlock = 8,
570 TotalConstantMemory = 9,
572 WarpSize = 10,
574 MaxPitch = 11,
576 MaxRegistersPerBlock = 12,
578 ClockRate = 13,
580 TextureAlignment = 14,
582 GpuOverlap = 15,
584 MultiprocessorCount = 16,
586 KernelExecTimeout = 17,
588 Integrated = 18,
590 CanMapHostMemory = 19,
592 ComputeMode = 20,
594 MaxTexture1DWidth = 21,
596 MaxTexture2DWidth = 22,
598 MaxTexture2DHeight = 23,
600 MaxTexture3DWidth = 24,
602 MaxTexture3DHeight = 25,
604 MaxTexture3DDepth = 26,
606 MaxTexture2DLayeredWidth = 27,
608 MaxTexture2DLayeredHeight = 28,
610 MaxTexture2DLayeredLayers = 29,
612 SurfaceAlignment = 30,
614 ConcurrentKernels = 31,
616 EccEnabled = 32,
618 PciBusId = 33,
620 PciDeviceId = 34,
622 TccDriver = 35,
624 MemoryClockRate = 36,
626 GlobalMemoryBusWidth = 37,
628 L2CacheSize = 38,
630 MaxThreadsPerMultiprocessor = 39,
632 AsyncEngineCount = 40,
634 UnifiedAddressing = 41,
636 MaxTexture1DLayeredWidth = 42,
638 MaxTexture1DLayeredLayers = 43,
640 MaxTexture2DGatherWidth = 44,
642 MaxTexture2DGatherHeight = 45,
644 MaxTexture3DWidthAlt = 47,
646 MaxTexture3DHeightAlt = 48,
648 MaxTexture3DDepthAlt = 49,
650 PciDomainId = 50,
652 TexturePitchAlignment = 51,
654 MaxTexture1DMipmappedWidth2 = 52,
656 MaxTextureCubemapWidth = 54,
658 MaxTextureCubemapLayeredWidth = 55,
660 MaxTextureCubemapLayeredLayers = 56,
662 MaxSurface1DWidth = 57,
664 MaxSurface2DWidth = 58,
666 MaxSurface2DHeight = 59,
668 MaxSurface3DWidth = 60,
670 MaxSurface3DHeight = 61,
672 MaxSurface3DDepth = 62,
674 MaxSurfaceCubemapWidth = 63,
676 MaxSurface1DLayeredWidth = 64,
678 MaxSurface1DLayeredLayers = 65,
680 MaxSurface2DLayeredWidth = 66,
682 MaxSurface2DLayeredHeight = 67,
684 MaxSurface2DLayeredLayers = 68,
686 MaxSurfaceCubemapLayeredWidth = 69,
688 MaxSurfaceCubemapLayeredLayers = 70,
690 MaxTexture1DLinearWidth = 71,
692 MaxTexture2DLinearWidth = 72,
694 MaxTexture2DLinearHeight = 73,
696 MaxTexture2DLinearPitch = 74,
698 ComputeCapabilityMajor = 75,
700 ComputeCapabilityMinor = 76,
702 MaxTexture2DMipmappedWidth = 77,
704 MaxTexture2DMipmappedHeight = 78,
706 MaxTexture1DMipmappedWidth = 79,
708 StreamPrioritiesSupported = 80,
710 MaxSharedMemoryPerMultiprocessor = 81,
712 MaxRegistersPerMultiprocessor = 82,
714 ManagedMemory = 83,
716 IsMultiGpuBoard = 84,
718 MultiGpuBoardGroupId = 85,
720 HostNativeAtomicSupported = 86,
722 SingleToDoublePrecisionPerfRatio = 87,
724 PageableMemoryAccess = 88,
726 ConcurrentManagedAccess = 89,
728 ComputePreemptionSupported = 90,
730 CanUseHostPointerForRegisteredMem = 91,
732 Reserved92 = 92,
734 Reserved93 = 93,
736 Reserved94 = 94,
738 CooperativeLaunch = 95,
740 CooperativeMultiDeviceLaunch = 96,
742 MaxSharedMemoryPerBlockOptin = 97,
744 CanFlushRemoteWrites = 98,
746 HostRegisterSupported = 99,
748 PageableMemoryAccessUsesHostPageTables = 100,
750 DirectManagedMemAccessFromHost = 101,
752 VirtualMemoryManagementSupported = 102,
754 HandleTypePosixFileDescriptorSupported = 103,
756 HandleTypeWin32HandleSupported = 104,
758 HandleTypeWin32KmtHandleSupported = 105,
760 MaxBlocksPerMultiprocessor = 106,
762 GenericCompressionSupported = 107,
764 MaxPersistingL2CacheSize = 108,
766 MaxAccessPolicyWindowSize = 109,
768 GpuDirectRdmaWithCudaVmmSupported = 110,
770 AccessPolicyMaxWindowSize = 111,
772 ReservedSharedMemoryPerBlock = 112,
774 TimelineSemaphoreInteropSupported = 113,
776 MemoryPoolsSupported = 115,
778 GpuDirectRdmaSupported = 116,
780 GpuDirectRdmaFlushWritesOptions = 117,
782 GpuDirectRdmaWritesOrdering = 118,
784 MemoryPoolSupportedHandleTypes = 119,
786 ClusterLaunch = 120,
788 DeferredMappingCudaArraySupported = 121,
790 IpcEventSupported = 122,
792 MemSyncDomainCount = 123,
794 TensorMapAccessSupported = 124,
796 UnifiedFunctionPointers = 125,
798 NumaConfig = 127,
800 NumaId = 128,
802 MaxTimelineSemaphoreInteropSupported = 129,
806 MemSyncDomainSupported = 130,
808 GpuDirectRdmaFabricSupported = 131,
810 MulticastSupported = 132,
812 MpsEnabled = 133,
814 HostNumaId = 134,
816}
817
818#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
824#[repr(u32)]
825#[non_exhaustive]
826#[allow(non_camel_case_types)]
827pub enum CUjit_option {
828 MaxRegisters = 0,
830 ThreadsPerBlock = 1,
832 WallTime = 2,
834 InfoLogBuffer = 3,
836 InfoLogBufferSizeBytes = 4,
838 ErrorLogBuffer = 5,
840 ErrorLogBufferSizeBytes = 6,
842 OptimizationLevel = 7,
844 TargetFromCuContext = 8,
846 Target = 9,
848 FallbackStrategy = 10,
850 GenerateDebugInfo = 11,
852 LogVerbose = 12,
854 GenerateLineInfo = 13,
856 CacheMode = 14,
858 Sm3xOpt = 15,
860 FastCompile = 16,
862 GlobalSymbolNames = 17,
864 GlobalSymbolAddresses = 18,
866 GlobalSymbolCount = 19,
868 Lto = 20,
870 Ftz = 21,
872 PrecDiv = 22,
874 PrecSqrt = 23,
876 Fma = 24,
878 ReferencedKernelNames = 25,
880 ReferencedKernelCount = 26,
882 ReferencedVariableNames = 27,
884 ReferencedVariableCount = 28,
886 OptimizeUnusedDeviceVariables = 29,
888 PositionIndependentCode = 30,
890}
891
892#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
898#[repr(u32)]
899#[non_exhaustive]
900pub enum CUjitInputType {
901 Ptx = 1,
903 Cubin = 2,
905 Fatbin = 3,
907 Object = 4,
909 Library = 5,
911}
912
913#[path = "ffi_constants.rs"]
918mod ffi_constants;
919pub use ffi_constants::*;
920
921#[path = "ffi_launch.rs"]
922mod ffi_launch;
923pub use ffi_launch::*;
924
925#[path = "ffi_descriptors.rs"]
926mod ffi_descriptors;
927pub use ffi_descriptors::*;
928
929#[cfg(test)]
934mod tests {
935 use super::*;
936
937 #[test]
938 fn test_cuda_success_is_zero() {
939 assert_eq!(CUDA_SUCCESS, 0);
940 }
941
942 #[test]
943 fn test_opaque_types_are_pointer_sized() {
944 assert_eq!(
945 std::mem::size_of::<CUcontext>(),
946 std::mem::size_of::<*mut c_void>()
947 );
948 assert_eq!(
949 std::mem::size_of::<CUmodule>(),
950 std::mem::size_of::<*mut c_void>()
951 );
952 assert_eq!(
953 std::mem::size_of::<CUstream>(),
954 std::mem::size_of::<*mut c_void>()
955 );
956 assert_eq!(
957 std::mem::size_of::<CUevent>(),
958 std::mem::size_of::<*mut c_void>()
959 );
960 assert_eq!(
961 std::mem::size_of::<CUfunction>(),
962 std::mem::size_of::<*mut c_void>()
963 );
964 assert_eq!(
965 std::mem::size_of::<CUmemoryPool>(),
966 std::mem::size_of::<*mut c_void>()
967 );
968 }
969
970 #[test]
971 fn test_handle_default_is_null() {
972 assert!(CUcontext::default().is_null());
973 assert!(CUmodule::default().is_null());
974 assert!(CUfunction::default().is_null());
975 assert!(CUstream::default().is_null());
976 assert!(CUevent::default().is_null());
977 assert!(CUmemoryPool::default().is_null());
978 }
979
980 #[test]
981 fn test_device_attribute_repr() {
982 assert_eq!(CUdevice_attribute::MaxThreadsPerBlock as i32, 1);
984 assert_eq!(CUdevice_attribute::WarpSize as i32, 10);
985 assert_eq!(CUdevice_attribute::MultiprocessorCount as i32, 16);
986 assert_eq!(CUdevice_attribute::ComputeCapabilityMajor as i32, 75);
987 assert_eq!(CUdevice_attribute::ComputeCapabilityMinor as i32, 76);
988 assert_eq!(CUdevice_attribute::MaxBlocksPerMultiprocessor as i32, 106);
989 assert_eq!(CUdevice_attribute::L2CacheSize as i32, 38);
990 assert_eq!(
991 CUdevice_attribute::MaxSharedMemoryPerMultiprocessor as i32,
992 81
993 );
994 assert_eq!(CUdevice_attribute::ManagedMemory as i32, 83);
995
996 assert_eq!(CUdevice_attribute::MaxTexture2DGatherWidth as i32, 44);
998 assert_eq!(CUdevice_attribute::MaxTexture2DGatherHeight as i32, 45);
999 assert_eq!(CUdevice_attribute::MaxTexture3DWidthAlt as i32, 47);
1000 assert_eq!(CUdevice_attribute::MaxTexture3DHeightAlt as i32, 48);
1001 assert_eq!(CUdevice_attribute::MaxTexture3DDepthAlt as i32, 49);
1002 assert_eq!(CUdevice_attribute::MaxTexture1DMipmappedWidth2 as i32, 52);
1003 assert_eq!(CUdevice_attribute::Reserved92 as i32, 92);
1004 assert_eq!(CUdevice_attribute::Reserved93 as i32, 93);
1005 assert_eq!(CUdevice_attribute::Reserved94 as i32, 94);
1006 assert_eq!(
1007 CUdevice_attribute::VirtualMemoryManagementSupported as i32,
1008 102
1009 );
1010 assert_eq!(
1011 CUdevice_attribute::HandleTypePosixFileDescriptorSupported as i32,
1012 103
1013 );
1014 assert_eq!(
1015 CUdevice_attribute::HandleTypeWin32HandleSupported as i32,
1016 104
1017 );
1018 assert_eq!(
1019 CUdevice_attribute::HandleTypeWin32KmtHandleSupported as i32,
1020 105
1021 );
1022 assert_eq!(CUdevice_attribute::AccessPolicyMaxWindowSize as i32, 111);
1023 assert_eq!(CUdevice_attribute::ReservedSharedMemoryPerBlock as i32, 112);
1024 assert_eq!(
1025 CUdevice_attribute::TimelineSemaphoreInteropSupported as i32,
1026 113
1027 );
1028 assert_eq!(CUdevice_attribute::MemoryPoolsSupported as i32, 115);
1029 assert_eq!(CUdevice_attribute::ClusterLaunch as i32, 120);
1030 assert_eq!(CUdevice_attribute::UnifiedFunctionPointers as i32, 125);
1031 assert_eq!(
1032 CUdevice_attribute::MaxTimelineSemaphoreInteropSupported as i32,
1033 129
1034 );
1035 assert_eq!(CUdevice_attribute::MemSyncDomainSupported as i32, 130);
1036 assert_eq!(CUdevice_attribute::GpuDirectRdmaFabricSupported as i32, 131);
1037 }
1038
1039 #[test]
1040 fn test_jit_option_repr() {
1041 assert_eq!(CUjit_option::MaxRegisters as u32, 0);
1042 assert_eq!(CUjit_option::ThreadsPerBlock as u32, 1);
1043 assert_eq!(CUjit_option::WallTime as u32, 2);
1044 assert_eq!(CUjit_option::InfoLogBuffer as u32, 3);
1045 assert_eq!(CUjit_option::InfoLogBufferSizeBytes as u32, 4);
1046 assert_eq!(CUjit_option::ErrorLogBuffer as u32, 5);
1047 assert_eq!(CUjit_option::ErrorLogBufferSizeBytes as u32, 6);
1048 assert_eq!(CUjit_option::OptimizationLevel as u32, 7);
1049 assert_eq!(CUjit_option::Target as u32, 9);
1050 assert_eq!(CUjit_option::FallbackStrategy as u32, 10);
1051 }
1052
1053 #[test]
1054 #[allow(clippy::assertions_on_constants)]
1055 fn test_error_code_ranges() {
1056 assert!(CUDA_ERROR_INVALID_VALUE < 10);
1058 assert!((100..=102).contains(&CUDA_ERROR_NO_DEVICE));
1060 assert!((100..=102).contains(&CUDA_ERROR_INVALID_DEVICE));
1061 assert!((100..=102).contains(&CUDA_ERROR_DEVICE_NOT_LICENSED));
1062 assert!(CUDA_ERROR_INVALID_IMAGE >= 200);
1064 assert!(CUDA_ERROR_LAUNCH_FAILED >= 700);
1066 assert!(CUDA_ERROR_ILLEGAL_ADDRESS >= 700);
1067 assert!(CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES >= 700);
1068 assert!(CUDA_ERROR_STREAM_CAPTURE_UNSUPPORTED >= 900);
1070 assert_eq!(CUDA_ERROR_UNKNOWN, 999);
1072 }
1073
1074 #[test]
1075 fn test_handle_debug_format() {
1076 let ctx = CUcontext::default();
1077 let debug_str = format!("{ctx:?}");
1078 assert!(debug_str.starts_with("CUcontext("));
1079 }
1080
1081 #[test]
1082 fn test_handle_equality() {
1083 let a = CUcontext::default();
1084 let b = CUcontext::default();
1085 assert_eq!(a, b);
1086 }
1087
1088 #[test]
1089 fn test_new_handle_types_are_pointer_sized() {
1090 assert_eq!(
1091 std::mem::size_of::<CUtexref>(),
1092 std::mem::size_of::<*mut c_void>()
1093 );
1094 assert_eq!(
1095 std::mem::size_of::<CUsurfref>(),
1096 std::mem::size_of::<*mut c_void>()
1097 );
1098 assert_eq!(
1099 std::mem::size_of::<CUtexObject>(),
1100 std::mem::size_of::<*mut c_void>()
1101 );
1102 assert_eq!(
1103 std::mem::size_of::<CUsurfObject>(),
1104 std::mem::size_of::<*mut c_void>()
1105 );
1106 }
1107
1108 #[test]
1109 fn test_new_handle_defaults_are_null() {
1110 assert!(CUtexref::default().is_null());
1111 assert!(CUsurfref::default().is_null());
1112 assert!(CUtexObject::default().is_null());
1113 assert!(CUsurfObject::default().is_null());
1114 }
1115
1116 #[test]
1117 fn test_memory_type_enum() {
1118 assert_eq!(CUmemorytype::Host as u32, 1);
1119 assert_eq!(CUmemorytype::Device as u32, 2);
1120 assert_eq!(CUmemorytype::Array as u32, 3);
1121 assert_eq!(CUmemorytype::Unified as u32, 4);
1122 }
1123
1124 #[test]
1125 fn test_pointer_attribute_enum() {
1126 assert_eq!(CUpointer_attribute::Context as u32, 1);
1127 assert_eq!(CUpointer_attribute::MemoryType as u32, 2);
1128 assert_eq!(CUpointer_attribute::DevicePointer as u32, 3);
1129 assert_eq!(CUpointer_attribute::HostPointer as u32, 4);
1130 assert_eq!(CUpointer_attribute::IsManaged as u32, 9);
1131 assert_eq!(CUpointer_attribute::DeviceOrdinal as u32, 10);
1132 }
1133
1134 #[test]
1135 fn test_limit_enum() {
1136 assert_eq!(CUlimit::StackSize as u32, 0);
1137 assert_eq!(CUlimit::PrintfFifoSize as u32, 1);
1138 assert_eq!(CUlimit::MallocHeapSize as u32, 2);
1139 assert_eq!(CUlimit::DevRuntimeSyncDepth as u32, 3);
1140 assert_eq!(CUlimit::DevRuntimePendingLaunchCount as u32, 4);
1141 assert_eq!(CUlimit::MaxL2FetchGranularity as u32, 5);
1142 assert_eq!(CUlimit::PersistingL2CacheSize as u32, 6);
1143 }
1144
1145 #[test]
1146 fn test_function_attribute_enum() {
1147 assert_eq!(CUfunction_attribute::MaxThreadsPerBlock as i32, 0);
1148 assert_eq!(CUfunction_attribute::SharedSizeBytes as i32, 1);
1149 assert_eq!(CUfunction_attribute::NumRegs as i32, 4);
1150 assert_eq!(CUfunction_attribute::PtxVersion as i32, 5);
1151 assert_eq!(CUfunction_attribute::BinaryVersion as i32, 6);
1152 assert_eq!(CUfunction_attribute::MaxDynamicSharedSizeBytes as i32, 8);
1153 assert_eq!(
1154 CUfunction_attribute::PreferredSharedMemoryCarveout as i32,
1155 9
1156 );
1157 }
1158}