|
24 | 24 | #include <gflags/gflags.h>
|
25 | 25 |
|
26 | 26 | #include <executorch/devtools/bundled_program/bundled_program.h>
|
| 27 | +#include <executorch/devtools/etdump/data_sinks/buffer_data_sink.h> |
27 | 28 | #include <executorch/devtools/etdump/etdump_flatcc.h>
|
28 | 29 | #include <executorch/extension/data_loader/buffer_data_loader.h>
|
29 | 30 | #include <executorch/runtime/executor/method.h>
|
@@ -76,6 +77,7 @@ DEFINE_int32(
|
76 | 77 | 262144, // 256 KB
|
77 | 78 | "Size of the debug buffer in bytes to allocate for intermediate outputs and program outputs logging.");
|
78 | 79 |
|
| 80 | +using executorch::etdump::BufferDataSink; |
79 | 81 | using executorch::etdump::ETDumpGen;
|
80 | 82 | using executorch::etdump::ETDumpResult;
|
81 | 83 | using executorch::extension::BufferDataLoader;
|
@@ -216,27 +218,38 @@ int main(int argc, char** argv) {
|
216 | 218 | // be used by a single thread at at time, but it can be reused.
|
217 | 219 | //
|
218 | 220 | ETDumpGen etdump_gen;
|
219 |
| - Result<Method> method = |
220 |
| - program->load_method(method_name, &memory_manager, &etdump_gen); |
221 |
| - ET_CHECK_MSG( |
222 |
| - method.ok(), |
223 |
| - "Loading of method %s failed with status 0x%" PRIx32, |
224 |
| - method_name, |
225 |
| - static_cast<int>(method.error())); |
226 |
| - ET_LOG(Info, "Method loaded."); |
227 | 221 |
|
| 222 | + // Malloc debug buffer and create if and only if we need to log intermediate |
| 223 | + // tensor outputs |
228 | 224 | void* debug_buffer = malloc(FLAGS_debug_buffer_size);
|
| 225 | + Result<BufferDataSink> data_sink_ret = |
| 226 | + BufferDataSink::create(debug_buffer, FLAGS_debug_buffer_size); |
| 227 | + ET_CHECK_MSG( |
| 228 | + data_sink_ret.ok(), |
| 229 | + "Creating Datasink for etdump failed with status 0x%" PRIx32, |
| 230 | + static_cast<int>(data_sink_ret.error())); |
| 231 | + |
| 232 | + BufferDataSink* data_sink = &data_sink_ret.get(); |
| 233 | + |
229 | 234 | if (FLAGS_dump_intermediate_outputs) {
|
230 |
| - Span<uint8_t> buffer((uint8_t*)debug_buffer, FLAGS_debug_buffer_size); |
231 |
| - etdump_gen.set_debug_buffer(buffer); |
232 | 235 | etdump_gen.set_event_tracer_debug_level(
|
233 | 236 | EventTracerDebugLogLevel::kIntermediateOutputs);
|
| 237 | + etdump_gen.set_data_sink(data_sink); |
234 | 238 | } else if (FLAGS_dump_outputs) {
|
235 |
| - Span<uint8_t> buffer((uint8_t*)debug_buffer, FLAGS_debug_buffer_size); |
236 |
| - etdump_gen.set_debug_buffer(buffer); |
237 | 239 | etdump_gen.set_event_tracer_debug_level(
|
238 | 240 | EventTracerDebugLogLevel::kProgramOutputs);
|
| 241 | + etdump_gen.set_data_sink(data_sink); |
239 | 242 | }
|
| 243 | + |
| 244 | + Result<Method> method = |
| 245 | + program->load_method(method_name, &memory_manager, &etdump_gen); |
| 246 | + ET_CHECK_MSG( |
| 247 | + method.ok(), |
| 248 | + "Loading of method %s failed with status 0x%" PRIx32, |
| 249 | + method_name, |
| 250 | + static_cast<int>(method.error())); |
| 251 | + ET_LOG(Info, "Method loaded."); |
| 252 | + |
240 | 253 | // Use the inputs embedded in the bundled program.
|
241 | 254 | status = executorch::bundled_program::load_bundled_input(
|
242 | 255 | *method, file_data.data(), FLAGS_testset_idx);
|
|
0 commit comments