Skip to content

Commit

Permalink
refactor method to return err together (pytorch#1212)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#1212

Feedback from D51234032, just so we can reset temp allocator in `execute_instruction` to as it's shared by both step and execute

Reviewed By: JacobSzwejbka

Differential Revision: D51315734

fbshipit-source-id: d3250a8cc8c4281b210d6e256818047bc8a99fb7
  • Loading branch information
cccclai authored and facebook-github-bot committed Nov 15, 2023
1 parent 3448a74 commit 3f32b96
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions runtime/executor/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,8 @@ Error Method::execute_instruction() {
(size_t)instructions->size());

auto instruction = instructions->Get(step_state_.instr_idx);
size_t next_instr_idx = step_state_.instr_idx + 1;
Error err = Error::Ok;
switch (instruction->instr_args_type()) {
case executorch_flatbuffer::InstructionArguments::KernelCall: {
EXECUTORCH_SCOPE_PROF("OPERATOR_CALL");
Expand All @@ -915,7 +917,7 @@ Error Method::execute_instruction() {
KernelRuntimeContext context(event_tracer_);
auto args = chain.argument_lists_[step_state_.instr_idx];
chain.kernels_[step_state_.instr_idx](context, args.data());
Error err = context.failure_state();
err = context.failure_state();
if (err != Error::Ok) {
auto op_index = instruction->instr_args_as_KernelCall()->op_index();
auto op = serialization_plan_->operators()->Get(op_index);
Expand All @@ -937,7 +939,6 @@ Error Method::execute_instruction() {
// TODO(T153804650): Consider logging the EValues to help with
// debugging. This is a failure path, and it doesn't matter if it's a
// little slow. Do the same for DelegateCall errors.
return err;
}
} break;
case executorch_flatbuffer::InstructionArguments::DelegateCall: {
Expand All @@ -955,7 +956,7 @@ Error Method::execute_instruction() {
n_delegate_,
step_state_.instr_idx);
BackendExecutionContext backend_execution_context(event_tracer_);
Error err = delegates_[delegate_idx].Execute(
err = delegates_[delegate_idx].Execute(
backend_execution_context,
chain.argument_lists_[step_state_.instr_idx].data());
if (err != Error::Ok) {
Expand All @@ -964,7 +965,6 @@ Error Method::execute_instruction() {
"CALL_DELEGATE execute failed at instruction %zu: 0x%" PRIx32,
step_state_.instr_idx,
static_cast<uint32_t>(err));
return err;
}
} break;
case executorch_flatbuffer::InstructionArguments::JumpFalseCall: {
Expand All @@ -974,8 +974,8 @@ Error Method::execute_instruction() {
auto jf_call = instruction->instr_args_as_JumpFalseCall();
bool jf_result = parse_cond_value(values_[jf_call->cond_value_index()]);
if (!jf_result) {
step_state_.instr_idx = jf_call->destination_instruction();
return Error::Ok;
next_instr_idx = jf_call->destination_instruction();
// return Error::Ok;
}
} break;
case executorch_flatbuffer::InstructionArguments::MoveCall: {
Expand All @@ -999,8 +999,10 @@ Error Method::execute_instruction() {
"Instruction is not supported. %hhu",
static_cast<uint8_t>(instruction->instr_args_type()));
}
step_state_.instr_idx += 1;
return Error::Ok;
if (err == Error::Ok) {
step_state_.instr_idx = next_instr_idx;
}
return err;
}

Error Method::experimental_reset_execution() {
Expand Down

0 comments on commit 3f32b96

Please sign in to comment.