Crate megenginelite_rs

Crate megenginelite_rs 

Source
Expand description

megenginelite-rs provides the safe megenginelite wrapper in Rust.

See more in megenginelite.

§Examples


// The dynamic library version needs to be greater than or equal to the compiled version.
// It is needless if the feature `auto-load` is enable (default enable).
unsafe {
    load("dynamic_library_path")?;
}

// set some options, and load model
let mut network = Network::builder()
        .dev_id(0)
        .stream_id(0)
        // ...
        .build("model_path")?;

// get an input of the model by name
let mut input = network.io_tensor("input_name").unwrap();
let data = Tensor::host()?;
input.copy_from(&data);

// exec, and wait
network.exec_wait()?;
// exec, async
network.exec().await?;

// get an output of the model by name
let output = network.io_tensor("output_name").unwrap();
println!("{:?}", output.as_slice::<f32>());

§Default feature flags

The following features are turned on by default:

  • auto-load: automatically load megenginelite dynamic library from the megenginelite python package, and find that by python3 -c "import megenginelite;print(megenginelite.__file__)".

§Optional feature flags

The following features is optional.

  • ndarray-basis: enable ndarray support.
  • ndarray-rayon: enable ndarray/rayon feature.

Modules§

ffi

Macros§

idx
A helper macro used to slice tensor.

Structs§

AlgoSelectStrategy
A type to describe fastrun strategy
DataType
A type to describe data
DeviceType
A type to describe device
IO
A type to describe network’s input and output
IOType
A type to describe network’s input and output
Idx
An tensor index of the TensorPool
Layout
The simple layout description
Network
The network is construct from a model, implement model load, init, forward, and display some model information
NetworkBuilder
The network builder
Tensor
The Lite Tensor object
TensorPool
A tensor pool to reuse memory

Enums§

LiteError
A error type

Functions§

clear_memory_pair
Clear the physical and virtual address pair in mge.
default_config
Default network config
device_count
Get device count
dump_persistent_cache
Dump the algo policy cache to file, if the network is set to profile
load
Find and load megenginelite dynamic library.
register_memory_pair
Register the physical and virtual address pair to the mge, some device need the map from physical to virtual.
set_persistent_cache
Set the algo policy cache file for CPU/CUDA …
try_coalesce_all_free_memory
Try to coalesce all free memory in megenine
update_decryption
Update decryption key by name.

Type Aliases§

LiteResult