From 48371618a5b33778897cfed1e554d4c90cde882c Mon Sep 17 00:00:00 2001
From: cmoineau <cyril.moineau@cea.fr>
Date: Fri, 13 Sep 2024 14:04:36 +0000
Subject: [PATCH] Fix gnuplot issue

---
 aidge_core/mem_info.py | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/aidge_core/mem_info.py b/aidge_core/mem_info.py
index 720208580..1f2f48dd6 100644
--- a/aidge_core/mem_info.py
+++ b/aidge_core/mem_info.py
@@ -42,7 +42,6 @@ def compute_default_mem_info(scheduler: aidge_core.Scheduler) -> Tuple[int, List
 
 
 def generate_optimized_memory_info(scheduler: aidge_core.Scheduler, stats_folder: Path, wrapping: bool = False) -> Tuple[int, List[dict]]:
-
     # The forward dims has to done outside the function
     # Also supposed the generation of the scheduler has been performed outside
     # Otherwise decomment the following line
@@ -55,18 +54,16 @@ def generate_optimized_memory_info(scheduler: aidge_core.Scheduler, stats_folder
     # List of nodes which are connected at the input of the graph (None if input is not connected)
     nodes_at_input = [n[0] for n in scheduler.graph_view().inputs()]
     # Use gnuplot to generate the log
-    try:
-        os.makedirs(str(stats_folder / "graph"), exist_ok=True)
-        mem_manager.log("memory_info")
-        os.chmod("memory_info_plot.gnu", 0o777)
-        os.system("./memory_info_plot.gnu")
-        shutil.move("memory_info", str(stats_folder / "graph" / "memory_info"))
-        shutil.move("memory_info_plot.png", str(
-            stats_folder / "graph" / "memory_info_plot.png"))
-        os.remove("memory_info_plot.gnu")
-    except:
-        print("Please install gnuplot if you want memory plot from MemoryManager.")
-
+    if isinstance(stats_folder, str):
+        stats_folder = Path(stats_folder)
+    os.makedirs(str(Path(stats_folder) / "graph"), exist_ok=True)
+    mem_manager.log("memory_info")
+    os.chmod("memory_info_plot.gnu", 0o777)
+    os.system("./memory_info_plot.gnu")
+    shutil.move("memory_info", str(Path(stats_folder) / "graph" / "memory_info"))
+    shutil.move("memory_info_plot.png", str(
+        Path(stats_folder) / "graph" / "memory_info_plot.png"))
+    os.remove("memory_info_plot.gnu")
     # In the export, we currently use an unified memory buffer whose size
     # is determined by the memory peak usage
     mem_size = mem_manager.get_peak_usage()
@@ -86,7 +83,6 @@ def generate_optimized_memory_info(scheduler: aidge_core.Scheduler, stats_folder
             if len(tensor.dims()) < 3:
                 raise RuntimeError(
                     f"Input producer dimensions must be with [:, channel, height, width] but got {tensor.dims()} instead")
-
             # TODO : use get_chan get_height and get_width function !
             node_mem_info.append({
                     "size": tensor.dims()[-3],          # Should be nb_channels
@@ -108,7 +104,7 @@ def generate_optimized_memory_info(scheduler: aidge_core.Scheduler, stats_folder
                 plane = mem_planes[node][out_id]
                 node_mem_info.append({
                     "size": plane.size,
-                    "offset": plane.offset,
+                    "offset": plane.get_contiguous_offset(),
                     "stride": plane.stride,
                     "length": plane.length,
                     "count": plane.count,
-- 
GitLab