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

Function getOutputSingle

plugins/wasi_nn/wasinn_bitnet.cpp:2262–2297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2260}
2261
2262Expect<ErrNo> getOutputSingle(WasiNNEnvironment &Env, uint32_t ContextId,
2263 uint32_t Index, Span<uint8_t> OutBuffer,
2264 uint32_t &BytesWritten) noexcept {
2265 auto &CxtRef = Env.NNContext[ContextId].get<Context>();
2266 auto &GraphRef = Env.NNGraph[CxtRef.GraphId].get<Graph>();
2267 LOG_DEBUG(GraphRef.EnableDebugLog, "getOutputSingle: with Index {}"sv, Index)
2268
2269 // Metadata Output at Index 1
2270 if (Index == 1) {
2271 const std::string Metadata = buildOutputMetadata(CxtRef);
2272 const size_t BytesToCopy =
2273 std::min(static_cast<size_t>(OutBuffer.size()), Metadata.length());
2274 std::copy_n(Metadata.data(), BytesToCopy, OutBuffer.data());
2275 BytesWritten = static_cast<uint32_t>(Metadata.length());
2276
2277 LOG_DEBUG(GraphRef.EnableDebugLog,
2278 "getOutputSingle: Metadata (Index 1)...Done"sv)
2279 return ErrNo::Success;
2280 }
2281
2282 if (CxtRef.LlamaOutputTokens.empty()) {
2283 BytesWritten = 0;
2284 return ErrNo::Success;
2285 }
2286
2287 const std::string LastTokenStr = common_token_to_piece(
2288 GraphRef.LlamaContext.get(), CxtRef.LlamaOutputTokens.back());
2289
2290 const size_t BytesToCopy =
2291 std::min(static_cast<size_t>(OutBuffer.size()), LastTokenStr.length());
2292 std::copy_n(LastTokenStr.data(), BytesToCopy, OutBuffer.data());
2293 BytesWritten = LastTokenStr.length();
2294
2295 LOG_DEBUG(GraphRef.EnableDebugLog, "getOutputSingle: Text (Index 0)...Done"sv)
2296 return ErrNo::Success;
2297}
2298
2299Expect<ErrNo> computeSingle(WasiNNEnvironment &Env,
2300 uint32_t ContextId) noexcept {

Callers 1

bodyImplMethod · 0.70

Calls 7

backMethod · 0.80
buildOutputMetadataFunction · 0.70
sizeMethod · 0.45
dataMethod · 0.45
emptyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected