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

Function compute

plugins/wasi_nn/wasinn_bitnet.cpp:2212–2260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2210}
2211
2212Expect<ErrNo> compute(WasiNNEnvironment &Env, uint32_t ContextId) noexcept {
2213 auto &CxtRef = Env.NNContext[ContextId].get<Context>();
2214 auto &GraphRef = Env.NNGraph[CxtRef.GraphId].get<Graph>();
2215 LOG_DEBUG(GraphRef.EnableDebugLog, "compute");
2216
2217 // Clear the context and reset the sampler.
2218 clearContext(GraphRef, CxtRef);
2219
2220 if (GraphRef.Params.embedding) {
2221 return getEmbedding(GraphRef, CxtRef);
2222 }
2223
2224 // Evaluate the input tokens.
2225 auto ReturnCode = evaluateInput(GraphRef, CxtRef, "compute"sv);
2226 if (ReturnCode != ErrNo::Success) {
2227 return ReturnCode;
2228 }
2229
2230 // Main prediction loop.
2231 LOG_DEBUG(GraphRef.EnableDebugLog, "compute: enter main prediction loop"sv)
2232 int64_t NPredict = CxtRef.Conf.NPredict;
2233 if (NPredict < 0) {
2234 NPredict = INT32_MAX;
2235 }
2236
2237 while (NPredict > 0) {
2238 ReturnCode = sampleOutput(GraphRef, CxtRef);
2239 if (ReturnCode != ErrNo::Success) {
2240 break;
2241 }
2242 NPredict--;
2243 }
2244
2245 if (ReturnCode == ErrNo::EndOfSequence || ReturnCode == ErrNo::ContextFull) {
2246 LOG_INFO(GraphRef.EnableLog, "compute finished with status: {}."sv,
2247 static_cast<uint32_t>(ReturnCode))
2248 return ErrNo::Success;
2249 }
2250
2251 LOG_DEBUG(GraphRef.EnableDebugLog,
2252 "compute: enter main prediction loop...Done"sv)
2253
2254 if (GraphRef.EnableLog) {
2255 common_perf_print(GraphRef.LlamaContext.get(), CxtRef.LlamaSampler.get());
2256 }
2257
2258 LOG_DEBUG(GraphRef.EnableDebugLog, "compute...Done")
2259 return ReturnCode;
2260}
2261
2262Expect<ErrNo> getOutputSingle(WasiNNEnvironment &Env, uint32_t ContextId,
2263 uint32_t Index, Span<uint8_t> OutBuffer,

Callers

nothing calls this directly

Calls 6

clearContextFunction · 0.70
getEmbeddingFunction · 0.70
evaluateInputFunction · 0.70
sampleOutputFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected