nixl_sys/
descriptors.rs

1// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use super::*;
17
18mod query;
19mod reg;
20mod sync_manager;
21mod xfer;
22mod xfer_dlist_handle;
23
24pub use query::{QueryResponse, QueryResponseIterator, QueryResponseList};
25pub use reg::{RegDescList, RegDescriptor};
26pub use sync_manager::{BackendSyncable, SyncManager};
27pub use xfer::{XferDescList, XferDescriptor};
28pub use xfer_dlist_handle::XferDlistHandle;
29
30/// Memory types supported by NIXL
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
32pub enum MemType {
33    Dram,
34    Vram,
35    Block,
36    Object,
37    File,
38    Unknown,
39}
40
41impl From<nixl_capi_mem_type_t> for MemType {
42    fn from(mem_type: nixl_capi_mem_type_t) -> Self {
43        match mem_type {
44            0 => MemType::Dram,
45            1 => MemType::Vram,
46            2 => MemType::Block,
47            3 => MemType::Object,
48            4 => MemType::File,
49            _ => MemType::Unknown,
50        }
51    }
52}
53
54impl fmt::Display for MemType {
55    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56        // SAFETY: We know the memory type is valid and the string will be available
57        let mut str_ptr = ptr::null();
58        unsafe {
59            let mem_type = match self {
60                MemType::Dram => 0,
61                MemType::Vram => 1,
62                MemType::Block => 2,
63                MemType::Object => 3,
64                MemType::File => 4,
65                MemType::Unknown => 5,
66            };
67            nixl_capi_mem_type_to_string(mem_type, &mut str_ptr);
68            let c_str = CStr::from_ptr(str_ptr);
69            write!(f, "{}", c_str.to_str().unwrap())
70        }
71    }
72}