From 61e9bf2abb6c60fd91bd124f48a93eb927fd2ae7 Mon Sep 17 00:00:00 2001 From: cmoineau <cyril.moineau@cea.fr> Date: Thu, 2 Jan 2025 09:35:42 +0000 Subject: [PATCH] Remove MemoryManager.log() method. --- .../scheduler/pybind_MemoryManager.cpp | 5 +- src/scheduler/MemoryManager.cpp | 146 ------------------ 2 files changed, 2 insertions(+), 149 deletions(-) diff --git a/python_binding/scheduler/pybind_MemoryManager.cpp b/python_binding/scheduler/pybind_MemoryManager.cpp index 0f18db405..3fce92349 100644 --- a/python_binding/scheduler/pybind_MemoryManager.cpp +++ b/python_binding/scheduler/pybind_MemoryManager.cpp @@ -36,10 +36,10 @@ void init_MemoryManager(py::module& m) .def_readwrite("released", &MemoryManager::MemorySpace::released); py::class_<MemoryManager::MemoryPlane, std::shared_ptr<MemoryManager::MemoryPlane>>(m, "MemoryPlane") - .def(py::init<std::shared_ptr<MemoryManager::MemorySpace>, + .def(py::init<std::shared_ptr<MemoryManager::MemorySpace>, MemoryManager::Clock_T, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int>(), - py::arg("mem_space"), py::arg("clock"), py::arg("offset"), + py::arg("mem_space"), py::arg("clock"), py::arg("offset"), py::arg("size"), py::arg("stride"), py::arg("length"), py::arg("count")) .def_readwrite("mem_space", &MemoryManager::MemoryPlane::memSpace) .def_readwrite("allocated", &MemoryManager::MemoryPlane::allocated) @@ -101,7 +101,6 @@ void init_MemoryManager(py::module& m) .def("get_nb_planes", (unsigned int (MemoryManager::*)(std::shared_ptr<MemoryManager::MemorySpace>) const) &MemoryManager::getNbPlanes, py::arg("mem_space")) .def("get_current_tick", &MemoryManager::getCurrentTick) .def("tick", &MemoryManager::tick) - .def("log", &MemoryManager::log, py::arg("file_name")) ; } diff --git a/src/scheduler/MemoryManager.cpp b/src/scheduler/MemoryManager.cpp index ba805f919..05f461b82 100644 --- a/src/scheduler/MemoryManager.cpp +++ b/src/scheduler/MemoryManager.cpp @@ -634,152 +634,6 @@ void Aidge::MemoryManager::tick() ++mClock; } -void Aidge::MemoryManager::log(const std::string& fileName) const -{ - auto memData = std::unique_ptr<FILE, decltype(&std::fclose)>(std::fopen(fileName.c_str(), "w"), &std::fclose); - - if (!memData) { - AIDGE_THROW_OR_ABORT(std::runtime_error, - "Could not create memory layout log file: {}", fileName); - } - - auto gnuplot = std::unique_ptr<FILE, decltype(&std::fclose)>(std::fopen((fileName + "_plot.gnu").c_str(), "w"), &std::fclose); - - if (!gnuplot) { - AIDGE_THROW_OR_ABORT(std::runtime_error, - "Could not create memory layout log file: {}", (fileName + "_plot.gnu")); - } - - const Clock_T maxLifetime = getMaxLifetime(); - const unsigned int peakUsage = getPeakUsage(); - - fmt::print(gnuplot.get(), "#!/usr/bin/gnuplot\n"); - fmt::print(gnuplot.get(), "set term pngcairo size 1280,768 noenhanced\n"); - fmt::print(gnuplot.get(), "set output \"{}\"\n", fileName + "_plot.png"); - fmt::print(gnuplot.get(), "set xrange [{}:{}]\n", 0, maxLifetime + 1); - fmt::print(gnuplot.get(), "set yrange [{}:{}]\n", 0, 1.05 * (peakUsage / 1024.0)); - fmt::print(gnuplot.get(), "set xlabel \"Time\"\n"); - fmt::print(gnuplot.get(), "set ylabel \"Memory usage (KWords)\"\n"); - fmt::print(gnuplot.get(), "set grid\n"); - fmt::print(gnuplot.get(), "set xtics 1\n"); - fmt::print(gnuplot.get(), "unset key\n"); - fmt::print(gnuplot.get(), "set palette rgbformulae 30,31,32\n"); - fmt::print(gnuplot.get(), "unset colorbox\n"); - fmt::print(gnuplot.get(), "N={}\n", mMemPlanes.size() + 1); - - unsigned int objectId = 1; - unsigned int labelId = 1; - - for (std::map<std::shared_ptr<Node>, std::vector<MemoryPlane> > - ::const_iterator it = mMemPlanes.begin(), itEnd = mMemPlanes.end(); - it != itEnd; ++it) - { - const std::string name = (*it).first->name(); - fmt::print(memData.get(), "{}\n", name); - - double minX = -1; - unsigned int maxY = 0; - - for (std::vector<MemoryPlane>::const_iterator itPlanes - = (*it).second.begin(), itPlanesBegin = (*it).second.begin(), - itPlanesEnd = (*it).second.end(); itPlanes != itPlanesEnd; - ++itPlanes) - { - const unsigned int contiguousOffset - = (*itPlanes).getContiguousOffset(); - const unsigned int contiguousSize = (*itPlanes).getContiguousSize(); - const unsigned int wrappedOffset = (*itPlanes).getWrappedOffset(); - const unsigned int wrappedSize = (*itPlanes).getWrappedSize(); - - const Clock_T allocated = (*itPlanes).allocated; - const Clock_T released = (*itPlanes).memSpace->released; - const bool isReleased = (released >= 0 - && (*itPlanes).memSpace->dependencies.empty()); - - fmt::print(memData.get(), " {} {} ({:#08x}U) -> {} ({:#08x}U)", - (itPlanes - itPlanesBegin), contiguousOffset, contiguousOffset, - (contiguousOffset + contiguousSize), (contiguousOffset + contiguousSize)); - - if (wrappedSize > 0) { - fmt::print(memData.get(), " + {} ({:#08x}U) -> {} ({:#08x}U)", - wrappedOffset, wrappedOffset, - (wrappedOffset + wrappedSize), (wrappedOffset + wrappedSize)); - } - - fmt::print(memData.get(), " [{}] @ {}", (*itPlanes).getSize(), allocated); - - if (isReleased) { - fmt::print(memData.get(), " to {}", released); - } - - fmt::print(memData.get(), "\n"); - - // Gnuplot - const double startX = allocated; - - if (startX < minX || minX < 0) { - minX = startX; - maxY = contiguousOffset + contiguousSize; - } - - if ((*itPlanes).size != (*itPlanes).stride) { - for (unsigned int offset = contiguousOffset; - offset < contiguousOffset + contiguousSize; - offset += (*itPlanes).stride) - { - fmt::print(gnuplot.get(), "set object {} rectangle from {},{} to {},{} fc palette frac ({} * 1./N)\n", - (allocated * 100 + objectId), startX, (offset / 1024.0), - (((isReleased) ? released : maxLifetime) + 1), - (std::min((offset + (*itPlanes).size), - contiguousOffset + contiguousSize) / 1024.0), - labelId); - ++objectId; - } - } - else { - fmt::print(gnuplot.get(), "set object {} rectangle from {},{} to {},{} fc palette frac ({} * 1./N)\n", - (allocated * 100 + objectId), startX, (contiguousOffset / 1024.0), - (((isReleased) ? released : maxLifetime) + 1), - ((contiguousOffset + contiguousSize) / 1024.0), - labelId); - ++objectId; - } - - if (wrappedSize > 0) { - fmt::print(gnuplot.get(), "set object {} rectangle from {},{} to {},{} fc palette frac ({} * 1./N)\n", - (allocated * 100 + objectId), startX, (wrappedOffset / 1024.0), - (((isReleased) ? released : maxLifetime) + 1), - ((wrappedOffset + contiguousSize) / 1024.0), - labelId); - ++objectId; - - fmt::print(gnuplot.get(), "set arrow from {},{} to {},{} nohead\n", - startX, (contiguousOffset / 1024.0), - (startX + 0.1), (contiguousOffset / 1024.0)); - - fmt::print(gnuplot.get(), "set arrow from {},{} to {},{} nohead\n", - (startX + 0.05), ((contiguousOffset + contiguousSize) / 1024.0), - (startX + 0.05), (wrappedOffset / 1024.0)); - } - } - - fmt::print(gnuplot.get(), "set label {} '{}' at {},{} rotate by 30 font \",8\" offset char 0.5,0.5\n", - labelId, name, minX, (maxY / 1024.0)); - ++labelId; - - fmt::print(memData.get(), "\n"); - } - - fmt::print(gnuplot.get(), "set arrow from 0,{} to {},{} nohead lc rgb \"red\"\n", - (peakUsage / 1024.0), (maxLifetime + 1), - (peakUsage / 1024.0)); - - fmt::print(gnuplot.get(), "set label {} 'Peak usage = {} KWords' at 0,{} textcolor rgb \"red\" offset char 0.5,0.5\n", - labelId, (peakUsage / 1024.0), (peakUsage / 1024.0)); - - fmt::print(gnuplot.get(), "plot 0\n"); -} - unsigned int Aidge::MemoryManager::onStack(unsigned int size) { unsigned int offset = 0; -- GitLab