| 71 | } // namespace |
| 72 | |
| 73 | Expect<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 | |
| 117 | Expect<uint32_t> CreateSessionSavedModel::body( |
| 118 | const Runtime::CallingFrame &Frame, uint32_t PathPtr, uint32_t PathLen, |
nothing calls this directly
no test coverage detected