1+ #include " ExecutorchModule.h"
2+
3+ #include < fmt/core.h>
4+ #include < rnexecutorch/Log.h>
5+
6+ namespace rnexecutorch {
7+
8+ using ::executorch::extension::Module;
9+ using ::executorch::runtime::Error;
10+
11+ ExecutorchModule::ExecutorchModule (const std::string &modelSource,
12+ facebook::jsi::Runtime *runtime)
13+ : module (std::make_unique<Module>(
14+ modelSource, Module::LoadMode::MmapUseMlockIgnoreErrors)),
15+ runtime (runtime) {
16+ Error loadError = module ->load ();
17+ if (loadError != Error::Ok) {
18+ throw std::runtime_error (" Couldn't load the model, error: " +
19+ std::to_string (static_cast <uint32_t >(loadError)));
20+ }
21+ }
22+
23+ std::vector<int32_t > ExecutorchModule::getInputShape (std::string method_name,
24+ int index) {
25+ auto method_meta = module ->method_meta (method_name);
26+ if (!method_meta.ok ()) {
27+ throw std::runtime_error (
28+ fmt::format (" Failed to load method with name {}" , method_name));
29+ }
30+
31+ std::vector<int32_t > input_shape;
32+ auto input_meta = method_meta->input_tensor_meta (index);
33+ if (!input_meta.ok ()) {
34+ throw std::runtime_error (
35+ fmt::format (" Failed to load forward input {}" , index));
36+ }
37+
38+ for (auto size : input_meta->sizes ()) {
39+ input_shape.push_back (size);
40+ }
41+ return input_shape;
42+ }
43+ } // namespace rnexecutorch
0 commit comments