Skip to main content

baracuda_cuda_sys/runtime/
types.rs

1//! Core handle types used by the CUDA Runtime API.
2//!
3//! Most of these are typedef-compatible with the Driver API handles
4//! (`cudaStream_t == CUstream`, `cudaEvent_t == CUevent`, ...) so
5//! Driver↔Runtime conversions are zero-cost.
6
7use core::ffi::c_void;
8
9/// Opaque CUDA stream (typedef-compatible with [`crate::CUstream`]).
10pub type cudaStream_t = *mut c_void;
11
12/// Opaque CUDA event (typedef-compatible with [`crate::CUevent`]).
13pub type cudaEvent_t = *mut c_void;
14
15/// Opaque CUDA graph.
16pub type cudaGraph_t = *mut c_void;
17
18/// Opaque executable graph.
19pub type cudaGraphExec_t = *mut c_void;
20
21/// Opaque graph node.
22pub type cudaGraphNode_t = *mut c_void;
23
24/// Opaque CUDA memory pool.
25pub type cudaMemPool_t = *mut c_void;
26
27/// Opaque CUDA array.
28pub type cudaArray_t = *mut c_void;
29
30/// Opaque CUDA mipmapped array (CUDA 5+).
31pub type cudaMipmappedArray_t = *mut c_void;
32
33/// `cudaTextureObject_t` — 64-bit opaque texture object handle.
34pub type cudaTextureObject_t = u64;
35
36/// `cudaSurfaceObject_t` — 64-bit opaque surface object handle.
37pub type cudaSurfaceObject_t = u64;
38
39/// `cudaMemGenericAllocationHandle_t` — opaque VMM allocation handle.
40pub type cudaMemGenericAllocationHandle_t = u64;
41
42/// `cudaGreenCtx_t` — green-context handle (CUDA 13.1+).
43pub type cudaGreenCtx_t = *mut c_void;
44
45/// `cudaChannelFormatKind` — texel format family.
46#[allow(non_snake_case)]
47pub mod cudaChannelFormatKind {
48    pub const SIGNED: i32 = 0;
49    pub const UNSIGNED: i32 = 1;
50    pub const FLOAT: i32 = 2;
51    pub const NONE: i32 = 3;
52}
53
54/// `cudaChannelFormatDesc` — 20-byte descriptor (4×c_int + c_int kind).
55#[repr(C)]
56#[derive(Copy, Clone, Debug, Default)]
57#[allow(non_camel_case_types)]
58pub struct cudaChannelFormatDesc {
59    pub x: core::ffi::c_int,
60    pub y: core::ffi::c_int,
61    pub z: core::ffi::c_int,
62    pub w: core::ffi::c_int,
63    pub kind: core::ffi::c_int,
64}
65
66/// `cudaExtent` — 3D size in elements (width) + texels (height/depth).
67#[repr(C)]
68#[derive(Copy, Clone, Debug, Default)]
69#[allow(non_camel_case_types)]
70pub struct cudaExtent {
71    pub width: usize,
72    pub height: usize,
73    pub depth: usize,
74}
75
76/// `cudaPos` — 3D starting offset inside an array.
77#[repr(C)]
78#[derive(Copy, Clone, Debug, Default)]
79#[allow(non_camel_case_types)]
80pub struct cudaPos {
81    pub x: usize,
82    pub y: usize,
83    pub z: usize,
84}
85
86/// `cudaPitchedPtr` — pitched device pointer (from `cudaMalloc3D`).
87#[repr(C)]
88#[derive(Copy, Clone, Debug)]
89#[allow(non_camel_case_types)]
90pub struct cudaPitchedPtr {
91    pub ptr: *mut c_void,
92    pub pitch: usize,
93    pub xsize: usize,
94    pub ysize: usize,
95}
96
97impl Default for cudaPitchedPtr {
98    fn default() -> Self {
99        Self {
100            ptr: core::ptr::null_mut(),
101            pitch: 0,
102            xsize: 0,
103            ysize: 0,
104        }
105    }
106}
107
108/// `cudaMemcpy3DParms` — full 3D memcpy descriptor.
109#[repr(C)]
110#[derive(Copy, Clone, Debug)]
111#[allow(non_camel_case_types)]
112pub struct cudaMemcpy3DParms {
113    pub src_array: cudaArray_t,
114    pub src_pos: cudaPos,
115    pub src_ptr: cudaPitchedPtr,
116    pub dst_array: cudaArray_t,
117    pub dst_pos: cudaPos,
118    pub dst_ptr: cudaPitchedPtr,
119    pub extent: cudaExtent,
120    pub kind: cudaMemcpyKind,
121}
122
123impl Default for cudaMemcpy3DParms {
124    fn default() -> Self {
125        Self {
126            src_array: core::ptr::null_mut(),
127            src_pos: cudaPos::default(),
128            src_ptr: cudaPitchedPtr::default(),
129            dst_array: core::ptr::null_mut(),
130            dst_pos: cudaPos::default(),
131            dst_ptr: cudaPitchedPtr::default(),
132            extent: cudaExtent::default(),
133            kind: cudaMemcpyKind::Default,
134        }
135    }
136}
137
138/// `cudaResourceType` — what a `cudaResourceDesc` points at.
139#[allow(non_snake_case)]
140pub mod cudaResourceType {
141    pub const ARRAY: i32 = 0;
142    pub const MIPMAPPED_ARRAY: i32 = 1;
143    pub const LINEAR: i32 = 2;
144    pub const PITCH_2D: i32 = 3;
145}
146
147/// `cudaResourceDesc` — tagged union describing a texture/surface source.
148/// Layout: `type: i32` + 4-byte pad + 32-byte union payload + 8-byte pad.
149/// We model the union as an opaque byte buffer and expose typed builders.
150#[repr(C)]
151#[derive(Copy, Clone)]
152#[allow(non_camel_case_types)]
153pub struct cudaResourceDesc {
154    pub res_type: core::ffi::c_int,
155    _pad0: u32,
156    /// 32 bytes — the widest union arm (pitch2D: devPtr + desc + w + h + pitch).
157    pub payload: [u8; 32],
158    _pad1: [u8; 8],
159}
160
161impl Default for cudaResourceDesc {
162    fn default() -> Self {
163        Self {
164            res_type: cudaResourceType::ARRAY,
165            _pad0: 0,
166            payload: [0; 32],
167            _pad1: [0; 8],
168        }
169    }
170}
171
172impl core::fmt::Debug for cudaResourceDesc {
173    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
174        f.debug_struct("cudaResourceDesc")
175            .field("type", &self.res_type)
176            .finish_non_exhaustive()
177    }
178}
179
180impl cudaResourceDesc {
181    /// Build an `ARRAY`-type descriptor.
182    #[allow(clippy::not_unsafe_ptr_arg_deref)]
183    pub fn from_array(array: cudaArray_t) -> Self {
184        let mut s = Self {
185            res_type: cudaResourceType::ARRAY,
186            ..Default::default()
187        };
188        unsafe {
189            let p = s.payload.as_mut_ptr();
190            (p as *mut cudaArray_t).write_unaligned(array);
191        }
192        s
193    }
194
195    /// Build a `MIPMAPPED_ARRAY`-type descriptor.
196    #[allow(clippy::not_unsafe_ptr_arg_deref)]
197    pub fn from_mipmapped(mipmap: cudaMipmappedArray_t) -> Self {
198        let mut s = Self {
199            res_type: cudaResourceType::MIPMAPPED_ARRAY,
200            ..Default::default()
201        };
202        unsafe {
203            let p = s.payload.as_mut_ptr();
204            (p as *mut cudaMipmappedArray_t).write_unaligned(mipmap);
205        }
206        s
207    }
208
209    /// Build a `LINEAR`-type descriptor: bytewise view of a device pointer.
210    #[allow(clippy::not_unsafe_ptr_arg_deref)]
211    pub fn from_linear(
212        dev_ptr: *mut c_void,
213        desc: cudaChannelFormatDesc,
214        size_in_bytes: usize,
215    ) -> Self {
216        let mut s = Self {
217            res_type: cudaResourceType::LINEAR,
218            ..Default::default()
219        };
220        unsafe {
221            let p = s.payload.as_mut_ptr();
222            (p as *mut *mut c_void).write_unaligned(dev_ptr);
223            (p.add(8) as *mut cudaChannelFormatDesc).write_unaligned(desc);
224            (p.add(28) as *mut usize).write_unaligned(size_in_bytes); // offset after 8+20=28
225        }
226        s
227    }
228}
229
230/// `cudaTextureAddressMode` — out-of-bounds sampler behavior.
231#[allow(non_snake_case)]
232pub mod cudaTextureAddressMode {
233    pub const WRAP: i32 = 0;
234    pub const CLAMP: i32 = 1;
235    pub const MIRROR: i32 = 2;
236    pub const BORDER: i32 = 3;
237}
238
239/// `cudaTextureFilterMode` — filter kernel on fetch.
240#[allow(non_snake_case)]
241pub mod cudaTextureFilterMode {
242    pub const POINT: i32 = 0;
243    pub const LINEAR: i32 = 1;
244}
245
246/// `cudaTextureReadMode` — element-type reinterpretation on fetch.
247#[allow(non_snake_case)]
248pub mod cudaTextureReadMode {
249    pub const ELEMENT_TYPE: i32 = 0;
250    pub const NORMALIZED_FLOAT: i32 = 1;
251}
252
253/// `cudaTextureDesc` — sampler state (filter/address/normalize/mipmap).
254#[repr(C)]
255#[derive(Copy, Clone, Debug)]
256#[allow(non_camel_case_types)]
257pub struct cudaTextureDesc {
258    pub address_mode: [core::ffi::c_int; 3],
259    pub filter_mode: core::ffi::c_int,
260    pub read_mode: core::ffi::c_int,
261    pub srgb: core::ffi::c_int,
262    pub border_color: [f32; 4],
263    pub normalized_coords: core::ffi::c_int,
264    pub max_anisotropy: core::ffi::c_uint,
265    pub mipmap_filter_mode: core::ffi::c_int,
266    pub mipmap_level_bias: f32,
267    pub min_mipmap_level_clamp: f32,
268    pub max_mipmap_level_clamp: f32,
269    pub disable_trilinear_optimization: core::ffi::c_int,
270    pub seamless_cubemap: core::ffi::c_int,
271}
272
273impl Default for cudaTextureDesc {
274    fn default() -> Self {
275        Self {
276            address_mode: [cudaTextureAddressMode::CLAMP; 3],
277            filter_mode: cudaTextureFilterMode::POINT,
278            read_mode: cudaTextureReadMode::ELEMENT_TYPE,
279            srgb: 0,
280            border_color: [0.0; 4],
281            normalized_coords: 0,
282            max_anisotropy: 0,
283            mipmap_filter_mode: cudaTextureFilterMode::POINT,
284            mipmap_level_bias: 0.0,
285            min_mipmap_level_clamp: 0.0,
286            max_mipmap_level_clamp: 0.0,
287            disable_trilinear_optimization: 0,
288            seamless_cubemap: 0,
289        }
290    }
291}
292
293/// `cudaResourceViewDesc` — optional view transformation applied on fetch.
294#[repr(C)]
295#[derive(Copy, Clone, Debug, Default)]
296#[allow(non_camel_case_types)]
297pub struct cudaResourceViewDesc {
298    pub format: core::ffi::c_int,
299    pub width: usize,
300    pub height: usize,
301    pub depth: usize,
302    pub first_mipmap_level: core::ffi::c_uint,
303    pub last_mipmap_level: core::ffi::c_uint,
304    pub first_layer: core::ffi::c_uint,
305    pub last_layer: core::ffi::c_uint,
306}
307
308/// `cudaLaunchAttributeID` — selectors for extended launch attributes.
309#[allow(non_snake_case)]
310pub mod cudaLaunchAttributeID {
311    pub const IGNORE: i32 = 0;
312    pub const ACCESS_POLICY_WINDOW: i32 = 1;
313    pub const COOPERATIVE: i32 = 2;
314    pub const SYNC_POLICY: i32 = 3;
315    pub const CLUSTER_DIMENSION: i32 = 4;
316    pub const CLUSTER_SCHEDULING_POLICY_PREFERENCE: i32 = 5;
317    pub const PROGRAMMATIC_STREAM_SERIALIZATION: i32 = 6;
318    pub const PROGRAMMATIC_EVENT: i32 = 7;
319    pub const PRIORITY: i32 = 8;
320    pub const MEM_SYNC_DOMAIN_MAP: i32 = 9;
321    pub const MEM_SYNC_DOMAIN: i32 = 10;
322    pub const LAUNCH_COMPLETION_EVENT: i32 = 12;
323    pub const DEVICE_UPDATABLE_KERNEL_NODE: i32 = 13;
324}
325
326/// `cudaLaunchAttributeValue` — 64-byte union payload.
327#[repr(C, align(8))]
328#[derive(Copy, Clone)]
329#[allow(non_camel_case_types)]
330pub struct cudaLaunchAttributeValue {
331    pub raw: [u8; 64],
332}
333
334impl Default for cudaLaunchAttributeValue {
335    fn default() -> Self {
336        Self { raw: [0; 64] }
337    }
338}
339
340impl core::fmt::Debug for cudaLaunchAttributeValue {
341    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
342        f.debug_struct("cudaLaunchAttributeValue")
343            .finish_non_exhaustive()
344    }
345}
346
347impl cudaLaunchAttributeValue {
348    /// Cluster-dimension payload (3 × u32, rest zero).
349    pub fn cluster_dimension(x: u32, y: u32, z: u32) -> Self {
350        let mut v = Self::default();
351        unsafe {
352            let p = v.raw.as_mut_ptr() as *mut u32;
353            p.write(x);
354            p.add(1).write(y);
355            p.add(2).write(z);
356        }
357        v
358    }
359
360    /// COOPERATIVE = 1 (i.e., enable cooperative launch).
361    pub fn cooperative(enable: bool) -> Self {
362        let mut v = Self::default();
363        unsafe {
364            let p = v.raw.as_mut_ptr() as *mut core::ffi::c_int;
365            p.write(if enable { 1 } else { 0 });
366        }
367        v
368    }
369
370    /// Priority payload (signed 32-bit).
371    pub fn priority(prio: i32) -> Self {
372        let mut v = Self::default();
373        unsafe {
374            let p = v.raw.as_mut_ptr() as *mut i32;
375            p.write(prio);
376        }
377        v
378    }
379}
380
381/// `cudaLaunchAttribute` — paired ID + value entry.
382#[repr(C)]
383#[derive(Copy, Clone, Debug)]
384#[allow(non_camel_case_types)]
385pub struct cudaLaunchAttribute {
386    pub id: core::ffi::c_int,
387    pub _pad: core::ffi::c_int,
388    pub val: cudaLaunchAttributeValue,
389}
390
391/// `cudaLaunchConfig_t` — the config object consumed by `cudaLaunchKernelEx`.
392#[repr(C)]
393#[derive(Copy, Clone, Debug)]
394#[allow(non_camel_case_types)]
395pub struct cudaLaunchConfig_t {
396    pub grid_dim: dim3,
397    pub block_dim: dim3,
398    pub dynamic_smem_bytes: usize,
399    pub stream: cudaStream_t,
400    pub attrs: *mut cudaLaunchAttribute,
401    pub num_attrs: core::ffi::c_uint,
402}
403
404impl Default for cudaLaunchConfig_t {
405    fn default() -> Self {
406        Self {
407            grid_dim: dim3::default(),
408            block_dim: dim3::default(),
409            dynamic_smem_bytes: 0,
410            stream: core::ptr::null_mut(),
411            attrs: core::ptr::null_mut(),
412            num_attrs: 0,
413        }
414    }
415}
416
417/// `cudaMemAllocationProp` — properties for VMM `cudaMemCreate`.
418/// Shared ABI with the Driver API's `CUmemAllocationProp`.
419#[repr(C)]
420#[derive(Copy, Clone, Debug)]
421#[allow(non_camel_case_types)]
422pub struct cudaMemAllocationProp {
423    pub alloc_type: core::ffi::c_int, // cudaMemAllocationType
424    pub requested_handle_types: core::ffi::c_int, // cudaMemAllocationHandleType
425    pub location: super::types::cudaMemLocation,
426    pub win32_handle_meta_data: *mut c_void,
427    pub allocation_flags: [u8; 32], // rdma + compression + reserved
428}
429
430impl Default for cudaMemAllocationProp {
431    fn default() -> Self {
432        Self {
433            alloc_type: 0,
434            requested_handle_types: 0,
435            location: super::types::cudaMemLocation { type_: 0, id: 0 },
436            win32_handle_meta_data: core::ptr::null_mut(),
437            allocation_flags: [0; 32],
438        }
439    }
440}
441
442/// Opaque CUDA library handle (CUDA 12.0+).
443pub type cudaLibrary_t = *mut c_void;
444
445/// Opaque CUDA kernel handle (CUDA 12.0+).
446pub type cudaKernel_t = *mut c_void;
447
448/// Opaque user-object handle (CUDA 12.0+).
449pub type cudaUserObject_t = *mut c_void;
450
451/// `cudaDeviceScheduleFlags` — bits for `cudaSetDeviceFlags`.
452#[allow(non_snake_case)]
453pub mod cudaDeviceScheduleFlags {
454    pub const AUTO: u32 = 0x00;
455    pub const SPIN: u32 = 0x01;
456    pub const YIELD: u32 = 0x02;
457    pub const BLOCKING_SYNC: u32 = 0x04;
458    pub const MAP_HOST: u32 = 0x08;
459    pub const LMEM_RESIZE_TO_MAX: u32 = 0x10;
460}
461
462/// External memory object (imported Vulkan / D3D12 / NVIDIA Buffer).
463/// Typedef-compatible with [`crate::CUexternalMemory`] — pointer-level
464/// swaps between Driver and Runtime wrappers are zero-cost.
465pub type cudaExternalMemory_t = *mut c_void;
466
467/// External semaphore object.
468/// Typedef-compatible with [`crate::CUexternalSemaphore`].
469pub type cudaExternalSemaphore_t = *mut c_void;
470
471/// Direction-of-copy selector for `cudaMemcpy`.
472#[repr(i32)]
473#[derive(Copy, Clone, Debug, Eq, PartialEq)]
474pub enum cudaMemcpyKind {
475    HostToHost = 0,
476    HostToDevice = 1,
477    DeviceToHost = 2,
478    DeviceToDevice = 3,
479    /// Let the runtime infer direction from the pointer attributes (UVA).
480    Default = 4,
481}
482
483/// Three-dimensional `dim3` used for grid/block sizes.
484#[repr(C)]
485#[derive(Copy, Clone, Debug, Eq, PartialEq)]
486pub struct dim3 {
487    pub x: core::ffi::c_uint,
488    pub y: core::ffi::c_uint,
489    pub z: core::ffi::c_uint,
490}
491
492impl dim3 {
493    #[inline]
494    pub const fn new(x: core::ffi::c_uint, y: core::ffi::c_uint, z: core::ffi::c_uint) -> Self {
495        Self { x, y, z }
496    }
497}
498
499impl Default for dim3 {
500    fn default() -> Self {
501        Self { x: 1, y: 1, z: 1 }
502    }
503}
504
505/// Stream creation flags.
506#[allow(non_snake_case)]
507pub mod cudaStreamFlags {
508    pub const DEFAULT: u32 = 0x0;
509    pub const NON_BLOCKING: u32 = 0x1;
510}
511
512/// Event creation flags.
513#[allow(non_snake_case)]
514pub mod cudaEventFlags {
515    pub const DEFAULT: u32 = 0x0;
516    pub const BLOCKING_SYNC: u32 = 0x1;
517    pub const DISABLE_TIMING: u32 = 0x2;
518    pub const INTERPROCESS: u32 = 0x4;
519}
520
521/// `cudaMemoryAdvise` — values accepted by `cudaMemAdvise`.
522#[allow(non_snake_case)]
523pub mod cudaMemoryAdvise {
524    pub const SET_READ_MOSTLY: i32 = 1;
525    pub const UNSET_READ_MOSTLY: i32 = 2;
526    pub const SET_PREFERRED_LOCATION: i32 = 3;
527    pub const UNSET_PREFERRED_LOCATION: i32 = 4;
528    pub const SET_ACCESSED_BY: i32 = 5;
529    pub const UNSET_ACCESSED_BY: i32 = 6;
530}
531
532/// `cudaMemAttach*` — flags for `cudaMallocManaged` / `cudaStreamAttachMemAsync`.
533#[allow(non_snake_case)]
534pub mod cudaMemAttach {
535    pub const GLOBAL: u32 = 0x01;
536    pub const HOST: u32 = 0x02;
537    pub const SINGLE: u32 = 0x04;
538}
539
540/// `cudaHostAllocFlags` — flags for `cudaHostAlloc`.
541#[allow(non_snake_case)]
542pub mod cudaHostAllocFlags {
543    pub const DEFAULT: u32 = 0x00;
544    pub const PORTABLE: u32 = 0x01;
545    pub const MAPPED: u32 = 0x02;
546    pub const WRITE_COMBINED: u32 = 0x04;
547}
548
549/// `cudaStreamCaptureMode` — argument to `cudaStreamBeginCapture`.
550#[allow(non_snake_case)]
551pub mod cudaStreamCaptureMode {
552    pub const GLOBAL: i32 = 0;
553    pub const THREAD_LOCAL: i32 = 1;
554    pub const RELAXED: i32 = 2;
555}
556
557/// `cudaStreamCaptureStatus` — returned by `cudaStreamIsCapturing`.
558#[allow(non_snake_case)]
559pub mod cudaStreamCaptureStatus {
560    pub const NONE: i32 = 0;
561    pub const ACTIVE: i32 = 1;
562    pub const INVALIDATED: i32 = 2;
563}
564
565/// Host-function trampoline type (parallel to `CUhostFn`).
566pub type cudaHostFn_t = Option<unsafe extern "C" fn(user_data: *mut c_void)>;
567
568// ---- Memory-pool types ---------------------------------------------------
569
570/// `cudaMemAllocationType` — same values as the Driver side.
571#[allow(non_snake_case)]
572pub mod cudaMemAllocationType {
573    pub const INVALID: i32 = 0;
574    pub const PINNED: i32 = 1;
575}
576
577/// `cudaMemLocationType` — same values as the Driver side.
578#[allow(non_snake_case)]
579pub mod cudaMemLocationType {
580    pub const INVALID: i32 = 0;
581    pub const DEVICE: i32 = 1;
582    pub const HOST: i32 = 2;
583    pub const HOST_NUMA: i32 = 3;
584    pub const HOST_NUMA_CURRENT: i32 = 4;
585}
586
587/// `cudaMemAccessFlags`.
588#[allow(non_snake_case)]
589pub mod cudaMemAccessFlags {
590    pub const NONE: i32 = 0;
591    pub const READ: i32 = 1;
592    pub const READ_WRITE: i32 = 3;
593}
594
595/// `cudaMemAllocationHandleType` — IPC export type.
596#[allow(non_snake_case)]
597pub mod cudaMemAllocationHandleType {
598    pub const NONE: i32 = 0;
599    pub const POSIX_FILE_DESCRIPTOR: i32 = 1;
600    pub const WIN32: i32 = 2;
601    pub const WIN32_KMT: i32 = 4;
602    pub const FABRIC: i32 = 8;
603}
604
605/// `cudaMemPoolAttr` — selector for `cudaMemPoolSetAttribute` / `GetAttribute`.
606#[allow(non_snake_case)]
607pub mod cudaMemPoolAttr {
608    pub const REUSE_FOLLOW_EVENT_DEPENDENCIES: i32 = 1;
609    pub const REUSE_ALLOW_OPPORTUNISTIC: i32 = 2;
610    pub const REUSE_ALLOW_INTERNAL_DEPENDENCIES: i32 = 3;
611    pub const RELEASE_THRESHOLD: i32 = 4;
612    pub const RESERVED_MEM_CURRENT: i32 = 5;
613    pub const RESERVED_MEM_HIGH: i32 = 6;
614    pub const USED_MEM_CURRENT: i32 = 7;
615    pub const USED_MEM_HIGH: i32 = 8;
616}
617
618#[repr(C)]
619#[derive(Copy, Clone, Debug, Default)]
620#[allow(non_camel_case_types)]
621pub struct cudaMemLocation {
622    pub type_: core::ffi::c_int,
623    pub id: core::ffi::c_int,
624}
625
626#[repr(C)]
627#[derive(Copy, Clone, Debug, Default)]
628#[allow(non_camel_case_types)]
629pub struct cudaMemAccessDesc {
630    pub location: cudaMemLocation,
631    pub flags: core::ffi::c_int,
632}
633
634/// `cudaMemPoolProps` — 88 bytes in C. Matches the Driver-side
635/// `CUmemPoolProps` layout byte-for-byte.
636#[repr(C)]
637#[derive(Copy, Clone, Debug)]
638#[allow(non_camel_case_types)]
639pub struct cudaMemPoolProps {
640    pub alloc_type: core::ffi::c_int,
641    pub handle_types: core::ffi::c_int,
642    pub location: cudaMemLocation,
643    pub win32_security_attributes: *mut c_void,
644    pub max_size: usize,
645    pub usage: core::ffi::c_ushort,
646    pub reserved: [core::ffi::c_uchar; 54],
647}
648
649impl Default for cudaMemPoolProps {
650    fn default() -> Self {
651        Self {
652            alloc_type: cudaMemAllocationType::PINNED,
653            handle_types: cudaMemAllocationHandleType::NONE,
654            location: cudaMemLocation::default(),
655            win32_security_attributes: core::ptr::null_mut(),
656            max_size: 0,
657            usage: 0,
658            reserved: [0u8; 54],
659        }
660    }
661}
662
663/// `cudaMemPoolPtrExportData` — 64-byte opaque blob.
664#[repr(C)]
665#[derive(Copy, Clone, Debug)]
666#[allow(non_camel_case_types)]
667pub struct cudaMemPoolPtrExportData {
668    pub reserved: [core::ffi::c_uchar; 64],
669}
670
671impl Default for cudaMemPoolPtrExportData {
672    fn default() -> Self {
673        Self {
674            reserved: [0u8; 64],
675        }
676    }
677}
678
679// ---- Kernel launch parameters for graph nodes ----------------------------
680
681/// `cudaKernelNodeParams` — parameters for `cudaGraphAddKernelNode`.
682#[repr(C)]
683#[derive(Copy, Clone, Debug)]
684#[allow(non_camel_case_types)]
685pub struct cudaKernelNodeParams {
686    pub func: *mut c_void,
687    pub grid_dim: dim3,
688    pub block_dim: dim3,
689    pub shared_mem_bytes: core::ffi::c_uint,
690    pub kernel_params: *mut *mut c_void,
691    pub extra: *mut *mut c_void,
692}
693
694impl Default for cudaKernelNodeParams {
695    fn default() -> Self {
696        Self {
697            func: core::ptr::null_mut(),
698            grid_dim: dim3::default(),
699            block_dim: dim3::default(),
700            shared_mem_bytes: 0,
701            kernel_params: core::ptr::null_mut(),
702            extra: core::ptr::null_mut(),
703        }
704    }
705}
706
707/// `cudaMemsetParams` — parameters for `cudaGraphAddMemsetNode`.
708#[repr(C)]
709#[derive(Copy, Clone, Debug, Default)]
710#[allow(non_camel_case_types)]
711pub struct cudaMemsetParams {
712    pub dst: *mut c_void,
713    pub pitch: usize,
714    pub value: core::ffi::c_uint,
715    pub element_size: core::ffi::c_uint,
716    pub width: usize,
717    pub height: usize,
718}
719
720/// `cudaHostNodeParams` — `{ fn, user_data }` for `cudaGraphAddHostNode`.
721#[repr(C)]
722#[derive(Copy, Clone, Debug)]
723#[allow(non_camel_case_types)]
724pub struct cudaHostNodeParams {
725    pub fn_: cudaHostFn_t,
726    pub user_data: *mut c_void,
727}
728
729impl Default for cudaHostNodeParams {
730    fn default() -> Self {
731        Self {
732            fn_: None,
733            user_data: core::ptr::null_mut(),
734        }
735    }
736}
737
738/// `cudaMemAllocNodeParams` — parameters for `cudaGraphAddMemAllocNode`.
739#[repr(C)]
740#[derive(Copy, Clone, Debug)]
741#[allow(non_camel_case_types)]
742pub struct cudaMemAllocNodeParams {
743    pub pool_props: cudaMemPoolProps,
744    pub access_descs: *const cudaMemAccessDesc,
745    pub access_desc_count: usize,
746    pub bytesize: usize,
747    pub dptr: *mut c_void,
748}
749
750impl Default for cudaMemAllocNodeParams {
751    fn default() -> Self {
752        Self {
753            pool_props: cudaMemPoolProps::default(),
754            access_descs: core::ptr::null(),
755            access_desc_count: 0,
756            bytesize: 0,
757            dptr: core::ptr::null_mut(),
758        }
759    }
760}
761
762/// `cudaGraphExecUpdateResult` — outcome of `cudaGraphExecUpdate`.
763#[allow(non_snake_case)]
764pub mod cudaGraphExecUpdateResult {
765    pub const SUCCESS: i32 = 0;
766    pub const ERROR: i32 = 1;
767    pub const ERROR_TOPOLOGY_CHANGED: i32 = 2;
768    pub const ERROR_NODE_TYPE_CHANGED: i32 = 3;
769    pub const ERROR_FUNCTION_CHANGED: i32 = 4;
770    pub const ERROR_PARAMETERS_CHANGED: i32 = 5;
771    pub const ERROR_NOT_SUPPORTED: i32 = 6;
772    pub const ERROR_UNSUPPORTED_FUNCTION_CHANGE: i32 = 7;
773    pub const ERROR_ATTRIBUTES_CHANGED: i32 = 8;
774}
775
776// ---- Pointer / function attributes ---------------------------------------
777
778/// `cudaPointerAttributes` — returned by `cudaPointerGetAttributes`.
779///
780/// The C struct is 48 bytes. We model the fields directly.
781#[repr(C)]
782#[derive(Copy, Clone, Debug)]
783#[allow(non_camel_case_types)]
784pub struct cudaPointerAttributes {
785    /// `cudaMemoryType` — 0=unregistered, 1=host, 2=device, 3=managed.
786    pub type_: core::ffi::c_int,
787    /// Device ordinal the allocation lives on.
788    pub device: core::ffi::c_int,
789    /// Device-addressable pointer (null for plain host memory).
790    pub device_pointer: *mut c_void,
791    /// Host-addressable pointer (null for plain device memory).
792    pub host_pointer: *mut c_void,
793}
794
795impl Default for cudaPointerAttributes {
796    fn default() -> Self {
797        Self {
798            type_: 0,
799            device: 0,
800            device_pointer: core::ptr::null_mut(),
801            host_pointer: core::ptr::null_mut(),
802        }
803    }
804}
805
806/// `cudaMemoryType` — `cudaPointerAttributes::type_` values.
807#[allow(non_snake_case)]
808pub mod cudaMemoryType {
809    pub const UNREGISTERED: i32 = 0;
810    pub const HOST: i32 = 1;
811    pub const DEVICE: i32 = 2;
812    pub const MANAGED: i32 = 3;
813}
814
815/// `cudaFuncAttributes` — kernel metadata (36 bytes in C).
816#[repr(C)]
817#[derive(Copy, Clone, Debug, Default)]
818#[allow(non_camel_case_types)]
819pub struct cudaFuncAttributes {
820    pub shared_size_bytes: usize,
821    pub const_size_bytes: usize,
822    pub local_size_bytes: usize,
823    pub max_threads_per_block: core::ffi::c_int,
824    pub num_regs: core::ffi::c_int,
825    pub ptx_version: core::ffi::c_int,
826    pub binary_version: core::ffi::c_int,
827    pub cache_mode_ca: core::ffi::c_int,
828    pub max_dynamic_shared_size_bytes: core::ffi::c_int,
829    pub preferred_shmem_carveout: core::ffi::c_int,
830    pub cluster_dim_must_be_set: core::ffi::c_int,
831    pub required_cluster_width: core::ffi::c_int,
832    pub required_cluster_height: core::ffi::c_int,
833    pub required_cluster_depth: core::ffi::c_int,
834    pub cluster_scheduling_policy_preference: core::ffi::c_int,
835    pub non_portable_cluster_size_allowed: core::ffi::c_int,
836    pub reserved: [core::ffi::c_int; 16],
837}
838
839/// `cudaStreamWriteValueFlags`.
840#[allow(non_snake_case)]
841pub mod cudaStreamWriteValueFlags {
842    pub const DEFAULT: u32 = 0x0;
843    pub const NO_MEMORY_BARRIER: u32 = 0x1;
844}
845
846/// `cudaStreamWaitValueFlags`.
847#[allow(non_snake_case)]
848pub mod cudaStreamWaitValueFlags {
849    pub const GEQ: u32 = 0x0;
850    pub const EQ: u32 = 0x1;
851    pub const AND: u32 = 0x2;
852    pub const NOR: u32 = 0x3;
853    pub const FLUSH: u32 = 1 << 30;
854}
855
856/// Device-attribute selector (matches `cudaDeviceAttr` values).
857#[allow(non_snake_case)]
858pub mod cudaDeviceAttr {
859    pub const MAX_THREADS_PER_BLOCK: i32 = 1;
860    pub const MAX_BLOCK_DIM_X: i32 = 2;
861    pub const MAX_BLOCK_DIM_Y: i32 = 3;
862    pub const MAX_BLOCK_DIM_Z: i32 = 4;
863    pub const MAX_GRID_DIM_X: i32 = 5;
864    pub const MAX_GRID_DIM_Y: i32 = 6;
865    pub const MAX_GRID_DIM_Z: i32 = 7;
866    pub const MAX_SHARED_MEMORY_PER_BLOCK: i32 = 8;
867    pub const TOTAL_CONSTANT_MEMORY: i32 = 9;
868    pub const WARP_SIZE: i32 = 10;
869    pub const MAX_PITCH: i32 = 11;
870    pub const MAX_REGISTERS_PER_BLOCK: i32 = 12;
871    pub const CLOCK_RATE: i32 = 13;
872    pub const MULTIPROCESSOR_COUNT: i32 = 16;
873    pub const COMPUTE_CAPABILITY_MAJOR: i32 = 75;
874    pub const COMPUTE_CAPABILITY_MINOR: i32 = 76;
875    pub const CONCURRENT_KERNELS: i32 = 31;
876    pub const ECC_ENABLED: i32 = 32;
877    pub const PCI_BUS_ID: i32 = 33;
878    pub const PCI_DEVICE_ID: i32 = 34;
879    pub const PCI_DOMAIN_ID: i32 = 50;
880    pub const INTEGRATED: i32 = 18;
881}