| 289 | } |
| 290 | |
| 291 | Expect<WASINN::ErrNo> setInput(WASINN::WasiNNEnvironment &Env, |
| 292 | uint32_t ContextId, uint32_t Index, |
| 293 | const TensorData &Tensor) noexcept { |
| 294 | if (Index != 0) { |
| 295 | spdlog::error("[WASI-NN] Piper backend: Input index must be 0."sv); |
| 296 | return WASINN::ErrNo::InvalidArgument; |
| 297 | } |
| 298 | if (Tensor.Dimension.size() != 1) { |
| 299 | spdlog::error( |
| 300 | "[WASI-NN] Piper backend: Input tensor dimension must be 1D."sv); |
| 301 | return WASINN::ErrNo::InvalidArgument; |
| 302 | } |
| 303 | |
| 304 | auto &CxtRef = Env.NNContext[ContextId].get<Context>(); |
| 305 | auto &GraphRef = Env.NNGraph[CxtRef.GraphId].get<Graph>(); |
| 306 | |
| 307 | CxtRef.Line = |
| 308 | std::string(reinterpret_cast<const char *>(Tensor.Tensor.data()), |
| 309 | Tensor.Tensor.size()); |
| 310 | |
| 311 | if (GraphRef.Config->JsonInput) { |
| 312 | simdjson::dom::parser Parser; |
| 313 | simdjson::dom::element Doc; |
| 314 | simdjson::padded_string const PaddedInput(CxtRef.Line.value()); |
| 315 | |
| 316 | if (Parser.parse(PaddedInput).get(Doc) != simdjson::SUCCESS) { |
| 317 | spdlog::error("[WASI-NN] Piper backend: Failed to parse JSON input."sv); |
| 318 | return WASINN::ErrNo::InvalidArgument; |
| 319 | } |
| 320 | |
| 321 | simdjson::dom::object JsonObj; |
| 322 | if (Doc.get(JsonObj) != simdjson::SUCCESS) { |
| 323 | spdlog::error("[WASI-NN] Piper backend: JSON input is not an object."sv); |
| 324 | return WASINN::ErrNo::InvalidArgument; |
| 325 | } |
| 326 | |
| 327 | SynthesisConfig NewConfig; |
| 328 | if (auto Err = parseSynthesisConfig(NewConfig, JsonObj); |
| 329 | Err != WASINN::ErrNo::Success) { |
| 330 | return Err; |
| 331 | } |
| 332 | CxtRef.JsonInputSynthesisConfig = |
| 333 | std::make_unique<std::optional<SynthesisConfig>>(NewConfig); |
| 334 | } |
| 335 | return WASINN::ErrNo::Success; |
| 336 | } |
| 337 | |
| 338 | Expect<WASINN::ErrNo> getOutput(WASINN::WasiNNEnvironment &Env, |
| 339 | uint32_t ContextId, uint32_t Index, |
nothing calls this directly
no test coverage detected