MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / load

Function load

plugins/wasi_nn/wasinn_piper.cpp:236–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234}
235
236Expect<WASINN::ErrNo> load(WASINN::WasiNNEnvironment &Env,
237 Span<const Span<uint8_t>> Builders, WASINN::Device,
238 uint32_t &GraphId) noexcept {
239 // The graph builder length must be 1.
240 if (Builders.size() != 1) {
241 spdlog::error(
242 "[WASI-NN] Piper backend: Wrong GraphBuilder Length {:d}, expect 1"sv,
243 Builders.size());
244 return WASINN::ErrNo::InvalidArgument;
245 }
246
247 // Add a new graph.
248 uint32_t const GId = Env.newGraph(Backend::Piper);
249 auto &GraphRef = Env.NNGraph[GId].get<Graph>();
250 GraphRef.Config = std::make_unique<RunConfig>();
251 auto String = std::string{Builders[0].begin(), Builders[0].end()};
252 if (auto Res = parseRunConfig(*GraphRef.Config, String);
253 Res != WASINN::ErrNo::Success) {
254 Env.deleteGraph(GId);
255 spdlog::error("[WASI-NN] Piper backend: Failed to parse run config."sv);
256 return Res;
257 }
258
259 std::string EspeakPath = "";
260 if (GraphRef.Config->ESpeakDataPath) {
261 EspeakPath = GraphRef.Config->ESpeakDataPath->string();
262 }
263
264 piper_synthesizer *Synth =
265 piper_create(GraphRef.Config->ModelPath.string().c_str(),
266 GraphRef.Config->ModelConfigPath.string().c_str(),
267 EspeakPath.empty() ? nullptr : EspeakPath.c_str());
268
269 if (!Synth) {
270 spdlog::error(
271 "[WASI-NN] Piper backend: Failed to create piper synthesizer."sv);
272 Env.deleteGraph(GId);
273 return WASINN::ErrNo::InvalidArgument;
274 }
275
276 GraphRef.Synth = std::unique_ptr<piper_synthesizer, PiperDeleter>(Synth);
277 GraphId = GId;
278 Env.NNGraph[GId].setReady();
279 return WASINN::ErrNo::Success;
280}
281
282Expect<WASINN::ErrNo> initExecCtx(WASINN::WasiNNEnvironment &Env,
283 uint32_t GraphId,

Callers

nothing calls this directly

Calls 9

parseRunConfigFunction · 0.85
c_strMethod · 0.80
errorFunction · 0.50
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
setReadyMethod · 0.45

Tested by

no test coverage detected