Skip to content

Commit fdaf6fa

Browse files
JacobSzwejbkafacebook-github-bot
authored andcommitted
flag a bunch of method functions as deprecated (#523)
Summary: Pull Request resolved: #523 None of these should exist in the public API, but we are out of time before MVP so just deprecating. Added a way to get a MethodMeta from method. Reviewed By: dbort Differential Revision: D49747135 fbshipit-source-id: 93e11bb6870a63a4eec9e60926e43e0f52dbf2f2
1 parent e0cde5b commit fdaf6fa

File tree

3 files changed

+57
-8
lines changed

3 files changed

+57
-8
lines changed

runtime/executor/method.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,17 @@ Error Method::execute() {
11011101
return experimental_reset_execution();
11021102
}
11031103

1104+
MethodMeta Method::method_meta() const {
1105+
auto name = serialization_plan_->name()->c_str();
1106+
auto method_meta = program_->method_meta(name);
1107+
ET_CHECK_MSG(
1108+
method_meta.ok(),
1109+
"Internal error: method_meta(%s) returned 0x%" PRIx32,
1110+
name,
1111+
static_cast<uint32_t>(method_meta.error()));
1112+
return method_meta.get();
1113+
}
1114+
11041115
size_t Method::values_size() const {
11051116
return n_value_;
11061117
}

runtime/executor/method.h

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <executorch/runtime/core/event_tracer.h>
1313
#include <executorch/runtime/core/exec_aten/exec_aten.h>
1414
#include <executorch/runtime/executor/memory_manager.h>
15+
#include <executorch/runtime/executor/method_meta.h>
1516
#include <executorch/runtime/platform/compiler.h>
1617

1718
// Forward declare flatbuffer types. This is a public header and must not
@@ -196,17 +197,43 @@ class Method final {
196197
*/
197198
__ET_NODISCARD Error experimental_reset_execution();
198199

199-
size_t values_size() const;
200-
const EValue& get_value(size_t i) const;
201-
EValue& mutable_value(size_t i);
200+
/**
201+
* Returns the MethodMeta that corresponds to the calling Method.
202+
*/
203+
MethodMeta method_meta() const;
204+
205+
/**
206+
* Returns the number of inputs the Method expects.
207+
*/
202208
size_t inputs_size() const;
203-
size_t get_input_index(size_t i) const;
204-
const EValue& get_input(size_t i) const;
205-
EValue& mutable_input(size_t i);
209+
210+
/**
211+
* Returns the number of outputs the Method returns.
212+
*/
206213
size_t outputs_size() const;
207-
size_t get_output_index(size_t i) const;
214+
215+
/**
216+
* Retrieves the output at the specified index.
217+
*/
208218
const EValue& get_output(size_t i) const;
209-
EValue& mutable_output(size_t i);
219+
220+
__ET_DEPRECATED size_t values_size() const;
221+
__ET_DEPRECATED const EValue& get_value(size_t i) const;
222+
__ET_DEPRECATED EValue& mutable_value(size_t i);
223+
/// DEPRECATED: Use MethodMeta instead to access metadata, and set_input to
224+
/// update Method inputs.
225+
__ET_DEPRECATED size_t get_input_index(size_t i) const;
226+
/// DEPRECATED: Use MethodMeta instead to access metadata, and set_input to
227+
/// update Method inputs.
228+
__ET_DEPRECATED const EValue& get_input(size_t i) const;
229+
/// DEPRECATED: Use MethodMeta instead to access metadata, and set_input to
230+
/// update Method inputs.
231+
__ET_DEPRECATED EValue& mutable_input(size_t i);
232+
__ET_DEPRECATED size_t get_output_index(size_t i) const;
233+
/// DEPRECATED: Use MethodMeta instead to access metadata, and get_output to
234+
/// retrieve Method outputs.
235+
__ET_DEPRECATED EValue& mutable_output(size_t i);
236+
210237
~Method();
211238

212239
private:

runtime/executor/test/method_test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ TEST_F(MethodTest, SetPrimInputTest) {
116116
torch::executor::util::FreeInputs(inputs);
117117
}
118118

119+
TEST_F(MethodTest, MethodMetaTest) {
120+
ManagedMemoryManager mmm(kDefaultNonConstMemBytes, kDefaultRuntimeMemBytes);
121+
Result<Method> method = programs_["add"]->load_method("forward", &mmm.get());
122+
ASSERT_EQ(method.error(), Error::Ok);
123+
124+
auto method_meta = method->method_meta();
125+
126+
EXPECT_EQ(method_meta.num_inputs(), method->inputs_size());
127+
EXPECT_EQ(method_meta.num_outputs(), method->outputs_size());
128+
}
129+
119130
TEST_F(MethodTest, AliasedIOTest) {
120131
// TODO(T163238401)
121132
ManagedMemoryManager mmm(kDefaultNonConstMemBytes, kDefaultRuntimeMemBytes);

0 commit comments

Comments
 (0)