Skip to main content

cufile_sys/
bindings.rs

1// Pre-generated bindings for CuFile
2// These are fallback bindings when bindgen is not available
3
4use std::os::raw::{c_char, c_int, c_void};
5
6// CuFile version
7pub const CUFILE_VERSION: u32 = 1000;
8
9/// The cufile is successful.
10pub const CU_FILE_SUCCESS: i32 = 0;
11
12/// The nvidia-fs driver is not loaded.
13pub const CU_FILE_DRIVER_NOT_INITIALIZED: i32 = 5001;
14
15/// An invalid property.
16pub const CU_FILE_DRIVER_INVALID_PROPS: i32 = 5002;
17
18/// A property range error.
19pub const CU_FILE_DRIVER_UNSUPPORTED_LIMIT: i32 = 5003;
20
21/// An nvidia-fs driver version mismatch.
22pub const CU_FILE_DRIVER_VERSION_MISMATCH: i32 = 5004;
23
24/// An nvidia-fs driver version read error.
25pub const CU_FILE_DRIVER_VERSION_READ_ERROR: i32 = 5005;
26
27/// Driver shutdown in progress.
28pub const CU_FILE_DRIVER_CLOSING: i32 = 5006;
29
30/// GDS is not supported on the current platform.
31pub const CU_FILE_PLATFORM_NOT_SUPPORTED: i32 = 500;
32
33/// GDS is not supported on the current file.
34pub const CU_FILE_IO_NOT_SUPPORTED: i32 = 5008;
35
36/// GDS is not supported on the current GPU.
37pub const CU_FILE_DEVICE_NOT_SUPPORTED: i32 = 5009;
38
39/// An nvidia-fs driver ioctl error.
40pub const CU_FILE_NVFS_DRIVER_ERROR: i32 = 5010;
41
42/// A CUDA Driver API error.
43///
44/// This error indicates a CUDA driver-api error.
45/// If this is set, a CUDA-specific error code is set in the `cu_err` field for `cuFileError`.
46pub const CU_FILE_CUDA_DRIVER_ERROR: i32 = 5011;
47
48/// An invalid device pointer.
49pub const CU_FILE_CUDA_POINTER_INVALID: i32 = 5012;
50
51/// An invalid pointer memory type.
52pub const CU_FILE_CUDA_MEMORY_TYPE_INVALID: i32 = 5013;
53
54/// The pointer range exceeds the allocated address range.
55pub const CU_FILE_CUDA_POINTER_RANGE_ERROR: i32 = 5014;
56
57/// A CUDA context mismatch.
58pub const CU_FILE_CUDA_CONTEXT_MISMATCH: i32 = 5015;
59
60/// Access beyond the maximum pinned memory size.
61pub const CU_FILE_INVALID_MAPPING_SIZE: i32 = 5016;
62
63/// Access beyond the mapped size.
64pub const CU_FILE_INVALID_MAPPING_RANGE: i32 = 5017;
65
66/// An unsupported file type.
67pub const CU_FILE_INVALID_FILE_TYPE: i32 = 5018;
68
69/// Unsupported file open flags.
70pub const CU_FILE_INVALID_FILE_OPEN_FLAG: i32 = 5019;
71
72/// The fd direct IO is not set.
73pub const CU_FILE_DIO_NOT_SET: i32 = 5020;
74
75/// Invalid API arguments.
76pub const CU_FILE_INVALID_VALUE: i32 = 5022;
77
78/// Device pointer is already registered.
79pub const CU_FILE_MEMORY_ALREADY_REGISTERED: i32 = 5023;
80
81/// A device pointer lookup failure has occurred.
82pub const CU_FILE_MEMORY_NOT_REGISTERED: i32 = 5024;
83
84/// A driver or file access error.
85pub const CU_FILE_PERMISSION_DENIED: i32 = 5025;
86
87/// The driver is already open.
88pub const CU_FILE_DRIVER_ALREADY_OPEN: i32 = 5026;
89
90/// The file descriptor is not registered.
91pub const CU_FILE_HANDLE_NOT_REGISTERED: i32 = 5027;
92
93/// The file descriptor is already registered.
94pub const CU_FILE_HANDLE_ALREADY_REGISTERED: i32 = 5028;
95
96/// The GPU device cannot be not found.
97pub const CU_FILE_DEVICE_NOT_FOUND: i32 = 5029;
98
99/// An internal error has occurred. Refer to cufile.log for more details.
100pub const CU_FILE_INTERNAL_ERROR: i32 = 5030;
101
102/// Failed to obtain a new file descriptor.
103pub const CU_FILE_GETNEWFD_FAILED: i32 = 5031;
104
105/// An NVFS driver initialization error has occurred.
106pub const CU_FILE_NVFS_SETUP_ERROR: i32 = 5033;
107
108/// GDS is disabled by config on the current file.
109pub const CU_FILE_IO_DISABLED: i32 = 5034;
110
111/// Failed to submit a batch operation.
112pub const CU_FILE_BATCH_SUBMIT_FAILED: i32 = 5035;
113
114/// Failed to allocate pinned GPU memory.
115pub const CU_FILE_GPU_MEMORY_PINNING_FAILED: i32 = 5036;
116
117/// Queue full for batch operation.
118pub const CU_FILE_BATCH_FULL: i32 = 5037;
119
120/// cuFile stream operation is not supported.
121pub const CU_FILE_ASYNC_NOT_SUPPORTED: i32 = 5038;
122
123// Handle types
124pub type CUfileHandle_t = *mut c_void;
125
126#[repr(C)]
127#[derive(Debug, Copy, Clone, PartialEq, Eq)]
128pub enum CUfileFileHandleType {
129    /// linux based fd
130    CU_FILE_HANDLE_TYPE_OPAQUE_FD = 1,
131    /// windows based handle
132    CU_FILE_HANDLE_TYPE_OPAQUE_WIN32 = 2,
133    /// userspace based FS
134    CU_FILE_HANDLE_TYPE_USERSPACE_FS = 3,
135}
136
137#[repr(C)]
138pub union CUfileDescrHandle {
139    pub fd: c_int, // Linux
140    pub handle: *mut c_void, // Windows
141}
142
143#[repr(C)]
144pub struct CUfileDescr_t {
145    pub type_: CUfileFileHandleType,
146    pub handle: CUfileDescrHandle,
147    pub fs_ops: *const c_void,
148}
149
150
151// Error type
152pub type CUfileError_t = c_int;
153
154extern "C" {
155    // Driver management
156    pub fn cuFileDriverOpen() -> CUfileError_t;
157    pub fn cuFileDriverClose() -> CUfileError_t;
158
159    // Handle management
160    pub fn cuFileHandleRegister(
161        fh: *mut CUfileHandle_t,
162        descr: *mut CUfileDescr_t,
163    ) -> CUfileError_t;
164    pub fn cuFileHandleDeregister(fh: CUfileHandle_t) -> CUfileError_t;
165
166    // Buffer management
167    pub fn cuFileBufRegister(devPtr_base: *const c_void, size: usize, flags: c_int) -> CUfileError_t;
168    pub fn cuFileBufDeregister(devPtr_base: *const c_void) -> CUfileError_t;
169
170    // Synchronous I/O
171    pub fn cuFileRead(
172        fh: CUfileHandle_t,
173        bufPtr_base: *mut c_void,
174        size: usize,
175        file_offset: i64,
176        bufPtr_offset: i64,
177    ) -> isize;
178
179    pub fn cuFileWrite(
180        fh: CUfileHandle_t,
181        bufPtr_base: *const c_void,
182        size: usize,
183        file_offset: i64,
184        bufPtr_offset: i64,
185    ) -> isize;
186
187    // Error handling
188    pub fn cuFileGetErrorString(error: CUfileError_t) -> *const c_char;
189}