-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Introduce memory manager statistics #3639
Conversation
Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your 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.
Reviewed 4 of 5 files at r1.
Reviewable status: 4 of 5 files reviewed, 2 unresolved discussions (waiting on @stotko)
cpp/open3d/core/MemoryManager.cpp, line 42 at r1 (raw file):
void* MemoryManager::Malloc(size_t byte_size, const Device& device) { MemoryManagerStatistic::getInstance().IncrementCountMalloc(device);
Shall we count byte_size as well? That might be helpful for more advanced checks.
cpp/open3d/core/MemoryManagerStatistic.cpp, line 36 at r1 (raw file):
namespace core { MemoryManagerStatistic& MemoryManagerStatistic::getInstance() {
Should we use GetInstance
to keep consistency?
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.
Reviewable status: 2 of 5 files reviewed, 2 unresolved discussions (waiting on @theNded)
cpp/open3d/core/MemoryManager.cpp, line 42 at r1 (raw file):
Previously, theNded (Wei Dong) wrote…
Shall we count byte_size as well? That might be helpful for more advanced checks.
Done.
cpp/open3d/core/MemoryManagerStatistic.cpp, line 36 at r1 (raw file):
Previously, theNded (Wei Dong) wrote…
Should we use
GetInstance
to keep consistency?
Done.
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.
Reviewed 3 of 3 files at r2.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @theNded)
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.
Reviewed 2 of 5 files at r1, 2 of 3 files at r2.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @stotko and @theNded)
cpp/open3d/core/MemoryManager.cpp, line 50 at r2 (raw file):
void MemoryManager::Free(void* ptr, const Device& device) { GetDeviceMemoryManager(device)->Free(ptr, device); MemoryManagerStatistic::GetInstance().IncrementCountFree(device, ptr);
nit: shall we change the order to be consistent with MemoryManager::Free(ptr, device)
?
i.e.
// We have:
MemoryManager::Free(ptr, device);
// Change IncrementCountFree to:
IncrementCountFree(ptr, device);
Similarly for IncrementCountMalloc
:
// We have:
MemoryManager::Malloc(byte_size, device);
// Change IncrementCountMalloc to:
IncrementCountMalloc(ptr, byte_size, device);
cpp/open3d/core/MemoryManagerStatistic.h, line 76 at r2 (raw file):
}; struct DeviceComparator {
This could be useful on other occasions if we'd like to use Device
as the key in a map/unordered_map.
Shall we consider moving this to the Device
class itself? For the unordered_map
version, this would look like:
class Device {
public:
struct Hash {
std::size_t operator()(const open3d::core::Device& device) const {
return std::hash<std::string>{}(device.ToString());
}
};
};
and, we can use the unordered_map
as:
static std::unordered_map<Device, MemoryStatistics, Device::Hash>;
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.
Reviewable status: 2 of 6 files reviewed, 3 unresolved discussions (waiting on @theNded and @yxlao)
cpp/open3d/core/MemoryManager.cpp, line 50 at r2 (raw file):
Previously, yxlao (Yixing Lao) wrote…
nit: shall we change the order to be consistent with
MemoryManager::Free(ptr, device)
?
i.e.// We have: MemoryManager::Free(ptr, device); // Change IncrementCountFree to: IncrementCountFree(ptr, device);Similarly for
IncrementCountMalloc
:// We have: MemoryManager::Malloc(byte_size, device); // Change IncrementCountMalloc to: IncrementCountMalloc(ptr, byte_size, device);
Done.
cpp/open3d/core/MemoryManagerStatistic.h, line 76 at r2 (raw file):
Previously, yxlao (Yixing Lao) wrote…
This could be useful on other occasions if we'd like to use
Device
as the key in a map/unordered_map.Shall we consider moving this to the
Device
class itself? For theunordered_map
version, this would look like:class Device { public: struct Hash { std::size_t operator()(const open3d::core::Device& device) const { return std::hash<std::string>{}(device.ToString()); } }; };and, we can use the
unordered_map
as:static std::unordered_map<Device, MemoryStatistics, Device::Hash>;
Done. FYI I used std::map<Device, MemoryStatistics>
to have a consistent ordering during Print()
.
Features:
MemoryManagerStatistic
instance implemented as a singletonDevice
logging of memory allocations and freesAll
,Unbalanced
,None
Unbalanced
to minimize noiseDetected memory leaks in unit tests:
Free
in LU decomposition when the operation failsThis change is