32
32
#include < executorch/extension/data_loader/buffer_data_loader.h>
33
33
#include < executorch/runtime/core/error.h>
34
34
#include < executorch/runtime/core/result.h>
35
- #include < executorch/runtime/executor/executor.h>
35
+ #include < executorch/runtime/executor/method.h>
36
+ #include < executorch/runtime/executor/program.h>
36
37
#include < executorch/runtime/executor/test/managed_memory_manager.h>
37
38
#include < executorch/runtime/platform/log.h>
38
39
#include < executorch/runtime/platform/runtime.h>
@@ -59,10 +60,10 @@ DEFINE_validator(num_instances, &validate_positive_int32);
59
60
namespace {
60
61
using torch::executor::DataLoader;
61
62
using torch::executor::Error;
62
- using torch::executor::Executor;
63
63
using torch::executor::FreeableBuffer;
64
64
using torch::executor::MemoryAllocator;
65
65
using torch::executor::MemoryManager;
66
+ using torch::executor::Method;
66
67
using torch::executor::Program;
67
68
using torch::executor::Result;
68
69
using torch::executor::testing::ManagedMemoryManager;
@@ -86,22 +87,16 @@ class PreparedModel final {
86
87
loader_ (model_data, model_data_size),
87
88
program_(load_program_or_die(loader_)),
88
89
memory_manager_(non_const_mem_bytes, runtime_mem_bytes),
89
- executor_(& program_, &memory_manager_.get()),
90
+ method_(load_method_or_die( program_, &memory_manager_.get() )),
90
91
has_run_(false ) {
91
- Error status = executor_.init_execution_plan ();
92
- ET_CHECK_MSG (
93
- status == Error::Ok,
94
- " init_execution_plan() failed with status 0x%" PRIx32,
95
- status);
96
- inputs_ =
97
- torch::executor::util::PrepareInputTensors (executor_.execution_plan ());
92
+ inputs_ = torch::executor::util::PrepareInputTensors (method_);
98
93
}
99
94
100
95
void run () {
101
96
ET_CHECK_MSG (!has_run_, " A PreparedModel may only be run once" );
102
97
has_run_ = true ;
103
98
104
- Error status = executor_. execution_plan () .execute ();
99
+ Error status = method_ .execute ();
105
100
ET_CHECK_MSG (
106
101
status == Error::Ok,
107
102
" plan.execute() failed with status 0x%" PRIx32,
@@ -125,11 +120,19 @@ class PreparedModel final {
125
120
return std::move (program.get ());
126
121
}
127
122
123
+ static Method load_method_or_die (
124
+ const Program& program,
125
+ MemoryManager* memory_manager) {
126
+ Result<Method> method = program.load_method (" forward" , memory_manager);
127
+ ET_CHECK (method.ok ());
128
+ return std::move (method.get ());
129
+ }
130
+
128
131
const std::string name_;
129
132
BufferDataLoader loader_; // Needs to outlive program_
130
133
Program program_; // Needs to outlive executor_
131
134
ManagedMemoryManager memory_manager_; // Needs to outlive executor_
132
- Executor executor_ ;
135
+ Method method_ ;
133
136
exec_aten::ArrayRef<void *> inputs_;
134
137
135
138
bool has_run_;
0 commit comments