Skip to content

Microprofiler can now output logs for benchmarks in the csv format. #1290

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 7 commits into from
Aug 5, 2022

Conversation

tanmaydas82
Copy link
Contributor

BUG=240626703

@github-actions github-actions bot removed the ci:run label Jul 30, 2022
@tanmaydas82 tanmaydas82 marked this pull request as ready for review July 30, 2022 08:29
@tanmaydas82 tanmaydas82 requested a review from a team as a code owner July 30, 2022 08:29
@github-actions github-actions bot removed the ci:run label Jul 30, 2022
#endif
}

int MicroProfiler::FindExistingOrNextPosition(const char* tagName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we have some comments on what this function does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion Pauline! Adding a descriptive comment.

Copy link
Member

@advaitjain advaitjain left a comment

Choose a reason for hiding this comment

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

high level comment is that it might be worth implementing a generic Map class that is embedded friendly and then use that to perform the computation that we are doing to get to the total ticks per tag.

Comment on lines 64 to 65
// Prints the profiling information of each of the tags in CSV (Comma
// Separated Value) form.
Copy link
Member

Choose a reason for hiding this comment

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

We should expand this description.

Something like:

// Prints  total ticks for each unique tag in CSV format.
//
// Output will have one row for each unique tag along with the total ticks summed across all events with that particular tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks for the suggestion!

@@ -72,6 +76,14 @@ class MicroProfiler {
uint32_t end_ticks_[kMaxEvents];
int num_events_ = 0;

struct ticks_per_tag {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the link! Really helpful.

const char* tag;
uint32_t ticks;
};
ticks_per_tag total_ticks_per_tag[kMaxEvents];
Copy link
Member

Choose a reason for hiding this comment

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

add a comment that in practice the number of unique tags will be less than the number of events but it is theoretically possible for each event to be unique and hence we allow for the TicksPerTag array to have kMaxEvents entrires.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thank you for the suggestion!

};
ticks_per_tag total_ticks_per_tag[kMaxEvents];

int FindExistingOrNextPosition(const char* tagName);
Copy link
Member

Choose a reason for hiding this comment

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

nit: add a comment about what this function does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thank you for the suggestion!

};
ticks_per_tag total_ticks_per_tag[kMaxEvents];

int FindExistingOrNextPosition(const char* tagName);
Copy link
Member

Choose a reason for hiding this comment

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

tagName -> tag_name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thank you for the suggestion!

void MicroProfiler::LogTicksPerTagCsv() {
#if !defined(TF_LITE_STRIP_ERROR_STRINGS)
MicroPrintf(
"\"Unique Ops in the Graph\",\"Total Ticks (all instances of the Op)\"");
Copy link
Member

Choose a reason for hiding this comment

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

nit: technically may not be Ops. It could be any event that we profile with the MicroProfiler.

Unique Tag, Total ticks across all events with that tag.

#if !defined(TF_LITE_STRIP_ERROR_STRINGS)
MicroPrintf(
"\"Unique Ops in the Graph\",\"Total Ticks (all instances of the Op)\"");
int totalTicks = 0;
Copy link
Member

Choose a reason for hiding this comment

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

total_ticks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thank you for the suggestion!

}
MicroPrintf("%s,%d", ticksPerTag.tag, ticksPerTag.ticks);
}
MicroPrintf("total,%d", totalTicks);
Copy link
Member

Choose a reason for hiding this comment

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

this seems to not strictly be a part of the csv format. I would say skip from the current function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. I was thinking to print the total count as well as I have seen that this is required for the calculation but if you think that is not required, I can remove it. I can probably change it to "total number of ticks" or something like that to make it more meaningful.

#endif
}

/**
Copy link
Member

Choose a reason for hiding this comment

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

super nit: let's use // for the comment style for consistency.

https://google.github.io/styleguide/cppguide.html#Comment_Style

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion.

Comment on lines 110 to 111
const char* currentTagName_t = each_tag_entry.tag;
const char* newTagName_t = tag_name;
Copy link
Member

Choose a reason for hiding this comment

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

current_tag_name
new_tag_name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 112 to 120
bool matched = true;
while ((*currentTagName_t != '\0') && (*newTagName_t != '\0')) {
if (((*currentTagName_t) == (*newTagName_t))) {
++currentTagName_t;
++newTagName_t;
} else {
matched = false;
break;
}
Copy link
Member

Choose a reason for hiding this comment

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

Let's use strcmp instead of this custom loop.

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 was not aware of if strcmp is available in tflm Thank you for the suggestion.

// hence we allow total_ticks_per_tag to have kMaxEvents entries.
TicksPerTag total_ticks_per_tag[kMaxEvents];

int FindExistingOrNextPosition(const char* tagName);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Missed the header file last time.

Comment on lines 78 to 81
if (tags_[i] == nullptr) {
MicroPrintf("Event does not have a tag name.");
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

can this happen? seems like this should be a DCHECK and not an error that we want to print and continue on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a DCHECK. Thank you for the suggestion.

Comment on lines 83 to 86
if (position == -1) {
MicroPrintf("Number of tags exceeds the memory allocation.");
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

again, this should not happen, right? We explicitly se the total number of unique tags to be equal to the total number of permitted events.

DCHECK seems more appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. I was probably overthinking. Added DCHECK.

@TFLM-bot TFLM-bot added the ci:run label Aug 5, 2022
@github-actions github-actions bot removed the ci:run label Aug 5, 2022
@TFLM-bot TFLM-bot added the ci:run label Aug 5, 2022
@github-actions github-actions bot removed the ci:run label Aug 5, 2022
@TFLM-bot TFLM-bot added the ci:run label Aug 5, 2022
@github-actions github-actions bot removed the ci:run label Aug 5, 2022
@mergify mergify bot merged commit 4a8320a into tensorflow:main Aug 5, 2022
@tanmaydas82 tanmaydas82 deleted the csv-logger branch November 16, 2022 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants