Skip to content

Hide Method's ctor and init() #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 28 additions & 26 deletions runtime/executor/method.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,6 @@ using InstructionArgs = Span<EValue*>;
*/
class Method final {
public:
Method(
const Program* program,
MemoryManager* memory_manager,
EventTracer* event_tracer)
: step_state_(),
program_(program),
memory_manager_(memory_manager),
serialization_plan_(nullptr),
event_tracer_(event_tracer),
n_value_(0),
values_(nullptr),
n_delegate_(0),
delegates_(nullptr),
n_chains_(0),
chains_(nullptr),
init_state_(InitializationState::Uninitialized),
pre_allocated_input_(false),
pre_allocated_output_(false) {}

/**
* Move ctor. Takes ownership of resources previously owned by `rhs`,
* and leaves `rhs` in an uninitialized state.
Expand Down Expand Up @@ -106,13 +87,6 @@ class Method final {
rhs.pre_allocated_output_ = false;
}

/**
* Initialize the method from its serialized representation.
*
* @returns Error::Ok on success, non-Ok on failure.
*/
__ET_NODISCARD Error init(executorch_flatbuffer::ExecutionPlan* s_plan);

/**
* Sets a specific method input to the provided value.
*
Expand Down Expand Up @@ -243,6 +217,8 @@ class Method final {

// Let Program call load().
friend class Program;
// Let Executor call the ctor and init().
friend class Executor;

enum class InitializationState : uint8_t {
Uninitialized,
Expand All @@ -256,13 +232,39 @@ class Method final {
size_t instr_idx;
};

Method(
const Program* program,
MemoryManager* memory_manager,
EventTracer* event_tracer)
: step_state_(),
program_(program),
memory_manager_(memory_manager),
serialization_plan_(nullptr),
event_tracer_(event_tracer),
n_value_(0),
values_(nullptr),
n_delegate_(0),
delegates_(nullptr),
n_chains_(0),
chains_(nullptr),
init_state_(InitializationState::Uninitialized),
pre_allocated_input_(false),
pre_allocated_output_(false) {}

/// Static factory used by Program.
__ET_NODISCARD static Result<Method> load(
executorch_flatbuffer::ExecutionPlan* s_plan,
const Program* program,
MemoryManager* memory_manager,
EventTracer* event_tracer);

/**
* Initialize the method from its serialized representation.
*
* @returns Error::Ok on success, non-Ok on failure.
*/
__ET_NODISCARD Error init(executorch_flatbuffer::ExecutionPlan* s_plan);

/// Returns true if the Method was successfully initialized.
inline bool initialized() const {
return init_state_ == InitializationState::Initialized;
Expand Down