[rebase] Add rebase fix
authorParichay Kapoor <pk.kapoor@samsung.com>
Fri, 1 Oct 2021 04:24:10 +0000 (13:24 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Tue, 5 Oct 2021 04:54:00 +0000 (13:54 +0900)
Add rebase fix to the memory unitest. Memory unittest was updated to
shuffle the validity of the requests. However, the unittest check was
not ready for it. This patch adds the sort of the validity before
performing the check, corresponding to the previously added shuffle.

Signed-off-by: Parichay Kapoor <pk.kapoor@samsung.com>
nntrainer/graph/network_graph.h
test/unittest/memory/memory_planner_validate.cpp

index 7079933e56f180bfa2d17f43a1cfd0527d9c2ace..362fc0b3693b0a5345fc06403cedc907ffe476b2 100644 (file)
@@ -272,13 +272,13 @@ public:
       tensor_manager->allocateTensors(
         std::get<0>((*(cend() - 1))->getExecutionOrder()));
     else
-      /** @todo update this to skip non-trainable layers */
-      /**
-       * get the order of execution/usage order for the backwarding of the first
-       * layer (as that will be the last layer to executed in the backwarding)
-       * and pass that as the max_exec_order ensuring that all tensors with
-       * usage less than the max_exec_order are allocated.
-       */
+    /** @todo update this to skip non-trainable layers */
+    /**
+     * get the order of execution/usage order for the backwarding of the first
+     * layer (as that will be the last layer to executed in the backwarding)
+     * and pass that as the max_exec_order ensuring that all tensors with
+     * usage less than the max_exec_order are allocated.
+     */
 #ifdef ENABLE_TEST
       tensor_manager->allocateTensors(
         std::get<2>((*(cbegin()))->getExecutionOrder()));
index 5097c8e69b55f772fd4a89cf4e4ae14995311f3c..501ea0d8dd19932c475cd0f3bcab87887323c7a0 100644 (file)
@@ -82,7 +82,21 @@ static bool validateIntervalOverlap(
   const std::vector<size_t> &memory_size,
   const std::vector<size_t> &memory_offset) {
   std::vector<unsigned int> valid_intervals;
+  std::vector<unsigned int> sorted_by_validity(memory_size.size());
+
+  /** sort the intervals by their validity for comparison */
   for (unsigned int idx = 0; idx < memory_size.size(); idx++) {
+    sorted_by_validity[idx] = idx;
+  }
+  std::sort(
+    sorted_by_validity.begin(), sorted_by_validity.end(),
+    [&memory_validity](auto const &idx1, auto const &idx2) -> unsigned int {
+      if (memory_validity[idx1].first == memory_validity[idx2].first)
+        return memory_validity[idx1].second < memory_validity[idx2].second;
+      return memory_validity[idx1].first < memory_validity[idx2].first;
+    });
+
+  for (unsigned int idx : sorted_by_validity) {
     /**
      * intervals which have finished before the start of the current intervals
      * must be popped