Skip to content

Commit d7dd048

Browse files
[ExecuTorch][#9638] Introduce Protected Method Getter in Extension.Module
Differential Revision: D73473766 Pull Request resolved: #10374
1 parent 95c663e commit d7dd048

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

extension/module/module.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,5 +302,15 @@ runtime::Error Module::set_output(
302302
output_tensor.mutable_data_ptr(), output_tensor.nbytes(), output_index);
303303
}
304304

305+
ET_NODISCARD inline runtime::Result<Method*> Module::get_method(
306+
const std::string& method_name) {
307+
ET_CHECK_OR_RETURN_ERROR(
308+
methods_.count(method_name) > 0,
309+
InvalidArgument,
310+
"no such method in program: %s",
311+
method_name.c_str());
312+
return methods_[method_name].method.get();
313+
}
314+
305315
} // namespace extension
306316
} // namespace executorch

extension/module/module.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,16 @@ class Module {
493493
std::unique_ptr<NamedDataMap> data_map_;
494494

495495
protected:
496+
/**
497+
* Get a method by method name.
498+
*
499+
* @param[in] method_name The name of the method to get.
500+
*
501+
* @returns A Result object containing either a pointer to the requested
502+
* method or an error to indicate failure.
503+
*/
504+
ET_NODISCARD inline runtime::Result<Method*> get_method(
505+
const std::string& method_name);
496506
std::unordered_map<std::string, MethodHolder> methods_;
497507

498508
friend class ExecuTorchJni;

0 commit comments

Comments
 (0)