This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Fixing duplication in operator profiling #15240
Merged
sandeep-krishnamurthy
merged 9 commits into
apache:master
from
Zha0q1:profiler_aggregate_stats_duplication
Jun 21, 2019
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d3534bd
initial
Zha0q1 1cd9fbd
adding a bool in ProfileStat to control if add to aggregate stats
Zha0q1 65469b0
add test case
Zha0q1 48e888f
fix style
Zha0q1 5b23b47
stylefix
Zha0q1 60607e5
testcases
Zha0q1 34c6cc1
fix type
Zha0q1 5980b95
fix comment
Zha0q1 1167c8b
Update profiler.h
Zha0q1 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 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 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 |
---|---|---|
|
@@ -128,6 +128,9 @@ struct ProfileStat { | |
/*! \brief operation categories (comma-delimited) */ | ||
profile_stat_string categories_; | ||
|
||
/*! \brief whether to add this stat to AggregateStats */ | ||
bool enable_aggregate_ = true; | ||
|
||
/* !\brief Process id */ | ||
size_t process_id_ = current_process_id(); | ||
|
||
|
@@ -807,6 +810,13 @@ struct ProfileTask : public ProfileDuration { | |
|
||
ProfileObjectType type() const override { return kTask; } | ||
|
||
/*! | ||
* \brief Whether to add stat to AggregateStats | ||
*/ | ||
void enableAggregateStats(bool enabled) { | ||
enable_aggregate_ = enabled; | ||
} | ||
|
||
protected: | ||
/*! | ||
* \brief Task statistic object | ||
|
@@ -831,6 +841,7 @@ struct ProfileTask : public ProfileDuration { | |
inline void SendStat() { | ||
Profiler::Get()->AddNewProfileStat<ProfileTaskStat>([this](ProfileTaskStat *stat) { | ||
stat->categories_.set(domain_->name()); | ||
stat->enable_aggregate_ = enable_aggregate_; | ||
}, name_.c_str(), start_time_, ProfileStat::NowInMicrosec()); | ||
} | ||
/*! \brief Task name */ | ||
|
@@ -843,6 +854,8 @@ struct ProfileTask : public ProfileDuration { | |
VTUNE_ONLY_CODE(std::unique_ptr<vtune::VTuneTask> vtune_task_); | ||
/*! \brief NVTX duration object */ | ||
NVTX_ONLY_CODE(std::unique_ptr<nvtx::NVTXDuration> nvtx_duration_); | ||
/*! \brief not to add this stat to AggregateStats */ | ||
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. nit: 'not to add...' -> Add profiler stat to AggregateStats. 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. fixed |
||
bool enable_aggregate_ = true; | ||
|
||
protected: | ||
/*! \brief Task's start tick */ | ||
|
@@ -1150,6 +1163,8 @@ struct ProfileOperator : public ProfileEvent { | |
, as_task_(name, &domain_) | ||
, name_(name) | ||
, attributes_(attributes) { | ||
// make as_task_ not to add stat to AggregateStats; otherwise we will add twice | ||
as_task_.enableAggregateStats(false); | ||
SetCategories(domain_.name()); | ||
} | ||
/*! | ||
|
This file contains 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 |
---|---|---|
|
@@ -269,6 +269,28 @@ def check_sorting(debug_str, sort_by, ascending): | |
check_sorting(debug_str, sb, asc) | ||
profiler.set_state('stop') | ||
|
||
def test_aggregate_duplication(): | ||
file_name = 'test_aggregate_duplication.json' | ||
enable_profiler(profile_filename = file_name, run=True, continuous_dump=True, \ | ||
aggregate_stats=True) | ||
inp = mx.nd.zeros(shape=(100, 100)) | ||
y = mx.nd.sqrt(inp) | ||
inp = inp + 1 | ||
inp = inp + 1 | ||
mx.nd.waitall() | ||
profiler.dump(False) | ||
debug_str = profiler.dumps(format = 'json') | ||
target_dict = json.loads(debug_str) | ||
assert 'Time' in target_dict and 'operator' in target_dict['Time'] \ | ||
and 'sqrt' in target_dict['Time']['operator'] \ | ||
and 'Count' in target_dict['Time']['operator']['sqrt'] \ | ||
and '_plus_scalar' in target_dict['Time']['operator'] \ | ||
and 'Count' in target_dict['Time']['operator']['_plus_scalar'] | ||
# thet are called once and twice respectively | ||
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. typo: they ? 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. Fixed. Nice catch! |
||
assert target_dict['Time']['operator']['sqrt']['Count'] == 1 | ||
assert target_dict['Time']['operator']['_plus_scalar']['Count'] == 2 | ||
profiler.set_state('stop') | ||
|
||
if __name__ == '__main__': | ||
import nose | ||
nose.runmodule() |
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.
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.
In the all the places this is True. Except in VTune task case.
Can we make it default parameter with default value True?
So in only VTune Task case, we set it to False. In other places, we don't need to make changes.
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.
I can default enabled to true. enableAggregateStats() is a new function I added and the only place it is called is in line 1167 with enabled == false
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.
enable_aggregate_ has already been defaulted to true