use std::ffi::c_void;
use std::ptr::NonNull;
use bitflags::bitflags;
use super::tensor::Tensor;
pub const DLPACK_MAJOR_VERSION: u32 = 1;
pub const DLPACK_MINOR_VERSION: u32 = 1;
#[repr(C)]
#[derive(Debug)]
pub struct PackVersion {
pub major: u32,
pub minor: u32,
}
impl Default for PackVersion {
fn default() -> Self {
Self {
major: DLPACK_MAJOR_VERSION,
minor: DLPACK_MINOR_VERSION,
}
}
}
impl PackVersion {
pub fn new(major: u32, minor: u32) -> Self {
PackVersion { major, minor }
}
}
bitflags! {
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Flags: u64 {
const READ_ONLY = 1 << 0;
const IS_COPIED = 1 << 1;
const IS_SUBBYTE_TYPE_PADDED = 1 << 2;
}
}
impl Default for Flags {
fn default() -> Self {
Flags::READ_ONLY
}
}
#[repr(C)]
#[derive(Debug)]
pub struct ManagedTensorVersioned {
pub version: PackVersion,
pub manager_ctx: *mut c_void,
pub deleter: Option<unsafe extern "C" fn(*mut Self)>,
pub flags: Flags,
pub dl_tensor: Tensor,
}
impl Default for ManagedTensorVersioned {
fn default() -> Self {
Self {
version: PackVersion::default(),
manager_ctx: std::ptr::null_mut(),
deleter: None,
flags: Flags::default(),
dl_tensor: Tensor::default(),
}
}
}
pub type DlpackVersioned = NonNull<ManagedTensorVersioned>;