diff --git a/include/mqt-core/dd/statistics/MemoryManagerStatistics.hpp b/include/mqt-core/dd/statistics/MemoryManagerStatistics.hpp index 6222f81a0..e95de140b 100644 --- a/include/mqt-core/dd/statistics/MemoryManagerStatistics.hpp +++ b/include/mqt-core/dd/statistics/MemoryManagerStatistics.hpp @@ -12,7 +12,9 @@ #include "dd/statistics/Statistics.hpp" #include "nlohmann/json_fwd.hpp" +#include #include +#include namespace dd { @@ -73,4 +75,91 @@ template struct MemoryManagerStatistics : public Statistics { [[nodiscard]] nlohmann::json json() const override; }; +///----------------------------------------------------------------------------- +/// \n Method Definitions \n +///----------------------------------------------------------------------------- + +template +std::size_t +MemoryManagerStatistics::getNumAvailableFromChunks() const noexcept { + return getTotalNumAvailable() - numAvailableForReuse; +} + +template +std::size_t MemoryManagerStatistics::getTotalNumAvailable() const noexcept { + return numAllocated - numUsed; +} + +template +double MemoryManagerStatistics::getUsageRatio() const noexcept { + return static_cast(numUsed) / static_cast(numAllocated); +} + +template +double MemoryManagerStatistics::getAllocatedMemoryMiB() const noexcept { + return static_cast(numAllocated) * ENTRY_MEMORY_MIB; +} + +template +double MemoryManagerStatistics::getUsedMemoryMiB() const noexcept { + return static_cast(numUsed) * ENTRY_MEMORY_MIB; +} + +template +double MemoryManagerStatistics::getPeakUsedMemoryMiB() const noexcept { + return static_cast(peakNumUsed) * ENTRY_MEMORY_MIB; +} + +template +void MemoryManagerStatistics::trackUsedEntries( + const std::size_t numEntries) noexcept { + numUsed += numEntries; + peakNumUsed = std::max(peakNumUsed, numUsed); +} + +template +void MemoryManagerStatistics::trackReusedEntries( + const std::size_t numEntries) noexcept { + numUsed += numEntries; + peakNumUsed = std::max(peakNumUsed, numUsed); + numAvailableForReuse -= numEntries; +} + +template +void MemoryManagerStatistics::trackReturnedEntry() noexcept { + ++numAvailableForReuse; + peakNumAvailableForReuse = + std::max(peakNumAvailableForReuse, numAvailableForReuse); + --numUsed; +} + +template void MemoryManagerStatistics::reset() noexcept { + numAllocations = 0U; + numAllocated = 0U; + numUsed = 0U; + numAvailableForReuse = 0U; +} + +template +nlohmann::basic_json<> MemoryManagerStatistics::json() const { + if (peakNumUsed == 0) { + return "unused"; + } + + auto j = Statistics::json(); + j["memory_allocated_MiB"] = getAllocatedMemoryMiB(); + j["memory_used_MiB"] = getUsedMemoryMiB(); + j["memory_used_MiB_peak"] = getPeakUsedMemoryMiB(); + j["num_allocated"] = numAllocated; + j["num_allocations"] = numAllocations; + j["num_available_for_reuse"] = numAvailableForReuse; + j["num_available_for_reuse_peak"] = peakNumAvailableForReuse; + j["num_available_from_chunks"] = getNumAvailableFromChunks(); + j["num_available_total"] = getTotalNumAvailable(); + j["num_used"] = numUsed; + j["num_used_peak"] = peakNumUsed; + j["usage_ratio"] = getUsageRatio(); + return j; +} + } // namespace dd diff --git a/src/dd/statistics/MemoryManagerStatistics.cpp b/src/dd/statistics/MemoryManagerStatistics.cpp deleted file mode 100644 index 2e1446688..000000000 --- a/src/dd/statistics/MemoryManagerStatistics.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2025 Chair for Design Automation, TUM - * All rights reserved. - * - * SPDX-License-Identifier: MIT - * - * Licensed under the MIT License - */ - -#include "dd/statistics/MemoryManagerStatistics.hpp" - -#include "dd/Node.hpp" -#include "dd/RealNumber.hpp" -#include "dd/statistics/Statistics.hpp" - -#include -#include -#include - -namespace dd { - -template -std::size_t -MemoryManagerStatistics::getNumAvailableFromChunks() const noexcept { - return getTotalNumAvailable() - numAvailableForReuse; -} - -template -std::size_t MemoryManagerStatistics::getTotalNumAvailable() const noexcept { - return numAllocated - numUsed; -} - -template -double MemoryManagerStatistics::getUsageRatio() const noexcept { - return static_cast(numUsed) / static_cast(numAllocated); -} - -template -double MemoryManagerStatistics::getAllocatedMemoryMiB() const noexcept { - return static_cast(numAllocated) * ENTRY_MEMORY_MIB; -} - -template -double MemoryManagerStatistics::getUsedMemoryMiB() const noexcept { - return static_cast(numUsed) * ENTRY_MEMORY_MIB; -} - -template -double MemoryManagerStatistics::getPeakUsedMemoryMiB() const noexcept { - return static_cast(peakNumUsed) * ENTRY_MEMORY_MIB; -} - -template -void MemoryManagerStatistics::trackUsedEntries( - const std::size_t numEntries) noexcept { - numUsed += numEntries; - peakNumUsed = std::max(peakNumUsed, numUsed); -} - -template -void MemoryManagerStatistics::trackReusedEntries( - const std::size_t numEntries) noexcept { - numUsed += numEntries; - peakNumUsed = std::max(peakNumUsed, numUsed); - numAvailableForReuse -= numEntries; -} - -template -void MemoryManagerStatistics::trackReturnedEntry() noexcept { - ++numAvailableForReuse; - peakNumAvailableForReuse = - std::max(peakNumAvailableForReuse, numAvailableForReuse); - --numUsed; -} - -template void MemoryManagerStatistics::reset() noexcept { - numAllocations = 0U; - numAllocated = 0U; - numUsed = 0U; - numAvailableForReuse = 0U; -} - -template -nlohmann::basic_json<> MemoryManagerStatistics::json() const { - if (peakNumUsed == 0) { - return "unused"; - } - - auto j = Statistics::json(); - j["memory_allocated_MiB"] = getAllocatedMemoryMiB(); - j["memory_used_MiB"] = getUsedMemoryMiB(); - j["memory_used_MiB_peak"] = getPeakUsedMemoryMiB(); - j["num_allocated"] = numAllocated; - j["num_allocations"] = numAllocations; - j["num_available_for_reuse"] = numAvailableForReuse; - j["num_available_for_reuse_peak"] = peakNumAvailableForReuse; - j["num_available_from_chunks"] = getNumAvailableFromChunks(); - j["num_available_total"] = getTotalNumAvailable(); - j["num_used"] = numUsed; - j["num_used_peak"] = peakNumUsed; - j["usage_ratio"] = getUsageRatio(); - return j; -} - -template struct MemoryManagerStatistics; -template struct MemoryManagerStatistics; -template struct MemoryManagerStatistics; -template struct MemoryManagerStatistics; -} // namespace dd