Skip to content
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

etdumpfilter impl #9752

Merged
merged 1 commit into from
Apr 4, 2025
Merged

Conversation

Gasoonjia
Copy link
Contributor

Differential Revision: D72025517

Copy link

pytorch-bot bot commented Mar 28, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/9752

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit b8f8988 with merge base d6e14fc (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 28, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D72025517

@Gasoonjia
Copy link
Contributor Author

@pytorchbot label "topic: not user facing"

Gasoonjia added a commit to Gasoonjia/executorch-1 that referenced this pull request Mar 29, 2025
Summary:


Introduce ETDumpFilter for filtering logged delegation intermediate data. 
Details can be found in pytorch#9260

Differential Revision: D72025517
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D72025517

Gasoonjia added a commit to Gasoonjia/executorch-1 that referenced this pull request Mar 29, 2025
Summary:
Pull Request resolved: pytorch#9752

Introduce ETDumpFilter for filtering logged delegation intermediate data.
Details can be found in pytorch#9260

Differential Revision: D72025517
Gasoonjia added a commit to Gasoonjia/executorch-1 that referenced this pull request Apr 2, 2025
Summary:


Introduce ETDumpFilter for filtering logged delegation intermediate data. 
Details can be found in pytorch#9260

Differential Revision: D72025517
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D72025517

Gasoonjia added a commit to Gasoonjia/executorch-1 that referenced this pull request Apr 2, 2025
Summary:
Pull Request resolved: pytorch#9752

Introduce ETDumpFilter for filtering logged delegation intermediate data.
Details can be found in pytorch#9260

Differential Revision: D72025517
Copy link
Contributor

@swolchok swolchok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some C++ comments; leaving for reviewers with more context on the actual goals here

namespace executorch {
namespace etdump {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have C++17 -- namespace executorch::etdump {

Comment on lines 98 to 100
size_t regex_count_;
size_t range_start_;
size_t range_end_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you don't need the explicit default constructor if you assign 0 to these here; you can then change the constructor implementation in the .cpp file to ETDumpFilter::ETDumpFilter() = default;

if (len >= MAX_PATTERN_LENGTH) {
return Error::InvalidArgument; // Pattern too long
}
strcpy(regex_patterns_[regex_count_], pattern);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you already have the length, so use it -- std::memcpy(regex_patterns_[regex_count_], pattern, len)

return Error::InvalidArgument; // Pattern too long
}
strcpy(regex_patterns_[regex_count_], pattern);
regex_patterns_[regex_count_][len] = '\0';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI strcpy already does this. however, if you take my memcpy advice above you'll need to leave it

return true;
}

Result<bool> ETDumpFilter::set_debug_handle_range(size_t start, size_t end) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does a successful result of false mean? (does Result<void> work?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false will not be use.
We can not use Result<void> cuz Result class need to use reference for the T type and void does not have Reference.


Result<bool> ETDumpFilter::filter_name_(const char* name) {
if (name == nullptr) {
return Error::InvalidArgument; // Name is null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment repeats the code, delete

size_t get_n_regex() const;

private:
char regex_patterns_[MAX_REGEX_PATTERNS][MAX_PATTERN_LENGTH]{};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the hardcoded limit on length instead of a std::vector<std::string>? I don't see any particular guarantees from RE2 itself that it doesn't malloc, so isn't studiously avoiding malloc in our wrapper a lost cause?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to use any memory allocation operation in etdump_filter; our user usually have their own memory allocation way and does not support anything like vector or malloc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not support anything like vector or malloc

but that's my point -- RE2 mallocs! (for example https://github.com/google/re2/blob/main/re2/compile.cc#L1254)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh fair point didn't pay attention to RE internal impl

* - An error code if number of pattern has reached to cap, or any
* error occurs during regex compilation.
*/
Result<bool> add_regex(const char* pattern);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string_view is in C++17. why not use it instead? (if the user ever passes a literal, we won't need to check its length at runtime)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx didn't know we have that; migrating to that.

Gasoonjia added a commit to Gasoonjia/executorch-1 that referenced this pull request Apr 2, 2025
Summary:


Introduce ETDumpFilter for filtering logged delegation intermediate data. 
Details can be found in pytorch#9260

Differential Revision: D72025517
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D72025517

@@ -0,0 +1,100 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall high level comment, i think it's reasonable that we can assume the etdump filter we provide based on regex will need malloc to be supported. If users want to use this malloc support will be required on their platform. Based on this i think it would be good to remove the limitations we have in this class such as max regex, max char len etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If users do need a filter for their platform that isn't based on regex they can write their own one. (which will be only very few embedded users).

Copy link
Contributor Author

@Gasoonjia Gasoonjia Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which will be only very few embedded users

ok in this case i agree we can make our etdump_filter support regex + malloc, just as what swolchok mentioned RE use malloc internally. Let me make an update

Gasoonjia added a commit to Gasoonjia/executorch-1 that referenced this pull request Apr 3, 2025
Summary:


Introduce ETDumpFilter for filtering logged delegation intermediate data. 
Details can be found in pytorch#9260

Differential Revision: D72025517
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D72025517

Gasoonjia added a commit to Gasoonjia/executorch-1 that referenced this pull request Apr 4, 2025
Summary:


Introduce ETDumpFilter for filtering logged delegation intermediate data. 
Details can be found in pytorch#9260

Reviewed By: tarun292

Differential Revision: D72025517
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D72025517

Gasoonjia added a commit to Gasoonjia/executorch-1 that referenced this pull request Apr 4, 2025
Summary:


Introduce ETDumpFilter for filtering logged delegation intermediate data. 
Details can be found in pytorch#9260

Reviewed By: tarun292

Differential Revision: D72025517
Summary:
Pull Request resolved: pytorch#9752

Introduce ETDumpFilter for filtering logged delegation intermediate data.
Details can be found in pytorch#9260

Reviewed By: tarun292

Differential Revision: D72025517
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D72025517

@facebook-github-bot facebook-github-bot merged commit 56c8dc2 into pytorch:main Apr 4, 2025
82 of 84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported topic: not user facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants