Skip to content

Add get_inputs to method.cpp #3775

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
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions runtime/executor/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,28 @@ Method::get_outputs(EValue* output_evalues, size_t length) {
return Error::Ok;
}

__ET_NODISCARD Error Method::get_inputs(EValue* input_evalues, size_t length) {
ET_CHECK_OR_RETURN_ERROR(
initialized(),
InvalidState,
"Inputs can not be retrieved until method has been initialized.");

ET_CHECK_OR_RETURN_ERROR(
length >= inputs_size(),
InvalidArgument,
"The given array is not large enough to hold all inputs.");

for (size_t i = 0; i < inputs_size(); i++) {
input_evalues[i] = values_[get_input_index(i)];
}

for (size_t i = inputs_size(); i < length; i++) {
input_evalues[i] = EValue();
}

return Error::Ok;
}

Error Method::execute_instruction() {
auto& chain = chains_[step_state_.chain_idx];
auto instructions = chain.s_chain_->instructions();
Expand Down
16 changes: 16 additions & 0 deletions runtime/executor/method.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@ class Method final {
*/
__ET_NODISCARD Error get_outputs(EValue* output_evalues, size_t length);

/**
* Copies the method's inputs into the provided array.
*
* WARNING: The input contains shallow copies of internal tensor inputs.
* Please do not mutate returned Tensor elements.
*
* @param[in] input_evalues The array to copy the inputs into. The first
* `inputs_size()` elements will be set to the corresponding input
* values. The rest of the array will be set to the EValue value None.
* @param[in] length The size of the `input_evalues` array in elements. Must
* be greater than or equal to `inputs_size()`.
*
* @returns Error::Ok on success, non-Ok on failure.
*/
__ET_NODISCARD Error get_inputs(EValue* input_evalues, size_t length);

/**
* Execute the method.
*
Expand Down
Loading