-
Notifications
You must be signed in to change notification settings - Fork 699
support etdump generation in executorch.runtime #14205
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| import os | ||
| import tempfile | ||
| import unittest | ||
|
|
||
| import torch | ||
| from executorch.devtools.etdump.serialize import deserialize_from_etdump_flatcc | ||
|
|
||
| from executorch.extension.pybindings.test.make_test import create_program, ModuleAdd | ||
| from executorch.runtime import Runtime, Verification | ||
|
|
||
|
|
||
| class RuntimeETDumpGenTest(unittest.TestCase): | ||
| def test_etdump_generation(self): | ||
| """Test etdump generation by creating a program with etdump enabled and verifying the output.""" | ||
|
|
||
| ep, inputs = create_program(ModuleAdd()) | ||
| runtime = Runtime.get() | ||
|
|
||
| with tempfile.TemporaryDirectory() as temp_dir: | ||
| # Save the program to a file | ||
| program_path = os.path.join(temp_dir, "test_program.pte") | ||
| with open(program_path, "wb") as f: | ||
| f.write(ep.buffer) | ||
|
|
||
| # Load program with etdump generation enabled | ||
| program = runtime.load_program( | ||
| program_path, | ||
| verification=Verification.Minimal, | ||
| enable_etdump=True, | ||
| debug_buffer_size=int( | ||
| 1e7 | ||
| ), # Large buffer size to ensure all debug info is captured | ||
| ) | ||
|
|
||
| # Execute the method | ||
| method = program.load_method("forward") | ||
| outputs = method.execute(inputs) | ||
|
|
||
| # Verify the computation is correct | ||
| self.assertTrue(torch.allclose(outputs[0], inputs[0] + inputs[1])) | ||
|
|
||
| # Write etdump result to files | ||
| etdump_path = os.path.join(temp_dir, "etdump_output.etdp") | ||
| debug_path = os.path.join(temp_dir, "debug_output.bin") | ||
| program.write_etdump_result_to_file(etdump_path, debug_path) | ||
|
|
||
| # Check that files were created | ||
| self.assertTrue( | ||
| os.path.exists(etdump_path), f"ETDump file not created at {etdump_path}" | ||
| ) | ||
| self.assertTrue( | ||
| os.path.exists(debug_path), f"Debug file not created at {debug_path}" | ||
| ) | ||
|
|
||
| # Verify the etdump file is not empty | ||
| etdump_size = os.path.getsize(etdump_path) | ||
| self.assertGreater(etdump_size, 0, "ETDump file is empty") | ||
|
|
||
| # Read and deserialize the etdump file to verify its structure | ||
| with open(etdump_path, "rb") as f: | ||
| etdump_data = f.read() | ||
|
|
||
| # Deserialize the etdump and check its header/structure | ||
| etdump = deserialize_from_etdump_flatcc(etdump_data) | ||
|
|
||
| # Verify ETDump header properties | ||
| self.assertIsInstance( | ||
| etdump.version, int, "ETDump version should be an integer" | ||
| ) | ||
| self.assertGreaterEqual( | ||
| etdump.version, 0, "ETDump version should be non-negative" | ||
| ) | ||
|
|
||
| # Verify run_data structure | ||
| self.assertIsInstance( | ||
| etdump.run_data, list, "ETDump run_data should be a list" | ||
| ) | ||
| self.assertGreater( | ||
| len(etdump.run_data), | ||
| 0, | ||
| "ETDump should contain at least one run data entry", | ||
| ) | ||
|
|
||
| # Check the first run_data entry | ||
| run_data = etdump.run_data[0] | ||
| self.assertIsInstance( | ||
| run_data.events, list, "Run data should contain events list" | ||
| ) | ||
| self.assertGreater( | ||
| len(run_data.events), 0, "Run data should contain at least one events" | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of using to total size of the debugbuffer you can dig out the actual used size with something like
size_t outputdump_len = etdump_gen->get_data_sink()->get_used_bytes();
Then the file size can match the data, and also only be saved if actual data is put in the area.
I recently did this here #14143 for the arm ethos-u runner that you can look at for inspiration.