hrx-rs 0.10.1

Owned native AMD GPU and NPU execution with Loom compilation
Documentation
/* automatically generated by rust-bindgen 0.73.2 */

#[repr(C)]
#[derive(Debug)]
pub struct hrx_fabric_gpu_image {
    _unused: [u8; 0],
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct hrx_fabric_gpu_info {
    pub storage_bytes: u64,
    pub descriptor_offset: u64,
    pub kernarg_bytes: u32,
    pub private_bytes: u32,
    pub wave_size: u32,
    pub local_bytes: u32,
    pub argument_count: u32,
    pub workgroup_size: [u32; 3usize],
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of hrx_fabric_gpu_info"][::std::mem::size_of::<hrx_fabric_gpu_info>() - 48usize];
    ["Alignment of hrx_fabric_gpu_info"][::std::mem::align_of::<hrx_fabric_gpu_info>() - 8usize];
    ["Offset of field: hrx_fabric_gpu_info::storage_bytes"]
        [::std::mem::offset_of!(hrx_fabric_gpu_info, storage_bytes) - 0usize];
    ["Offset of field: hrx_fabric_gpu_info::descriptor_offset"]
        [::std::mem::offset_of!(hrx_fabric_gpu_info, descriptor_offset) - 8usize];
    ["Offset of field: hrx_fabric_gpu_info::kernarg_bytes"]
        [::std::mem::offset_of!(hrx_fabric_gpu_info, kernarg_bytes) - 16usize];
    ["Offset of field: hrx_fabric_gpu_info::private_bytes"]
        [::std::mem::offset_of!(hrx_fabric_gpu_info, private_bytes) - 20usize];
    ["Offset of field: hrx_fabric_gpu_info::wave_size"]
        [::std::mem::offset_of!(hrx_fabric_gpu_info, wave_size) - 24usize];
    ["Offset of field: hrx_fabric_gpu_info::local_bytes"]
        [::std::mem::offset_of!(hrx_fabric_gpu_info, local_bytes) - 28usize];
    ["Offset of field: hrx_fabric_gpu_info::argument_count"]
        [::std::mem::offset_of!(hrx_fabric_gpu_info, argument_count) - 32usize];
    ["Offset of field: hrx_fabric_gpu_info::workgroup_size"]
        [::std::mem::offset_of!(hrx_fabric_gpu_info, workgroup_size) - 36usize];
};
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct hrx_fabric_gpu_argument {
    pub kind: u32,
    pub offset: u32,
    pub size: u32,
    pub reserved: u32,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of hrx_fabric_gpu_argument"][::std::mem::size_of::<hrx_fabric_gpu_argument>() - 16usize];
    ["Alignment of hrx_fabric_gpu_argument"]
        [::std::mem::align_of::<hrx_fabric_gpu_argument>() - 4usize];
    ["Offset of field: hrx_fabric_gpu_argument::kind"]
        [::std::mem::offset_of!(hrx_fabric_gpu_argument, kind) - 0usize];
    ["Offset of field: hrx_fabric_gpu_argument::offset"]
        [::std::mem::offset_of!(hrx_fabric_gpu_argument, offset) - 4usize];
    ["Offset of field: hrx_fabric_gpu_argument::size"]
        [::std::mem::offset_of!(hrx_fabric_gpu_argument, size) - 8usize];
    ["Offset of field: hrx_fabric_gpu_argument::reserved"]
        [::std::mem::offset_of!(hrx_fabric_gpu_argument, reserved) - 12usize];
};
#[repr(C)]
#[derive(Debug)]
pub struct hrx_fabric_xdna_program {
    _unused: [u8; 0],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct hrx_fabric_xdna_binding {
    pub memory: *mut ::std::os::raw::c_void,
    pub host_pointer: *mut ::std::os::raw::c_void,
    pub allocation_length: u64,
    pub offset: u64,
    pub length: u64,
    pub address: u64,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of hrx_fabric_xdna_binding"][::std::mem::size_of::<hrx_fabric_xdna_binding>() - 48usize];
    ["Alignment of hrx_fabric_xdna_binding"]
        [::std::mem::align_of::<hrx_fabric_xdna_binding>() - 8usize];
    ["Offset of field: hrx_fabric_xdna_binding::memory"]
        [::std::mem::offset_of!(hrx_fabric_xdna_binding, memory) - 0usize];
    ["Offset of field: hrx_fabric_xdna_binding::host_pointer"]
        [::std::mem::offset_of!(hrx_fabric_xdna_binding, host_pointer) - 8usize];
    ["Offset of field: hrx_fabric_xdna_binding::allocation_length"]
        [::std::mem::offset_of!(hrx_fabric_xdna_binding, allocation_length) - 16usize];
    ["Offset of field: hrx_fabric_xdna_binding::offset"]
        [::std::mem::offset_of!(hrx_fabric_xdna_binding, offset) - 24usize];
    ["Offset of field: hrx_fabric_xdna_binding::length"]
        [::std::mem::offset_of!(hrx_fabric_xdna_binding, length) - 32usize];
    ["Offset of field: hrx_fabric_xdna_binding::address"]
        [::std::mem::offset_of!(hrx_fabric_xdna_binding, address) - 40usize];
};
impl Default for hrx_fabric_xdna_binding {
    fn default() -> Self {
        let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
        unsafe {
            ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
            s.assume_init()
        }
    }
}
pub struct Bridge {
    __library: ::libloading::Library,
    pub hrx_fabric_error: unsafe extern "C" fn() -> *const ::std::os::raw::c_char,
    pub hrx_fabric_gpu_image_open: unsafe extern "C" fn(
        data: *const u8,
        size: usize,
        symbol: *const ::std::os::raw::c_char,
        out: *mut *mut hrx_fabric_gpu_image,
        info: *mut hrx_fabric_gpu_info,
    ) -> ::std::os::raw::c_int,
    pub hrx_fabric_gpu_image_close: unsafe extern "C" fn(image: *mut hrx_fabric_gpu_image),
    pub hrx_fabric_gpu_argument_info: unsafe extern "C" fn(
        image: *const hrx_fabric_gpu_image,
        index: u32,
        out: *mut hrx_fabric_gpu_argument,
    ) -> ::std::os::raw::c_int,
    pub hrx_fabric_gpu_global_info: unsafe extern "C" fn(
        image: *const hrx_fabric_gpu_image,
        name: *const ::std::os::raw::c_char,
        offset: *mut u64,
        length: *mut u64,
    ) -> ::std::os::raw::c_int,
    pub hrx_fabric_gpu_image_load: unsafe extern "C" fn(
        image: *const hrx_fabric_gpu_image,
        storage: *mut u8,
        size: usize,
        address: u64,
    ) -> ::std::os::raw::c_int,
    pub hrx_fabric_gpu_dispatch: unsafe extern "C" fn(
        image: *const hrx_fabric_gpu_image,
        image_address: u64,
        block: *const u16,
        grid: *const u32,
        kernarg_address: u64,
        kernarg: *const u8,
        kernarg_size: usize,
        scratch_address: u64,
        scratch_length: u64,
        scratch_waves: u32,
        shader_engines: u32,
        words: *mut u32,
        capacity: u32,
        count: *mut u32,
    ) -> ::std::os::raw::c_int,
    pub hrx_fabric_xdna_open: unsafe extern "C" fn(
        api: *const ::std::os::raw::c_void,
        xdna_api: *const ::std::os::raw::c_void,
        instance: *mut ::std::os::raw::c_void,
        endpoint: *mut ::std::os::raw::c_void,
        device: *mut ::std::os::raw::c_void,
        bytes: *const u8,
        length: usize,
        symbol: *const ::std::os::raw::c_char,
        columns: u16,
        binding_count: u32,
        bindings: *const hrx_fabric_xdna_binding,
        out: *mut *mut hrx_fabric_xdna_program,
    ) -> ::std::os::raw::c_int,
    pub hrx_fabric_xdna_close:
        unsafe extern "C" fn(program: *mut hrx_fabric_xdna_program) -> ::std::os::raw::c_int,
    pub hrx_fabric_xdna_command_copy: unsafe extern "C" fn(
        program: *mut hrx_fabric_xdna_program,
        bytes: *mut u8,
        capacity: usize,
        length: *mut usize,
    ) -> ::std::os::raw::c_int,
    pub hrx_fabric_xdna_command_replace: unsafe extern "C" fn(
        program: *mut hrx_fabric_xdna_program,
        bytes: *const u8,
        length: usize,
    ) -> ::std::os::raw::c_int,
    pub hrx_fabric_xdna_submit:
        unsafe extern "C" fn(program: *mut hrx_fabric_xdna_program, submission: *mut u64) -> u64,
    pub hrx_fabric_xdna_wait: unsafe extern "C" fn(
        program: *mut hrx_fabric_xdna_program,
        submission: u64,
        timeout_ns: u64,
    ) -> u64,
}
impl Bridge {
    pub unsafe fn new<P>(path: P) -> Result<Self, ::libloading::Error>
    where
        P: AsRef<::std::ffi::OsStr>,
    {
        let path = path.as_ref();
        let library = ::libloading::Library::new(path)?;
        Self::from_library(library)
    }
    pub unsafe fn from_library<L>(library: L) -> Result<Self, ::libloading::Error>
    where
        L: Into<::libloading::Library>,
    {
        let __library = library.into();
        let hrx_fabric_error = __library.get(b"hrx_fabric_error\0").map(|sym| *sym)?;
        let hrx_fabric_gpu_image_open = __library
            .get(b"hrx_fabric_gpu_image_open\0")
            .map(|sym| *sym)?;
        let hrx_fabric_gpu_image_close = __library
            .get(b"hrx_fabric_gpu_image_close\0")
            .map(|sym| *sym)?;
        let hrx_fabric_gpu_argument_info = __library
            .get(b"hrx_fabric_gpu_argument_info\0")
            .map(|sym| *sym)?;
        let hrx_fabric_gpu_global_info = __library
            .get(b"hrx_fabric_gpu_global_info\0")
            .map(|sym| *sym)?;
        let hrx_fabric_gpu_image_load = __library
            .get(b"hrx_fabric_gpu_image_load\0")
            .map(|sym| *sym)?;
        let hrx_fabric_gpu_dispatch = __library
            .get(b"hrx_fabric_gpu_dispatch\0")
            .map(|sym| *sym)?;
        let hrx_fabric_xdna_open = __library.get(b"hrx_fabric_xdna_open\0").map(|sym| *sym)?;
        let hrx_fabric_xdna_close = __library.get(b"hrx_fabric_xdna_close\0").map(|sym| *sym)?;
        let hrx_fabric_xdna_command_copy = __library
            .get(b"hrx_fabric_xdna_command_copy\0")
            .map(|sym| *sym)?;
        let hrx_fabric_xdna_command_replace = __library
            .get(b"hrx_fabric_xdna_command_replace\0")
            .map(|sym| *sym)?;
        let hrx_fabric_xdna_submit = __library.get(b"hrx_fabric_xdna_submit\0").map(|sym| *sym)?;
        let hrx_fabric_xdna_wait = __library.get(b"hrx_fabric_xdna_wait\0").map(|sym| *sym)?;
        Ok(Bridge {
            __library,
            hrx_fabric_error,
            hrx_fabric_gpu_image_open,
            hrx_fabric_gpu_image_close,
            hrx_fabric_gpu_argument_info,
            hrx_fabric_gpu_global_info,
            hrx_fabric_gpu_image_load,
            hrx_fabric_gpu_dispatch,
            hrx_fabric_xdna_open,
            hrx_fabric_xdna_close,
            hrx_fabric_xdna_command_copy,
            hrx_fabric_xdna_command_replace,
            hrx_fabric_xdna_submit,
            hrx_fabric_xdna_wait,
        })
    }
    pub unsafe fn hrx_fabric_error(&self) -> *const ::std::os::raw::c_char {
        (self.hrx_fabric_error)()
    }
    pub unsafe fn hrx_fabric_gpu_image_open(
        &self,
        data: *const u8,
        size: usize,
        symbol: *const ::std::os::raw::c_char,
        out: *mut *mut hrx_fabric_gpu_image,
        info: *mut hrx_fabric_gpu_info,
    ) -> ::std::os::raw::c_int {
        (self.hrx_fabric_gpu_image_open)(data, size, symbol, out, info)
    }
    pub unsafe fn hrx_fabric_gpu_image_close(&self, image: *mut hrx_fabric_gpu_image) {
        (self.hrx_fabric_gpu_image_close)(image)
    }
    pub unsafe fn hrx_fabric_gpu_argument_info(
        &self,
        image: *const hrx_fabric_gpu_image,
        index: u32,
        out: *mut hrx_fabric_gpu_argument,
    ) -> ::std::os::raw::c_int {
        (self.hrx_fabric_gpu_argument_info)(image, index, out)
    }
    pub unsafe fn hrx_fabric_gpu_global_info(
        &self,
        image: *const hrx_fabric_gpu_image,
        name: *const ::std::os::raw::c_char,
        offset: *mut u64,
        length: *mut u64,
    ) -> ::std::os::raw::c_int {
        (self.hrx_fabric_gpu_global_info)(image, name, offset, length)
    }
    pub unsafe fn hrx_fabric_gpu_image_load(
        &self,
        image: *const hrx_fabric_gpu_image,
        storage: *mut u8,
        size: usize,
        address: u64,
    ) -> ::std::os::raw::c_int {
        (self.hrx_fabric_gpu_image_load)(image, storage, size, address)
    }
    pub unsafe fn hrx_fabric_gpu_dispatch(
        &self,
        image: *const hrx_fabric_gpu_image,
        image_address: u64,
        block: *const u16,
        grid: *const u32,
        kernarg_address: u64,
        kernarg: *const u8,
        kernarg_size: usize,
        scratch_address: u64,
        scratch_length: u64,
        scratch_waves: u32,
        shader_engines: u32,
        words: *mut u32,
        capacity: u32,
        count: *mut u32,
    ) -> ::std::os::raw::c_int {
        (self.hrx_fabric_gpu_dispatch)(
            image,
            image_address,
            block,
            grid,
            kernarg_address,
            kernarg,
            kernarg_size,
            scratch_address,
            scratch_length,
            scratch_waves,
            shader_engines,
            words,
            capacity,
            count,
        )
    }
    pub unsafe fn hrx_fabric_xdna_open(
        &self,
        api: *const ::std::os::raw::c_void,
        xdna_api: *const ::std::os::raw::c_void,
        instance: *mut ::std::os::raw::c_void,
        endpoint: *mut ::std::os::raw::c_void,
        device: *mut ::std::os::raw::c_void,
        bytes: *const u8,
        length: usize,
        symbol: *const ::std::os::raw::c_char,
        columns: u16,
        binding_count: u32,
        bindings: *const hrx_fabric_xdna_binding,
        out: *mut *mut hrx_fabric_xdna_program,
    ) -> ::std::os::raw::c_int {
        (self.hrx_fabric_xdna_open)(
            api,
            xdna_api,
            instance,
            endpoint,
            device,
            bytes,
            length,
            symbol,
            columns,
            binding_count,
            bindings,
            out,
        )
    }
    pub unsafe fn hrx_fabric_xdna_close(
        &self,
        program: *mut hrx_fabric_xdna_program,
    ) -> ::std::os::raw::c_int {
        (self.hrx_fabric_xdna_close)(program)
    }
    pub unsafe fn hrx_fabric_xdna_command_copy(
        &self,
        program: *mut hrx_fabric_xdna_program,
        bytes: *mut u8,
        capacity: usize,
        length: *mut usize,
    ) -> ::std::os::raw::c_int {
        (self.hrx_fabric_xdna_command_copy)(program, bytes, capacity, length)
    }
    pub unsafe fn hrx_fabric_xdna_command_replace(
        &self,
        program: *mut hrx_fabric_xdna_program,
        bytes: *const u8,
        length: usize,
    ) -> ::std::os::raw::c_int {
        (self.hrx_fabric_xdna_command_replace)(program, bytes, length)
    }
    pub unsafe fn hrx_fabric_xdna_submit(
        &self,
        program: *mut hrx_fabric_xdna_program,
        submission: *mut u64,
    ) -> u64 {
        (self.hrx_fabric_xdna_submit)(program, submission)
    }
    pub unsafe fn hrx_fabric_xdna_wait(
        &self,
        program: *mut hrx_fabric_xdna_program,
        submission: u64,
        timeout_ns: u64,
    ) -> u64 {
        (self.hrx_fabric_xdna_wait)(program, submission, timeout_ns)
    }
}