Skip to content

Commit

Permalink
Prepare for release 0.1.0-rc.1 (#11)
Browse files Browse the repository at this point in the history
* Fill more metadata in Cargo.toml

* Remove 'extension-' prefix from features names

* Implement common traints for structs and enums

* Remove re-use at lib level

* Crate documentation

* Change version to 0.1.0-rc.1

* Avoid linking to static libs when building docs

* Enable all features when built by docs.rs
  • Loading branch information
barakugav committed Aug 3, 2024
1 parent 69092fc commit c33457c
Show file tree
Hide file tree
Showing 22 changed files with 845 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ target/
*.pdb

.vscode/
.venv/
32 changes: 28 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,38 @@ members = [

[package]
name = "executorch"
version = "0.1.0"
version = "0.1.0-rc.1"
authors = ["Barak Ugav <barakugav@gmail.com>"]
edition = "2021"
description = "Rust bindings for ExecuTorch - On-device AI across mobile, embedded and edge for PyTorch"
readme = "README.md"
repository = "https://github.com/barakugav/executorch-rs"
license = "Apache-2.0"
keywords = [
"executorch",
"pytorch",
"ai",
"ml",
"machine-learning",
"mobile",
"embedded",
"edge-device",
"bindings",
]
categories = [
"algorithms",
"mathematics",
"embedded",
"no-std",
"no-std::no-alloc",
]
include = ["Cargo.toml", "src/", "README.md", "LICENSE"]

[package.metadata.docs.rs]
features = ["data-loader", "module"]

[dependencies]
executorch-sys = { path = "executorch-sys" }
executorch-sys = { path = "executorch-sys", version = "0.1.0-rc.1" }
ndarray = "0.15.6"
log = "0.4.22"

Expand All @@ -24,5 +48,5 @@ cc = "1.1.6"
envsubst = "0.2.1"

[features]
extension-data-loader = ["executorch-sys/extension-data-loader"]
extension-module = ["executorch-sys/extension-module"]
data-loader = ["executorch-sys/data-loader"]
module = ["executorch-sys/module"]
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ with open("model.pte", "wb") as file:
```
Execute the model in Rust:
```rust
use executorch::{EValue, Module, Tag, Tensor, TensorImpl};
use executorch::evalue::{EValue, Tag};
use executorch::module::Module;
use executorch::tensor::{Tensor, TensorImpl};
use ndarray::array;

let mut module = Module::new("model.pte", None);
Expand All @@ -45,10 +47,10 @@ let outputs = module.forward(&[input_evalue1, input_evalue2]).unwrap();
assert_eq!(outputs.len(), 1);
let output = outputs.into_iter().next().unwrap();
assert_eq!(output.tag(), Some(Tag::Tensor));
let output = output.as_tensor().as_array::<f32>();
let output = output.as_tensor();

println!("Output tensor computed: {:?}", output);
assert_eq!(output, array![2.0].into_dyn());
assert_eq!(array![2.0_f32], output.as_array());
```
See `example/hello_world_add` and `example/hello_world_add_module` for the complete examples.

Expand Down Expand Up @@ -121,6 +123,6 @@ println!("cargo::rustc-link-search={}/kernels/portable/", libs_dir);
Note that the `portable_ops_lib` is linked with `+whole-archive` to ensure that all symbols are included in the binary.

## Cargo Features
- `default`: disables all features.
- `extension-data-loader`: include the `FileDataLoader` strut. The `libextension_data_loader.a` static library is required, compile C++ `executorch` with `EXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON`.
- `extension-module`: include the `Module` strut. The `libextension_module_static.a` static library is required, compile C++ `executorch` with `EXECUTORCH_BUILD_EXTENSION_MODULE=ON`.
By default all features are disabled.
- `data-loader`: include the `FileDataLoader` struct. The `libextension_data_loader.a` static library is required, compile C++ `executorch` with `EXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON`.
- `module`: include the `Module` struct. The `libextension_module_static.a` static library is required, compile C++ `executorch` with `EXECUTORCH_BUILD_EXTENSION_MODULE=ON`.
2 changes: 1 addition & 1 deletion examples/hello_world_add/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = "0.0.0"
edition = "2021"

[dependencies]
executorch = { path = "../../", features = ["extension-data-loader"] }
executorch = { path = "../../", features = ["data-loader"] }
log = "0.4.22"
env_logger = "0.11.3"
ndarray = "0.15.6"
Expand Down
17 changes: 9 additions & 8 deletions examples/hello_world_add/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#![deny(warnings)]

use executorch::data_loader::FileDataLoader;
use executorch::evalue::{EValue, Tag};
use executorch::memory::{HierarchicalAllocator, MallocMemoryAllocator, MemoryManager};
use executorch::program::{Program, ProgramVerification};
use executorch::tensor::{Tensor, TensorImpl};
use executorch::util::Span;
use executorch::{
EValue, HierarchicalAllocator, MallocMemoryAllocator, MemoryManager, Program,
ProgramVerification, Tag, Tensor, TensorImpl,
};

use ndarray::array;
use std::vec;

Expand All @@ -14,7 +15,7 @@ fn main() {
.filter_level(log::LevelFilter::Debug)
.init();

executorch::pal_init();
executorch::platform::pal_init();

let mut file_data_loader = FileDataLoader::new("model.pte", None).unwrap();

Expand Down Expand Up @@ -57,10 +58,10 @@ fn main() {
method_exe.set_input(&input_evalue2, 1).unwrap();

let outputs = method_exe.execute().unwrap();
let output = outputs.get_output(0);
let output = &outputs[0];
assert_eq!(output.tag(), Some(Tag::Tensor));
let output = output.as_tensor().as_array_dyn::<f32>();
let output = output.as_tensor();

println!("Output tensor computed: {:?}", output);
assert_eq!(output, array![2.0].into_dyn());
assert_eq!(array![2.0_f32], output.as_array());
}
5 changes: 1 addition & 4 deletions examples/hello_world_add_module/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ version = "0.0.0"
edition = "2021"

[dependencies]
executorch = { path = "../../", features = [
"extension-data-loader",
"extension-module",
] }
executorch = { path = "../../", features = ["data-loader", "module"] }
log = "0.4.22"
env_logger = "0.11.3"
ndarray = "0.15.6"
Expand Down
10 changes: 6 additions & 4 deletions examples/hello_world_add_module/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#![deny(warnings)]

use executorch::{EValue, Module, Tag, Tensor, TensorImpl};
use executorch::evalue::{EValue, Tag};
use executorch::module::Module;
use executorch::tensor::{Tensor, TensorImpl};
use ndarray::array;

fn main() {
env_logger::Builder::new()
.filter_level(log::LevelFilter::Debug)
.init();

executorch::pal_init();
executorch::platform::pal_init();

let mut module = Module::new("model.pte", None);

Expand All @@ -24,8 +26,8 @@ fn main() {
assert_eq!(outputs.len(), 1);
let output = outputs.into_iter().next().unwrap();
assert_eq!(output.tag(), Some(Tag::Tensor));
let output = output.as_tensor().as_array_dyn::<f32>();
let output = output.as_tensor();

println!("Output tensor computed: {:?}", output);
assert_eq!(output, array![2.0].into_dyn());
assert_eq!(array![2.0_f32], output.as_array());
}
33 changes: 30 additions & 3 deletions executorch-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
[package]
name = "executorch-sys"
version = "0.1.0"
version = "0.1.0-rc.1"
authors = ["Barak Ugav <barakugav@gmail.com>"]
edition = "2021"
description = "Unsafe Rust bindings for ExecuTorch - On-device AI across mobile, embedded and edge for PyTorch"
readme = "README.md"
repository = "https://github.com/barakugav/executorch-rs"
license = "Apache-2.0"
keywords = [
"executorch",
"pytorch",
"ai",
"ml",
"machine-learning",
"mobile",
"embedded",
"edge-device",
"bindings",
]
categories = [
"algorithms",
"mathematics",
"embedded",
"no-std",
"no-std::no-alloc",
]
links = "executorch"

[package.metadata.docs.rs]
features = ["data-loader", "module"]

[features]
extension-data-loader = []
extension-module = []
data-loader = []
module = []

[dependencies]

Expand Down
Loading

0 comments on commit c33457c

Please sign in to comment.