Skip to content

Commit

Permalink
[API] Add the API to set WASI-NN preloads. (WasmEdge#2827)
Browse files Browse the repository at this point in the history
Signed-off-by: YiYing He <[email protected]>
  • Loading branch information
q82419 committed Sep 20, 2023
1 parent 558f6ad commit f0d1e67
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/api/wasmedge/wasmedge.h
Original file line number Diff line number Diff line change
Expand Up @@ -3627,6 +3627,18 @@ WASMEDGE_CAPI_EXPORT extern WasmEdge_ModuleInstanceContext *
WasmEdge_PluginCreateModule(const WasmEdge_PluginContext *Cxt,
const WasmEdge_String ModuleName);

/// Initialize the wasi_nn plug-in.
///
/// This function will initialize the wasi_nn plug-in with the preloads string
/// list. Only available after loading the wasi_nn plug-in and before creating
/// the module instance from the plug-in.
///
/// \param NNPreloads the preload string list. NULL if the length is 0.
/// \param PreloadsLen the length of the preload list.
WASMEDGE_CAPI_EXPORT extern void
WasmEdge_PluginInitWASINN(const char *const *NNPreloads,
const uint32_t PreloadsLen);

/// Implement by plugins for returning the plugin descriptor.
///
/// \returns the plugin descriptor.
Expand Down
13 changes: 13 additions & 0 deletions lib/api/wasmedge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2940,6 +2940,19 @@ WasmEdge_PluginCreateModule(const WasmEdge_PluginContext *Cxt,
return nullptr;
}

WASMEDGE_CAPI_EXPORT void
WasmEdge_PluginInitWASINN(const char *const *NNPreloads,
const uint32_t PreloadsLen) {
using namespace std::literals::string_view_literals;
if (const auto *Plugin = WasmEdge::Plugin::Plugin::find("wasi_nn"sv)) {
PO::ArgumentParser Parser;
Plugin->registerOptions(Parser);
Parser.set_raw_value<std::vector<std::string>>(
"nn-preload"sv,
std::vector<std::string>(NNPreloads, NNPreloads + PreloadsLen));
}
}

// <<<<<<<< WasmEdge Plugin functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

// >>>>>>>> WasmEdge Experimental functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Expand Down

0 comments on commit f0d1e67

Please sign in to comment.