Skip to content

Commit 7efdfc0

Browse files
authored
Inline some of the Module methods.
Differential Revision: D61801122 Pull Request resolved: #4913
1 parent 4689c91 commit 7efdfc0

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

extension/module/module.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@ Error Module::load(const Program::Verification verification) {
130130
return Error::Ok;
131131
}
132132

133-
bool Module::is_loaded() const {
134-
return program_ != nullptr;
135-
}
136-
137133
Result<std::unordered_set<std::string>> Module::method_names() {
138134
ET_CHECK_OK_OR_RETURN_ERROR(load());
139135
const auto method_count = program_->num_methods();
@@ -181,10 +177,6 @@ Error Module::load_method(const std::string& method_name) {
181177
return Error::Ok;
182178
}
183179

184-
bool Module::is_method_loaded(const std::string& method_name) const {
185-
return methods_.count(method_name);
186-
}
187-
188180
Result<MethodMeta> Module::method_meta(const std::string& method_name) {
189181
ET_CHECK_OK_OR_RETURN_ERROR(load_method(method_name));
190182
return methods_.at(method_name).method->method_meta();

extension/module/module.h

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,17 @@ class Module final {
111111
*
112112
* @returns true if the program is loaded, false otherwise.
113113
*/
114-
bool is_loaded() const;
114+
inline bool is_loaded() const {
115+
return program_ != nullptr;
116+
}
115117

116118
/**
117119
* Get the program. The data loader used by the program is guaranteed to be
118120
* valid for the lifetime of the program.
119121
*
120122
* @returns Shared pointer to the program or nullptr if it's not yet loaded.
121123
*/
122-
std::shared_ptr<::executorch::runtime::Program> program() const {
124+
inline std::shared_ptr<::executorch::runtime::Program> program() const {
123125
return program_;
124126
}
125127

@@ -151,7 +153,9 @@ class Module final {
151153
* @returns true if the method specified by method_name is loaded, false
152154
* otherwise.
153155
*/
154-
bool is_method_loaded(const std::string& method_name) const;
156+
inline bool is_method_loaded(const std::string& method_name) const {
157+
return methods_.count(method_name);
158+
}
155159

156160
/**
157161
* Get a method metadata struct by method name.
@@ -191,8 +195,8 @@ class Module final {
191195
* @returns A Result object containing either a vector of output values
192196
* from the method or an error to indicate failure.
193197
*/
194-
ET_NODISCARD
195-
::executorch::runtime::Result<std::vector<::executorch::runtime::EValue>>
198+
ET_NODISCARD inline ::executorch::runtime::Result<
199+
std::vector<::executorch::runtime::EValue>>
196200
execute(
197201
const std::string& method_name,
198202
const ::executorch::runtime::EValue& input) {
@@ -209,8 +213,8 @@ class Module final {
209213
* @returns A Result object containing either a vector of output values
210214
* from the method or an error to indicate failure.
211215
*/
212-
ET_NODISCARD
213-
::executorch::runtime::Result<std::vector<::executorch::runtime::EValue>>
216+
ET_NODISCARD inline ::executorch::runtime::Result<
217+
std::vector<::executorch::runtime::EValue>>
214218
execute(const std::string& method_name) {
215219
return execute(method_name, std::vector<::executorch::runtime::EValue>{});
216220
}
@@ -225,9 +229,9 @@ class Module final {
225229
* @returns A Result object containing either the first output value from the
226230
* method or an error to indicate failure.
227231
*/
228-
ET_NODISCARD
229-
::executorch::runtime::Result<::executorch::runtime::EValue> get(
230-
const std::string& method_name,
232+
ET_NODISCARD inline ::executorch::runtime::Result<
233+
::executorch::runtime::EValue>
234+
get(const std::string& method_name,
231235
const std::vector<::executorch::runtime::EValue>& input) {
232236
auto result = ET_UNWRAP(execute(method_name, input));
233237
if (result.empty()) {
@@ -246,9 +250,9 @@ class Module final {
246250
* @returns A Result object containing either the first output value from the
247251
* method or an error to indicate failure.
248252
*/
249-
ET_NODISCARD
250-
::executorch::runtime::Result<::executorch::runtime::EValue> get(
251-
const std::string& method_name,
253+
ET_NODISCARD inline ::executorch::runtime::Result<
254+
::executorch::runtime::EValue>
255+
get(const std::string& method_name,
252256
const ::executorch::runtime::EValue& input) {
253257
return get(method_name, std::vector<::executorch::runtime::EValue>{input});
254258
}
@@ -262,9 +266,9 @@ class Module final {
262266
* @returns A Result object containing either the first output value from the
263267
* method or an error to indicate failure.
264268
*/
265-
ET_NODISCARD
266-
::executorch::runtime::Result<::executorch::runtime::EValue> get(
267-
const std::string& method_name) {
269+
ET_NODISCARD inline ::executorch::runtime::Result<
270+
::executorch::runtime::EValue>
271+
get(const std::string& method_name) {
268272
return get(method_name, std::vector<::executorch::runtime::EValue>{});
269273
}
270274

@@ -277,8 +281,8 @@ class Module final {
277281
* @returns A Result object containing either a vector of output values
278282
* from the 'forward' method or an error to indicate failure.
279283
*/
280-
ET_NODISCARD
281-
::executorch::runtime::Result<std::vector<::executorch::runtime::EValue>>
284+
ET_NODISCARD inline ::executorch::runtime::Result<
285+
std::vector<::executorch::runtime::EValue>>
282286
forward(const std::vector<::executorch::runtime::EValue>& input) {
283287
return execute("forward", input);
284288
}
@@ -292,8 +296,8 @@ class Module final {
292296
* @returns A Result object containing either a vector of output values
293297
* from the 'forward' method or an error to indicate failure.
294298
*/
295-
ET_NODISCARD
296-
::executorch::runtime::Result<std::vector<::executorch::runtime::EValue>>
299+
ET_NODISCARD inline ::executorch::runtime::Result<
300+
std::vector<::executorch::runtime::EValue>>
297301
forward(const ::executorch::runtime::EValue& input) {
298302
return forward(std::vector<::executorch::runtime::EValue>{input});
299303
}
@@ -305,8 +309,8 @@ class Module final {
305309
* @returns A Result object containing either a vector of output values
306310
* from the 'forward' method or an error to indicate failure.
307311
*/
308-
ET_NODISCARD
309-
::executorch::runtime::Result<std::vector<::executorch::runtime::EValue>>
312+
ET_NODISCARD inline ::executorch::runtime::Result<
313+
std::vector<::executorch::runtime::EValue>>
310314
forward() {
311315
return forward(std::vector<::executorch::runtime::EValue>{});
312316
}
@@ -319,7 +323,7 @@ class Module final {
319323
* @returns A pointer to the EventTracer instance. Returns nullptr if no
320324
* EventTracer is set.
321325
*/
322-
::executorch::runtime::EventTracer* event_tracer() const {
326+
inline ::executorch::runtime::EventTracer* event_tracer() const {
323327
return event_tracer_.get();
324328
}
325329

0 commit comments

Comments
 (0)