-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
【Hackathon 7th No.21】为 Paddle 新增 reset_max_memory_reserved/reset_max_memory_allocated API -part #70032
Merged
Merged
【Hackathon 7th No.21】为 Paddle 新增 reset_max_memory_reserved/reset_max_memory_allocated API -part #70032
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e2299f9
added reset peak value initialization
Qin-sx dc30348
added comments
Qin-sx d081dde
added cpp tests
Qin-sx 35a12c8
added python tests
Qin-sx cb5036c
added a python test for reset_max_memory_allocated
Qin-sx 5d28856
formatted by pre-commit
Qin-sx f6b3d84
formatted by pre-commit (clang-format)
Qin-sx b6ea9be
added reset max memory reserved function
Qin-sx caad368
deleted memory stats and reset peak memory stats
Qin-sx 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
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
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 |
---|---|---|
|
@@ -32,15 +32,18 @@ class StatsTest : public ::testing::Test { | |
void SetFunc( | ||
std::function<void(const std::string, int, int64_t)> update_func, | ||
std::function<int64_t(const std::string, int)> current_value_func, | ||
std::function<int64_t(const std::string, int)> peak_value_func) { | ||
std::function<int64_t(const std::string, int)> peak_value_func, | ||
std::function<void(const std::string, int)> reset_peak_value_func) { | ||
update_func_ = update_func; | ||
current_value_func_ = current_value_func; | ||
peak_value_func_ = peak_value_func; | ||
reset_peak_value_func_ = reset_peak_value_func; | ||
} | ||
|
||
void RunTests() { | ||
MultiThreadReadWriteTest(); | ||
PeakValueTest(); | ||
ResetPeakValueTest(); | ||
} | ||
|
||
private: | ||
|
@@ -94,6 +97,18 @@ class StatsTest : public ::testing::Test { | |
EXPECT_EQ(peak_value_func_(stat_type_, 0), peak_value); | ||
} | ||
|
||
void ResetPeakValueTest() { | ||
for (int64_t data : datas_) { | ||
update_func_(stat_type_, 0, data); | ||
|
||
EXPECT_GE(peak_value_func_(stat_type_, 0), | ||
current_value_func_(stat_type_, 0)); | ||
reset_peak_value_func_(stat_type_, 0); | ||
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. 在这个测试中,这一步如果reset不成功,是不是后面的检查也是会通过的? 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. 如果reset不成功,下一行(107行)的检查应该无法通过。 void ResetPeakValueTest() {
for (int64_t data : datas_) {
update_func_(stat_type_, 0, data);
EXPECT_GE(peak_value_func_(stat_type_, 0),
current_value_func_(stat_type_, 0));
// reset_peak_value_func_(stat_type_, 0);
printf("data: %ld, Peak Value: %ld, Current Value: %ld\n",data, peak_value_func_(stat_type_, 0), current_value_func_(stat_type_, 0));
EXPECT_EQ(peak_value_func_(stat_type_, 0),
current_value_func_(stat_type_, 0));
}
} 如果将
|
||
EXPECT_EQ(peak_value_func_(stat_type_, 0), | ||
current_value_func_(stat_type_, 0)); | ||
} | ||
} | ||
|
||
std::string stat_type_; | ||
std::vector<int64_t> datas_{ | ||
543149808935355, 634698327471328, 706215795436611, 577939367795333, | ||
|
@@ -125,13 +140,15 @@ class StatsTest : public ::testing::Test { | |
std::function<void(const std::string, int, int64_t)> update_func_; | ||
std::function<int64_t(const std::string, int)> current_value_func_; | ||
std::function<int64_t(const std::string, int)> peak_value_func_; | ||
std::function<void(const std::string, int)> reset_peak_value_func_; | ||
}; | ||
|
||
TEST_F(StatsTest, DeviceAllocatedTest) { | ||
SetStatType("Allocated"); | ||
SetFunc(DeviceMemoryStatUpdate, | ||
DeviceMemoryStatCurrentValue, | ||
DeviceMemoryStatPeakValue); | ||
DeviceMemoryStatPeakValue, | ||
DeviceMemoryStatResetPeakValue); | ||
RunTests(); | ||
} | ||
|
||
|
@@ -146,6 +163,9 @@ TEST_F(StatsTest, DeviceReservedMacroTest) { | |
}, | ||
[](const std::string stat_type, int id) { | ||
return DEVICE_MEMORY_STAT_PEAK_VALUE(Reserved, id); | ||
}, | ||
[](const std::string stat_type, int id) { | ||
return DEVICE_MEMORY_STAT_RESET_PEAK_VALUE(Reserved, id); | ||
}); | ||
RunTests(); | ||
} | ||
|
@@ -161,6 +181,9 @@ TEST_F(StatsTest, HostAllocatedMacroTest) { | |
}, | ||
[](const std::string stat_type, int id) { | ||
return HOST_MEMORY_STAT_PEAK_VALUE(Allocated, id); | ||
}, | ||
[](const std::string stat_type, int id) { | ||
return HOST_MEMORY_STAT_RESET_PEAK_VALUE(Allocated, id); | ||
}); | ||
RunTests(); | ||
} | ||
|
@@ -169,7 +192,8 @@ TEST_F(StatsTest, HostReservedTest) { | |
SetStatType("Reserved"); | ||
SetFunc(HostMemoryStatUpdate, | ||
HostMemoryStatCurrentValue, | ||
HostMemoryStatPeakValue); | ||
HostMemoryStatPeakValue, | ||
HostMemoryStatResetPeakValue); | ||
RunTests(); | ||
} | ||
|
||
|
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.
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.
接口说明最好和max_memory_allocated保持一致。
Reset the peak size of GPU memory that is held by the allocator of the given device.
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.
嗯,收到