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

Method body

plugins/wasmedge_tensorflow/tensorflow_func.cpp:73–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71} // namespace
72
73Expect<uint32_t> CreateSession::body(const Runtime::CallingFrame &Frame,
74 uint32_t ModBufPtr, uint32_t ModBufLen,
75 uint32_t SessionIdPtr) {
76 // Check memory instance from module.
77 MEMINST_CHECK(MemInst, Frame, 0)
78
79 // Check the input model buffer.
80 MEM_SPAN_CHECK(ModBufSpan, MemInst, char, ModBufPtr, ModBufLen,
81 "Failed when accessing the input model buffer memory."sv)
82
83 // Check the return value: SessionIdPtr should be valid.
84 MEM_PTR_CHECK(SessionId, MemInst, uint32_t, SessionIdPtr,
85 "Failed when accessing the return SessionID memory."sv)
86
87 // Create context and import graph.
88 uint32_t NewID = Env.newContext();
89 SESSION_CHECK(Cxt, NewID, "Failed when allocating resources."sv,
90 ErrNo::MissingMemory)
91
92 Cxt->Graph = TF_NewGraph();
93 Cxt->Buffer = TF_NewBufferFromString(ModBufSpan.data(), ModBufLen);
94 Cxt->GraphOpts = TF_NewImportGraphDefOptions();
95 TF_GraphImportGraphDef(Cxt->Graph, Cxt->Buffer, Cxt->GraphOpts, Cxt->Stat);
96 if (unlikely(TF_GetCode(Cxt->Stat) != TF_OK)) {
97 spdlog::error("[WasmEdge-Tensorflow] Cannot import graph from buffer: {}"sv,
98 TF_Message(Cxt->Stat));
99 Env.deleteContext(NewID);
100 return static_cast<uint32_t>(ErrNo::InvalidArgument);
101 }
102
103 // Create session.
104 Cxt->SessionOpts = TF_NewSessionOptions();
105 Cxt->Session = TF_NewSession(Cxt->Graph, Cxt->SessionOpts, Cxt->Stat);
106 if (unlikely(TF_GetCode(Cxt->Stat) != TF_OK)) {
107 spdlog::error("[WasmEdge-Tensorflow] Unable to create session: {}"sv,
108 TF_Message(Cxt->Stat));
109 Env.deleteContext(NewID);
110 return static_cast<uint32_t>(ErrNo::InvalidArgument);
111 }
112
113 *SessionId = NewID;
114 return static_cast<uint32_t>(ErrNo::Success);
115}
116
117Expect<uint32_t> CreateSessionSavedModel::body(
118 const Runtime::CallingFrame &Frame, uint32_t PathPtr, uint32_t PathLen,

Callers

nothing calls this directly

Calls 15

unlikelyFunction · 0.85
parseIndexFunction · 0.85
c_strMethod · 0.80
backMethod · 0.80
insertMethod · 0.80
clearInputsMethod · 0.80
clearOutputsMethod · 0.80
errorFunction · 0.50
MEM_SPAN_CHECKFunction · 0.50
likelyFunction · 0.50
newContextMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected