Skip to content

[executorch] Print executor_runner outputs using EValue's new operator<<() #481

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 3 commits 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
28 changes: 7 additions & 21 deletions examples/executor_runner/executor_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
* all fp32 tensors.
*/

#include <iostream>
#include <memory>

#include <gflags/gflags.h>

#include <executorch/extension/data_loader/file_data_loader.h>
#include <executorch/extension/evalue_util/print_evalue.h>
#include <executorch/runtime/executor/method.h>
#include <executorch/runtime/executor/program.h>
#include <executorch/runtime/platform/log.h>
Expand Down Expand Up @@ -169,29 +171,13 @@ int main(int argc, char** argv) {

// Print the outputs.
std::vector<EValue> outputs(method->outputs_size());
ET_LOG(Info, "%zu outputs: ", outputs.size());
status = method->get_outputs(outputs.data(), outputs.size());
ET_CHECK(status == Error::Ok);
for (EValue& output : outputs) {
// TODO(T159700776): This assumes that all outputs are fp32 tensors. Add
// support for other EValues and Tensor dtypes, and print tensors in a more
// readable way.
auto output_tensor = output.toTensor();
auto data_output = output_tensor.const_data_ptr<float>();

ssize_t max_print_element_count = 10000;
if (output_tensor.numel() > max_print_element_count) {
ET_LOG(
Info,
"Output tensor is too large, printing first %ld elements out of %ld",
max_print_element_count,
output_tensor.numel());
} else {
max_print_element_count = output_tensor.numel();
}

for (size_t j = 0; j < max_print_element_count; ++j) {
ET_LOG(Info, "%f", data_output[j]);
}
// Print the first and last 100 elements of long lists of scalars.
std::cout << torch::executor::util::evalue_edge_items(100);
for (int i = 0; i < outputs.size(); ++i) {
std::cout << "Output " << i << ": " << outputs[i] << std::endl;
}

// Dump the profiling data to the specified file.
Expand Down
1 change: 1 addition & 0 deletions examples/executor_runner/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def define_common_targets():
deps = [
"//executorch/runtime/executor:program",
"//executorch/extension/data_loader:file_data_loader",
"//executorch/extension/evalue_util:print_evalue",
"//executorch/util:util",
],
external_deps = [
Expand Down