Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Implement new API PluginManager::nn_preload #69

Merged
merged 7 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-20.04]
rust: [1.71, 1.70.0, 1.69]
rust: [1.72, 1.71, 1.70.0]
container:
image: wasmedge/wasmedge:ubuntu-build-clang

Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [1.71, 1.70.0, 1.69]
rust: [1.72, 1.71, 1.70.0]
container:
image: fedora:latest

Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:
strategy:
matrix:
os: [macos-11, macos-12]
rust: [1.71, 1.70.0, 1.69]
rust: [1.72, 1.71, 1.70.0]

steps:
- name: Checkout sources
Expand Down Expand Up @@ -222,7 +222,7 @@ jobs:
runs-on: windows-2022
strategy:
matrix:
rust: [1.71, 1.70.0, 1.69]
rust: [1.72, 1.71, 1.70.0]
env:
WASMEDGE_DIR: ${{ github.workspace }}\WasmEdge
WASMEDGE_BUILD_DIR: ${{ github.workspace }}\WasmEdge\build
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
rust: [1.71, 1.70.0, 1.69]
rust: [1.72, 1.71, 1.70.0]

steps:
- name: Checkout WasmEdge Rust SDK
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
rust: [1.71, 1.70.0, 1.69]
rust: [1.72, 1.71, 1.70.0]

steps:
- name: Checkout WasmEdge Rust SDK
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
strategy:
matrix:
os: [macos-11, macos-12]
rust: [1.71, 1.70.0, 1.69]
rust: [1.72, 1.71, 1.70.0]

steps:
- name: Checkout sources
Expand Down Expand Up @@ -119,7 +119,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [1.71, 1.70.0, 1.69]
rust: [1.72, 1.71, 1.70.0]
container:
image: fedora:latest

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "Apache-2.0"
name = "wasmedge-sdk"
readme = "README.md"
repository = "https://github.com/WasmEdge/wasmedge-rust-sdk"
version = "0.12.1"
version = "0.12.2-dev"

[dependencies]
anyhow = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmedge-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ links = "wasmedge"
name = "wasmedge-sys"
readme = "README.md"
repository = "https://github.com/WasmEdge/wasmedge-rust-sdk"
version = "0.17.1"
version = "0.17.2"

[dependencies]
fiber-for-wasmedge = { version = "8.0.1", optional = true }
Expand Down
17 changes: 16 additions & 1 deletion crates/wasmedge-sys/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use crate::{
utils, AsImport, Instance, WasmEdgeResult,
};
use parking_lot::Mutex;
use std::{ffi::CString, os::raw::c_void, sync::Arc};
use std::{
ffi::{c_void, CString},
sync::Arc,
};
use wasmedge_types::error::{InstanceError, PluginError, WasmEdgeError};

/// Defines the APIs for loading plugins and check the basic information of the loaded plugins.
Expand Down Expand Up @@ -45,6 +48,18 @@ impl PluginManager {
Ok(())
}

#[cfg(feature = "wasi_nn")]
#[cfg_attr(docsrs, doc(cfg(feature = "wasi_nn")))]
pub fn nn_preload(preloads: Vec<&str>) {
let c_args: Vec<CString> = preloads
.iter()
.map(|&x| std::ffi::CString::new(x).unwrap())
.collect();
let c_strs: Vec<*const i8> = c_args.iter().map(|x| x.as_ptr()).collect();
let len = c_strs.len() as u32;
unsafe { ffi::WasmEdge_PluginInitWASINN(c_strs.as_ptr(), len) }
}

/// Returns the count of loaded plugins.
pub fn count() -> u32 {
unsafe { ffi::WasmEdge_PluginListPluginsLength() }
Expand Down
6 changes: 6 additions & 0 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ impl PluginManager {
}
}

#[cfg(feature = "wasi_nn")]
#[cfg_attr(docsrs, doc(cfg(feature = "wasi_nn")))]
pub fn nn_preload(preloads: Vec<&str>) {
sys::plugin::PluginManager::nn_preload(preloads);
}

/// Returns the count of loaded plugins.
pub fn count() -> u32 {
sys::plugin::PluginManager::count()
Expand Down