-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add event tracing and ETDumps to executor_runner #5027
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
Changes from 7 commits
b09d09e
cbcbbe7
4db02c9
bf27add
a2c254c
3f23fae
e692a76
1d9d0c0
f3493e4
1a9721f
da448ce
b36d5b4
fde5862
931ddf4
b080c76
88f0e91
42a8b9c
34b6b3e
07d1c26
c886ad2
d9f3269
662cb81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * Copyright 2024 Arm Limited and/or its affiliates. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
|
|
@@ -25,21 +26,33 @@ | |
| #include <executorch/extension/data_loader/file_data_loader.h> | ||
| #include <executorch/extension/evalue_util/print_evalue.h> | ||
| #include <executorch/extension/runner_util/inputs.h> | ||
| #include <executorch/runtime/core/event_tracer.h> | ||
| #include <executorch/runtime/executor/method.h> | ||
| #include <executorch/runtime/executor/program.h> | ||
| #include <executorch/runtime/platform/log.h> | ||
| #include <executorch/runtime/platform/runtime.h> | ||
| #ifdef ET_EVENT_TRACER_ENABLED | ||
| #include <executorch/devtools/etdump/etdump_flatcc.h> | ||
| #endif // ET_EVENT_TRACER_ENABLED | ||
|
|
||
| static uint8_t method_allocator_pool[4 * 1024U * 1024U]; // 4 MB | ||
|
|
||
| DEFINE_string( | ||
| model_path, | ||
| "model.pte", | ||
| "Model serialized in flatbuffer format."); | ||
| DEFINE_uint32(num_executions, 1, "Number of times to run the model."); | ||
| #ifdef ET_EVENT_TRACER_ENABLED | ||
| DEFINE_string( | ||
| etdump_path, | ||
| "model.etdump", | ||
| "If ETDump generation is enabled an ETDump will be written out to this path."); | ||
|
benkli01 marked this conversation as resolved.
Outdated
|
||
| #endif // ET_EVENT_TRACER_ENABLED | ||
|
|
||
| using executorch::extension::FileDataLoader; | ||
| using executorch::runtime::Error; | ||
| using executorch::runtime::EValue; | ||
| using executorch::runtime::EventTracer; | ||
| using executorch::runtime::HierarchicalAllocator; | ||
| using executorch::runtime::MemoryAllocator; | ||
| using executorch::runtime::MemoryManager; | ||
|
|
@@ -151,8 +164,20 @@ int main(int argc, char** argv) { | |
| // the method can mutate the memory-planned buffers, so the method should only | ||
| // be used by a single thread at at time, but it can be reused. | ||
| // | ||
|
|
||
| Result<Method> method = program->load_method(method_name, &memory_manager); | ||
| EventTracer* event_tracer_ptr = nullptr; | ||
| #ifdef ET_EVENT_TRACER_ENABLED | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is already so long and complex, I'd like to factor out these ifdefs if possible. You could create a class to encapsulate the event tracing, like If tracing is enabled, the ctor could create the ETDump (a field), get_event_tracer can return a pointer to it, and write_to_file can open the file and write the contents. If tracing is disabled, the class is basically empty, returning a null tracer and just returning Error::NotSupported when asked to write. Then main() can say
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. Let me know if the implementation looks ok. |
||
| std::unique_ptr<FILE, decltype(&fclose)> etdump_file( | ||
| fopen(FLAGS_etdump_path.c_str(), "w+"), fclose); | ||
| ET_CHECK_MSG( | ||
| etdump_file, | ||
| "Failed to open ETDump file at %s.", | ||
| FLAGS_etdump_path.c_str()); | ||
|
benkli01 marked this conversation as resolved.
Outdated
|
||
|
|
||
| torch::executor::ETDumpGen etdump_gen = torch::executor::ETDumpGen(); | ||
| event_tracer_ptr = &etdump_gen; | ||
| #endif // ET_EVENT_TRACER_ENABLED | ||
| Result<Method> method = | ||
| program->load_method(method_name, &memory_manager, event_tracer_ptr); | ||
| ET_CHECK_MSG( | ||
| method.ok(), | ||
| "Loading of method %s failed with status 0x%" PRIx32, | ||
|
|
@@ -171,24 +196,39 @@ int main(int argc, char** argv) { | |
| ET_LOG(Info, "Inputs prepared."); | ||
|
|
||
| // Run the model. | ||
| Error status = method->execute(); | ||
| ET_CHECK_MSG( | ||
| status == Error::Ok, | ||
| "Execution of method %s failed with status 0x%" PRIx32, | ||
| method_name, | ||
| (uint32_t)status); | ||
| ET_LOG(Info, "Model executed successfully."); | ||
| for (uint32_t i = 0; i < FLAGS_num_executions; i++) { | ||
| Error status = method->execute(); | ||
| ET_CHECK_MSG( | ||
| status == Error::Ok, | ||
| "Execution of method %s failed with status 0x%" PRIx32, | ||
| method_name, | ||
| (uint32_t)status); | ||
| } | ||
| ET_LOG(Info, "Model executed successfully %i time(s).", FLAGS_num_executions); | ||
|
benkli01 marked this conversation as resolved.
Outdated
|
||
|
|
||
| // 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()); | ||
| Error status = method->get_outputs(outputs.data(), outputs.size()); | ||
| ET_CHECK(status == Error::Ok); | ||
| // Print the first and last 100 elements of long lists of scalars. | ||
| std::cout << executorch::extension::evalue_edge_items(100); | ||
| for (int i = 0; i < outputs.size(); ++i) { | ||
| std::cout << "Output " << i << ": " << outputs[i] << std::endl; | ||
| } | ||
|
|
||
| #ifdef ET_EVENT_TRACER_ENABLED | ||
| // Dump the ETDump data containing profiling/debugging data to the specified | ||
| // file. | ||
| torch::executor::etdump_result result = etdump_gen.get_etdump_data(); | ||
| if (result.buf != nullptr && result.size > 0) { | ||
| fwrite((uint8_t*)result.buf, 1, result.size, etdump_file.get()); | ||
| free(result.buf); | ||
| ET_LOG(Info, "ETDump written to file '%s'.", FLAGS_etdump_path.c_str()); | ||
| } else { | ||
| ET_LOG(Error, "No ETDump data available!"); | ||
| } | ||
| #endif // ET_EVENT_TRACER_ENABLED | ||
|
|
||
| return 0; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.