|
17 | 17 | * all fp32 tensors.
|
18 | 18 | */
|
19 | 19 |
|
| 20 | +#include <iostream> |
20 | 21 | #include <memory>
|
21 | 22 |
|
22 | 23 | #include <gflags/gflags.h>
|
23 | 24 |
|
24 | 25 | #include <executorch/extension/data_loader/file_data_loader.h>
|
| 26 | +#include <executorch/extension/evalue_util/print_evalue.h> |
25 | 27 | #include <executorch/runtime/executor/method.h>
|
26 | 28 | #include <executorch/runtime/executor/program.h>
|
27 | 29 | #include <executorch/runtime/platform/log.h>
|
@@ -169,29 +171,13 @@ int main(int argc, char** argv) {
|
169 | 171 |
|
170 | 172 | // Print the outputs.
|
171 | 173 | std::vector<EValue> outputs(method->outputs_size());
|
| 174 | + ET_LOG(Info, "%zu outputs: ", outputs.size()); |
172 | 175 | status = method->get_outputs(outputs.data(), outputs.size());
|
173 | 176 | ET_CHECK(status == Error::Ok);
|
174 |
| - for (EValue& output : outputs) { |
175 |
| - // TODO(T159700776): This assumes that all outputs are fp32 tensors. Add |
176 |
| - // support for other EValues and Tensor dtypes, and print tensors in a more |
177 |
| - // readable way. |
178 |
| - auto output_tensor = output.toTensor(); |
179 |
| - auto data_output = output_tensor.const_data_ptr<float>(); |
180 |
| - |
181 |
| - ssize_t max_print_element_count = 10000; |
182 |
| - if (output_tensor.numel() > max_print_element_count) { |
183 |
| - ET_LOG( |
184 |
| - Info, |
185 |
| - "Output tensor is too large, printing first %ld elements out of %ld", |
186 |
| - max_print_element_count, |
187 |
| - output_tensor.numel()); |
188 |
| - } else { |
189 |
| - max_print_element_count = output_tensor.numel(); |
190 |
| - } |
191 |
| - |
192 |
| - for (size_t j = 0; j < max_print_element_count; ++j) { |
193 |
| - ET_LOG(Info, "%f", data_output[j]); |
194 |
| - } |
| 177 | + // Print the first and last 100 elements of long lists of scalars. |
| 178 | + std::cout << torch::executor::util::evalue_edge_items(100); |
| 179 | + for (int i = 0; i < outputs.size(); ++i) { |
| 180 | + std::cout << "Output " << i << ": " << outputs[i] << std::endl; |
195 | 181 | }
|
196 | 182 |
|
197 | 183 | // Dump the profiling data to the specified file.
|
|
0 commit comments