paddle_inference/
lib.rs

1#![doc = include_str!("../README.md")]
2#[cfg(feature = "serde")]
3#[cfg_attr(feature = "serde", macro_use)]
4extern crate serde;
5
6pub mod common;
7pub mod config;
8pub mod ctypes;
9mod predictor;
10mod tensor;
11pub mod utils;
12
13use libloading::{library_filename, Library};
14use once_cell::sync::Lazy;
15pub use predictor::Predictor;
16pub use tensor::Tensor;
17
18static LIBRARY: Lazy<Library> = Lazy::new(|| unsafe {
19    Library::new(library_filename("paddle_inference_c")).expect("can't not load paddle_inference_c")
20});
21
22/// 用于快速调用实现了[`ctypes::Function`]的对象
23///
24/// **使用方法:**
25///
26/// ``` no_run
27/// use paddle_inference::call;
28/// use paddle_inference::ctypes::{Function, PD_ConfigCreate, PD_ConfigDestroy};
29///
30/// let ptr = call!(PD_ConfigCreate());
31/// call!(PD_ConfigDestroy(ptr));
32///
33/// /// 等同于
34/// let ptr = unsafe { PD_ConfigCreate::get()() };
35/// unsafe { PD_ConfigDestroy::get()(ptr) };
36/// ```
37#[macro_export]
38macro_rules! call {
39    ($name: ident ( $( $args: expr ),* )) => {
40        unsafe {
41            <$name as $crate::ctypes::Function>::get()( $($args),* )
42        }
43    };
44}