Skip to content

Commit 7ed5774

Browse files
GasoonjiaDannyYuyang-quic
authored andcommitted
use datasink in example runner
Differential Revision: D70540227 Pull Request resolved: pytorch#8920
1 parent b81e7f2 commit 7ed5774

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

examples/devtools/example_runner/example_runner.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <gflags/gflags.h>
2525

2626
#include <executorch/devtools/bundled_program/bundled_program.h>
27+
#include <executorch/devtools/etdump/data_sinks/buffer_data_sink.h>
2728
#include <executorch/devtools/etdump/etdump_flatcc.h>
2829
#include <executorch/extension/data_loader/buffer_data_loader.h>
2930
#include <executorch/runtime/executor/method.h>
@@ -76,6 +77,7 @@ DEFINE_int32(
7677
262144, // 256 KB
7778
"Size of the debug buffer in bytes to allocate for intermediate outputs and program outputs logging.");
7879

80+
using executorch::etdump::BufferDataSink;
7981
using executorch::etdump::ETDumpGen;
8082
using executorch::etdump::ETDumpResult;
8183
using executorch::extension::BufferDataLoader;
@@ -216,27 +218,38 @@ int main(int argc, char** argv) {
216218
// be used by a single thread at at time, but it can be reused.
217219
//
218220
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.");
227221

222+
// Malloc debug buffer and create if and only if we need to log intermediate
223+
// tensor outputs
228224
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+
229234
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);
232235
etdump_gen.set_event_tracer_debug_level(
233236
EventTracerDebugLogLevel::kIntermediateOutputs);
237+
etdump_gen.set_data_sink(data_sink);
234238
} 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);
237239
etdump_gen.set_event_tracer_debug_level(
238240
EventTracerDebugLogLevel::kProgramOutputs);
241+
etdump_gen.set_data_sink(data_sink);
239242
}
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+
240253
// Use the inputs embedded in the bundled program.
241254
status = executorch::bundled_program::load_bundled_input(
242255
*method, file_data.data(), FLAGS_testset_idx);

0 commit comments

Comments
 (0)