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

Method body

plugins/wasmedge_stablediffusion/sd_func.cpp:209–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

207}
208
209Expect<uint32_t> SDConvert::body(const Runtime::CallingFrame &Frame,
210 uint32_t ModelPathPtr, uint32_t ModelPathLen,
211 uint32_t VaeModelPathPtr,
212 uint32_t VaeModelPathLen,
213 uint32_t OutputPathPtr, uint32_t OutputPathLen,
214 uint32_t WType) {
215 // Check memory instance from module.
216 MEMINST_CHECK(MemInst, Frame, 0)
217
218 // Check the input parameter value.
219 MEM_SPAN_CHECK(ModelPathSpan, MemInst, char, ModelPathPtr, ModelPathLen,
220 "Failed when accessing the input model path memory."sv)
221 MEM_SPAN_CHECK(VaeModelPathSpan, MemInst, char, VaeModelPathPtr,
222 VaeModelPathLen,
223 "Failed when accessing the input vae model path memory."sv)
224 MEM_SPAN_CHECK(OutputPathSpan, MemInst, char, OutputPathPtr, OutputPathLen,
225 "Failed when accessing the output path memory."sv)
226 std::string ModelPath = std::string(
227 ModelPathSpan.begin(), ModelPathSpan.begin() + ModelPathSpan.size());
228 std::string VaeModelPath =
229 std::string(VaeModelPathSpan.begin(),
230 VaeModelPathSpan.begin() + VaeModelPathSpan.size());
231 std::string OutputPath = std::string(
232 OutputPathSpan.begin(), OutputPathSpan.begin() + OutputPathSpan.size());
233
234 spdlog::info("[WasmEdge-StableDiffusion] Convert model: {} to {}."sv,
235 ModelPath.data(), OutputPath.data());
236 std::ifstream Fin(ModelPath.data(), std::ios::in | std::ios::binary);
237 if (!Fin) {
238 Fin.close();
239 spdlog::error("[WasmEdge-StableDiffusion] Model not found."sv);
240 return static_cast<uint32_t>(ErrNo::InvalidArgument);
241 }
242 Fin.close();
243 // Convert model.
244 bool Ret = ::convert(ModelPath.data(), VaeModelPath.data(), OutputPath.data(),
245 static_cast<sd_type_t>(WType));
246 if (!Ret) {
247 spdlog::error("[WasmEdge-StableDiffusion] Failed to convert model."sv);
248 return static_cast<uint32_t>(ErrNo::InvalidArgument);
249 }
250
251 return static_cast<uint32_t>(ErrNo::Success);
252}
253
254Expect<uint32_t> SDCreateContext::body(
255 const Runtime::CallingFrame &Frame, uint32_t ModelPathPtr,

Callers

nothing calls this directly

Calls 15

debugFunction · 0.85
parameterCheckFunction · 0.85
readControlImageFunction · 0.85
upscalerModelFunction · 0.85
saveResultsFunction · 0.85
readMaskImageFunction · 0.85
addContextMethod · 0.80
freeContextMethod · 0.80
getNThreadsMethod · 0.80
substrMethod · 0.80
errorFunction · 0.50
convertFunction · 0.50

Tested by

no test coverage detected