From 43b467f6c8b95a35583958e4f899185315b1e0ea Mon Sep 17 00:00:00 2001
From: NAUD Maxence <maxence.naud@cea.fr>
Date: Tue, 9 Apr 2024 11:40:18 +0000
Subject: [PATCH] Remove warning in release compile mode

---
 include/aidge/data/Tensor.hpp             |  2 ++
 include/aidge/filler/Filler.hpp           | 20 ++----------
 include/aidge/scheduler/MemoryManager.hpp |  4 +++
 include/aidge/scheduler/Scheduler.hpp     |  9 +++--
 include/aidge/utils/Log.hpp               | 19 +++++++++--
 src/data/Tensor.cpp                       |  4 +++
 src/filler/Filler.cpp                     | 40 +++++++++++++++++++++++
 src/recipes/FuseBatchNorm.cpp             |  7 ++--
 src/scheduler/MemoryManager.cpp           |  2 ++
 src/scheduler/Scheduler.cpp               |  6 ++++
 10 files changed, 85 insertions(+), 28 deletions(-)
 create mode 100644 src/filler/Filler.cpp

diff --git a/include/aidge/data/Tensor.hpp b/include/aidge/data/Tensor.hpp
index 2503c01b3..b8623450a 100644
--- a/include/aidge/data/Tensor.hpp
+++ b/include/aidge/data/Tensor.hpp
@@ -331,6 +331,8 @@ class Tensor : public Data,
         return div_.getOutput(0)->clone();
     }
 
+    ~Tensor() noexcept;
+
 public:
     /**
      * @brief Perform a deep copy of the tensor.
diff --git a/include/aidge/filler/Filler.hpp b/include/aidge/filler/Filler.hpp
index abdb2017f..fe39771b6 100644
--- a/include/aidge/filler/Filler.hpp
+++ b/include/aidge/filler/Filler.hpp
@@ -16,27 +16,11 @@
 #include <memory>
 
 #include "aidge/data/Tensor.hpp"
-#include "aidge/utils/ErrorHandling.hpp"
 
 namespace Aidge {
 
-inline void calculateFanInFanOut(std::shared_ptr<Tensor> tensor,
-                                 std::uint32_t& fanIn, std::uint32_t& fanOut) {
-    AIDGE_ASSERT(
-        tensor->nbDims() == 4,
-        "Tensor need to have 4 dimensions to compute FanIn and FanOut.");
-    // Warning: This function suppose NCXX data layout.
-    // Aidge currently only support NCHW but this maybe not be true in the
-    // future.
-    DimSize_t batchSize = tensor->dims()[0];
-    DimSize_t channelSize = tensor->dims()[1];
-    AIDGE_ASSERT(batchSize != 0,
-                 "Cannot calculate FanIn if tensor batch size is 0.");
-    AIDGE_ASSERT(channelSize != 0,
-                 "Cannot calculate FanOut if tensor channel size is 0.");
-    fanIn =  static_cast<std::uint32_t>(tensor->size() / batchSize);
-    fanOut = static_cast<std::uint32_t>(tensor->size() / channelSize);
-}
+void calculateFanInFanOut(std::shared_ptr<Tensor> tensor,
+                                 std::uint32_t& fanIn, std::uint32_t& fanOut);
 
 enum class VarianceNorm { FanIn, Average, FanOut };
 
diff --git a/include/aidge/scheduler/MemoryManager.hpp b/include/aidge/scheduler/MemoryManager.hpp
index 21d122b44..360b01f76 100644
--- a/include/aidge/scheduler/MemoryManager.hpp
+++ b/include/aidge/scheduler/MemoryManager.hpp
@@ -193,7 +193,11 @@ public:
     typedef std::map<std::shared_ptr<Node>, std::vector<MemoryPlane>,
         CompByNodeName> MemMap_T;
 
+public:
     MemoryManager(): mClock(0) {}
+    ~MemoryManager() noexcept;
+
+public:
     /// Generates a new MemorySpace
     std::shared_ptr<MemorySpace> reserve(unsigned int size,
                                     const std::set<std::shared_ptr<Node> >&
diff --git a/include/aidge/scheduler/Scheduler.hpp b/include/aidge/scheduler/Scheduler.hpp
index 75ac90502..2f8fbb7ae 100644
--- a/include/aidge/scheduler/Scheduler.hpp
+++ b/include/aidge/scheduler/Scheduler.hpp
@@ -53,13 +53,16 @@ protected:
             std::chrono::time_point<std::chrono::high_resolution_clock> start_,
             std::chrono::time_point<std::chrono::high_resolution_clock> end_)
             : node(node_), start(start_), end(end_) {}
-
+        ~SchedulingElement() noexcept = default;
         std::shared_ptr<Node> node;
         std::chrono::time_point<std::chrono::high_resolution_clock> start;
         std::chrono::time_point<std::chrono::high_resolution_clock> end;
     };
-
+public:
     struct PriorProducersConsumers {
+        PriorProducersConsumers();
+        PriorProducersConsumers(const PriorProducersConsumers&);
+        ~PriorProducersConsumers() noexcept;
         bool isPrior = false;
         std::set<std::shared_ptr<Aidge::Node>> requiredProducers;
         std::set<std::shared_ptr<Aidge::Node>> priorConsumers;
@@ -73,7 +76,7 @@ public:
         // ctor
     };
 
-    virtual ~Scheduler() noexcept = default;
+    virtual ~Scheduler() noexcept;
 
 public:
     /**
diff --git a/include/aidge/utils/Log.hpp b/include/aidge/utils/Log.hpp
index f20a619c2..a01f81629 100644
--- a/include/aidge/utils/Log.hpp
+++ b/include/aidge/utils/Log.hpp
@@ -27,6 +27,17 @@ namespace Aidge {
 */
 #define AIDGE_LOG_CONTEXT(...) const Log::Context logContext_##__LINE__(__VA_ARGS__)
 
+
+template<class U>
+static void discard_args(U parg) {
+    (void)parg;
+}
+template<class U, class... Us>
+static void discard_args(U parg, Us... pargs) {
+    (void)parg;
+    discard_args(pargs...);
+}
+
 /**
  * Aidge logging class, for displaying and file logging of events.
 */
@@ -54,7 +65,7 @@ public:
     };
 
     /**
-     * Detailed messages for debugging purposes, providing information helpful 
+     * Detailed messages for debugging purposes, providing information helpful
      * for developers to trace and identify issues.
      * Detailed insights of what is appening in an operation, not useful for the
      * end-user. The operation is performed nominally.
@@ -66,11 +77,13 @@ public:
 #ifndef NDEBUG
         // only when compiled in Debug
         log(Debug, fmt::format(std::forward<Args>(args)...));
+#else
+        discard_args(&args...);
 #endif
     }
 
     /**
-     * Messages that provide a record of the normal operation, about 
+     * Messages that provide a record of the normal operation, about
      * the application's state, progress, or important events.
      * Reports normal start, end and key steps in an operation. The operation is
      * performed nominally.
@@ -103,7 +116,7 @@ public:
     }
 
     /**
-     * Signifies a problem or unexpected condition that the application can 
+     * Signifies a problem or unexpected condition that the application can
      * recover from, but attention is needed to prevent further issues.
      * The operation could not be performed, but it does not prevent potential
      * further operations.
diff --git a/src/data/Tensor.cpp b/src/data/Tensor.cpp
index b350c5bf0..b6aa4f2e5 100644
--- a/src/data/Tensor.cpp
+++ b/src/data/Tensor.cpp
@@ -39,6 +39,10 @@ Aidge::Tensor& Aidge::Tensor::operator=(const Aidge::Tensor& other) {
     return *this;
 }
 
+
+Aidge::Tensor::~Tensor() noexcept = default;
+
+
 void Aidge::Tensor::resize(const std::vector<Aidge::DimSize_t> &dims, std::vector<Aidge::DimSize_t> strides) {
     // TODO: scalar Tensor not handled
     if (dims.empty()) { // scalar
diff --git a/src/filler/Filler.cpp b/src/filler/Filler.cpp
new file mode 100644
index 000000000..34e04c2ba
--- /dev/null
+++ b/src/filler/Filler.cpp
@@ -0,0 +1,40 @@
+/********************************************************************************
+ * Copyright (c) 2023 CEA-List
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ ********************************************************************************/
+
+#include "aidge/filler/Filler.hpp"
+
+#include <cstdint>  // std::uint32_t
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "aidge/data/Tensor.hpp"
+#include "aidge/utils/ErrorHandling.hpp"
+#include "aidge/utils/Types.h"
+
+
+void Aidge::calculateFanInFanOut(std::shared_ptr<Aidge::Tensor> tensor,
+                                 std::uint32_t& fanIn, std::uint32_t& fanOut) {
+    AIDGE_ASSERT(
+        tensor->nbDims() == 4,
+        "Tensor need to have 4 dimensions to compute FanIn and FanOut.");
+    // Warning: This function suppose NCXX data layout.
+    // Aidge currently only support NCHW but this maybe not be true in the
+    // future.
+    DimSize_t batchSize = tensor->dims()[0];
+    DimSize_t channelSize = tensor->dims()[1];
+    AIDGE_ASSERT(batchSize != 0,
+                 "Cannot calculate FanIn if tensor batch size is 0.");
+    AIDGE_ASSERT(channelSize != 0,
+                 "Cannot calculate FanOut if tensor channel size is 0.");
+    fanIn =  static_cast<std::uint32_t>(tensor->size() / batchSize);
+    fanOut = static_cast<std::uint32_t>(tensor->size() / channelSize);
+}
diff --git a/src/recipes/FuseBatchNorm.cpp b/src/recipes/FuseBatchNorm.cpp
index ac1fc8d79..76c15a062 100644
--- a/src/recipes/FuseBatchNorm.cpp
+++ b/src/recipes/FuseBatchNorm.cpp
@@ -50,9 +50,9 @@ void Aidge::fuseBatchNorm(std::shared_ptr<Aidge::Node> convNode,
     const std::shared_ptr<BatchNorm_Op<2>> batchOp =
             std::static_pointer_cast<BatchNorm_Op<2>>(batchnormNode->getOperator());
 
-    DimSize_t convNbOutChannels;
-    DimSize_t channelsSize;
-    std::array<DimSize_t, 2> kernelDims;
+    DimSize_t convNbOutChannels = 1;
+    DimSize_t channelsSize = 1;
+    std::array<DimSize_t, 2> kernelDims = {1,1};
     AIDGE_ASSERT(convNode->getOperator()->operatorType() == OperatorType::Tensor, "Operator must be of Tensor type.");
     std::shared_ptr<OperatorTensor> convOp = std::static_pointer_cast<OperatorTensor>(convNode->getOperator());
     if (convNode->type() == Conv_Op<2>::Type) {
@@ -66,7 +66,6 @@ void Aidge::fuseBatchNorm(std::shared_ptr<Aidge::Node> convNode,
         const std::shared_ptr<ConvDepthWise_Op<2>> convOpPtr =
             std::static_pointer_cast<ConvDepthWise_Op<2>>(convNode->getOperator());
         convNbOutChannels = convOpPtr->getAttr<DimSize_t>("Channels");
-        channelsSize = 1;
         kernelDims = convOpPtr->getAttr<std::array<DimSize_t, 2>>("KernelDims");
     }
 
diff --git a/src/scheduler/MemoryManager.cpp b/src/scheduler/MemoryManager.cpp
index 9599dbf74..6fe0d1f07 100644
--- a/src/scheduler/MemoryManager.cpp
+++ b/src/scheduler/MemoryManager.cpp
@@ -14,6 +14,8 @@
 #include "aidge/scheduler/MemoryManager.hpp"
 #include "aidge/utils/ErrorHandling.hpp"
 
+Aidge::MemoryManager::~MemoryManager() noexcept = default;
+
 std::shared_ptr<Aidge::MemoryManager::MemorySpace> Aidge::MemoryManager::reserve(
     unsigned int size,
     const std::set<std::shared_ptr<Node> >& dependencies)
diff --git a/src/scheduler/Scheduler.cpp b/src/scheduler/Scheduler.cpp
index ecf000ef3..4e3f99788 100644
--- a/src/scheduler/Scheduler.cpp
+++ b/src/scheduler/Scheduler.cpp
@@ -35,6 +35,12 @@
 #include "aidge/operator/Producer.hpp"
 #include "aidge/utils/Types.h"
 
+
+Aidge::Scheduler::~Scheduler() noexcept = default;
+Aidge::Scheduler::PriorProducersConsumers::PriorProducersConsumers() = default;
+Aidge::Scheduler::PriorProducersConsumers::PriorProducersConsumers(const PriorProducersConsumers&) = default;
+Aidge::Scheduler::PriorProducersConsumers::~PriorProducersConsumers() noexcept = default;
+
 void Aidge::Scheduler::generateScheduling() {
     auto schedule = generateBaseScheduling();
     generateEarlyLateScheduling(schedule);
-- 
GitLab