33
33
std::move (*et_result__)); \
34
34
})
35
35
36
- using ::exec_aten::Tensor;
37
- using ::executorch::extension::FileDataLoader;
38
- using ::executorch::extension::MallocMemoryAllocator;
39
- using ::executorch::extension::MmapDataLoader;
40
- using ::executorch::runtime::DataLoader;
41
- using ::executorch::runtime::Error;
42
- using ::executorch::runtime::EValue;
43
- using ::executorch::runtime::EventTracer;
44
- using ::executorch::runtime::HierarchicalAllocator;
45
- using ::executorch::runtime::MemoryAllocator;
46
- using ::executorch::runtime::MemoryManager;
47
- using ::executorch::runtime::MethodMeta;
48
- using ::executorch::runtime::Program;
49
- using ::executorch::runtime::Result;
50
- using ::executorch::runtime::Span;
51
-
52
36
namespace executorch {
53
37
namespace extension {
54
38
55
39
Module::Module (
56
40
const std::string& file_path,
57
- const Module:: LoadMode load_mode,
58
- std::unique_ptr<EventTracer> event_tracer)
41
+ const LoadMode load_mode,
42
+ std::unique_ptr<runtime:: EventTracer> event_tracer)
59
43
: file_path_(file_path),
60
44
load_mode_ (load_mode),
61
45
memory_allocator_(std::make_unique<MallocMemoryAllocator>()),
62
46
temp_allocator_(std::make_unique<MallocMemoryAllocator>()),
63
47
event_tracer_(std::move(event_tracer)) {
64
- ::executorch:: runtime::runtime_init ();
48
+ runtime::runtime_init ();
65
49
}
66
50
67
51
Module::Module (
68
- std::unique_ptr<DataLoader> data_loader,
69
- std::unique_ptr<MemoryAllocator> memory_allocator,
70
- std::unique_ptr<MemoryAllocator> temp_allocator,
71
- std::unique_ptr<EventTracer> event_tracer)
52
+ std::unique_ptr<runtime:: DataLoader> data_loader,
53
+ std::unique_ptr<runtime:: MemoryAllocator> memory_allocator,
54
+ std::unique_ptr<runtime:: MemoryAllocator> temp_allocator,
55
+ std::unique_ptr<runtime:: EventTracer> event_tracer)
72
56
: data_loader_(std::move(data_loader)),
73
57
memory_allocator_(
74
58
memory_allocator ? std::move(memory_allocator)
@@ -77,14 +61,14 @@ Module::Module(
77
61
temp_allocator ? std::move(temp_allocator)
78
62
: std::make_unique<MallocMemoryAllocator>()),
79
63
event_tracer_(std::move(event_tracer)) {
80
- ::executorch:: runtime::runtime_init ();
64
+ runtime::runtime_init ();
81
65
}
82
66
83
67
Module::Module (
84
- std::shared_ptr<Program> program,
85
- std::unique_ptr<MemoryAllocator> memory_allocator,
86
- std::unique_ptr<MemoryAllocator> temp_allocator,
87
- std::unique_ptr<EventTracer> event_tracer)
68
+ std::shared_ptr<runtime:: Program> program,
69
+ std::unique_ptr<runtime:: MemoryAllocator> memory_allocator,
70
+ std::unique_ptr<runtime:: MemoryAllocator> temp_allocator,
71
+ std::unique_ptr<runtime:: EventTracer> event_tracer)
88
72
: program_(std::move(program)),
89
73
memory_allocator_(
90
74
memory_allocator ? std::move(memory_allocator)
@@ -93,10 +77,10 @@ Module::Module(
93
77
temp_allocator ? std::move(temp_allocator)
94
78
: std::make_unique<MallocMemoryAllocator>()),
95
79
event_tracer_(std::move(event_tracer)) {
96
- ::executorch:: runtime::runtime_init ();
80
+ runtime::runtime_init ();
97
81
}
98
82
99
- Error Module::load (const Program::Verification verification) {
83
+ runtime:: Error Module::load (const runtime:: Program::Verification verification) {
100
84
if (!is_loaded ()) {
101
85
if (!data_loader_) {
102
86
switch (load_mode_) {
@@ -119,15 +103,15 @@ Error Module::load(const Program::Verification verification) {
119
103
break ;
120
104
}
121
105
};
122
- auto program =
123
- ET_UNWRAP_UNIQUE ( Program::load (data_loader_.get (), verification));
124
- program_ = std::shared_ptr<Program>(
125
- program.release (), [](Program* pointer) { delete pointer; });
106
+ auto program = ET_UNWRAP_UNIQUE (
107
+ runtime:: Program::load (data_loader_.get (), verification));
108
+ program_ = std::shared_ptr<runtime:: Program>(
109
+ program.release (), [](runtime:: Program* pointer) { delete pointer; });
126
110
}
127
- return Error::Ok;
111
+ return runtime:: Error::Ok;
128
112
}
129
113
130
- Result<std::unordered_set<std::string>> Module::method_names () {
114
+ runtime:: Result<std::unordered_set<std::string>> Module::method_names () {
131
115
ET_CHECK_OK_OR_RETURN_ERROR (load ());
132
116
const auto method_count = program_->num_methods ();
133
117
std::unordered_set<std::string> result;
@@ -139,7 +123,7 @@ Result<std::unordered_set<std::string>> Module::method_names() {
139
123
return result;
140
124
}
141
125
142
- Error Module::load_method (const std::string& method_name) {
126
+ runtime:: Error Module::load_method (const std::string& method_name) {
143
127
if (!is_method_loaded (method_name)) {
144
128
ET_CHECK_OK_OR_RETURN_ERROR (load ());
145
129
@@ -158,10 +142,11 @@ Error Module::load_method(const std::string& method_name) {
158
142
method_holder.planned_spans .emplace_back (
159
143
method_holder.planned_buffers .back ().data (), buffer_size);
160
144
}
161
- method_holder.planned_memory = std::make_unique<HierarchicalAllocator>(Span (
162
- method_holder.planned_spans .data (),
163
- method_holder.planned_spans .size ()));
164
- method_holder.memory_manager = std::make_unique<MemoryManager>(
145
+ method_holder.planned_memory =
146
+ std::make_unique<runtime::HierarchicalAllocator>(runtime::Span (
147
+ method_holder.planned_spans .data (),
148
+ method_holder.planned_spans .size ()));
149
+ method_holder.memory_manager = std::make_unique<runtime::MemoryManager>(
165
150
memory_allocator_.get (),
166
151
method_holder.planned_memory .get (),
167
152
temp_allocator_.get ());
@@ -171,33 +156,36 @@ Error Module::load_method(const std::string& method_name) {
171
156
event_tracer_.get ()));
172
157
methods_.emplace (method_name, std::move (method_holder));
173
158
}
174
- return Error::Ok;
159
+ return runtime:: Error::Ok;
175
160
}
176
161
177
- Result<MethodMeta> Module::method_meta (const std::string& method_name) {
162
+ runtime::Result<runtime::MethodMeta> Module::method_meta (
163
+ const std::string& method_name) {
178
164
ET_CHECK_OK_OR_RETURN_ERROR (load_method (method_name));
179
165
return methods_.at (method_name).method ->method_meta ();
180
166
}
181
167
182
- Result<std::vector<EValue>> Module::execute (
168
+ runtime:: Result<std::vector<runtime:: EValue>> Module::execute (
183
169
const std::string& method_name,
184
- const std::vector<EValue>& input) {
170
+ const std::vector<runtime:: EValue>& input) {
185
171
ET_CHECK_OK_OR_RETURN_ERROR (load_method (method_name));
186
172
auto & method = methods_.at (method_name).method ;
187
173
188
174
ET_CHECK_OK_OR_RETURN_ERROR (method->set_inputs (
189
- exec_aten::ArrayRef<EValue>(input.data (), input.size ())));
175
+ exec_aten::ArrayRef<runtime:: EValue>(input.data (), input.size ())));
190
176
ET_CHECK_OK_OR_RETURN_ERROR (method->execute ());
191
177
192
178
const auto outputs_size = method->outputs_size ();
193
- std::vector<EValue> outputs (outputs_size);
179
+ std::vector<runtime:: EValue> outputs (outputs_size);
194
180
ET_CHECK_OK_OR_RETURN_ERROR (
195
181
method->get_outputs (outputs.data (), outputs_size));
196
182
197
183
return outputs;
198
184
}
199
185
200
- Error Module::set_output_data_ptr (EValue output_value, size_t output_index) {
186
+ runtime::Error Module::set_output_data_ptr (
187
+ runtime::EValue output_value,
188
+ size_t output_index) {
201
189
ET_CHECK_OK_OR_RETURN_ERROR (load_method (" forward" ));
202
190
auto & output_tensor = output_value.toTensor ();
203
191
auto & method = methods_.at (" forward" ).method ;
0 commit comments