[Clean] Remove getOutputDimensions()
authorJihoon Lee <jhoon.it.lee@samsung.com>
Tue, 28 Dec 2021 08:01:07 +0000 (17:01 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Wed, 29 Dec 2021 07:48:32 +0000 (16:48 +0900)
This patch removes initContext::getOutputDimensions().

This function is only used in the test so removed
(It is used in network_graph but soon will be substitued)

**Self evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Jihoon Lee <jhoon.it.lee@samsung.com>
nntrainer/graph/network_graph.cpp
nntrainer/layers/layer_context.cpp
nntrainer/layers/layer_context.h
test/unittest/layers/layers_dependent_common_tests.cpp
test/unittest/layers/layers_golden_tests.cpp
test/unittest/layers/layers_standalone_common_tests.cpp

index 36cc112..e682d79 100644 (file)
@@ -12,6 +12,7 @@
  * @todo    Support multi-input graph.
  */
 
+#include "tensor.h"
 #include <cmath>
 #include <stdexcept>
 #include <string>
@@ -696,10 +697,13 @@ NetworkGraph::finalizeContext(const std::shared_ptr<LayerNode> &lnode,
    * allocated input. This is neccesary for manager to know when this output
    * node is going to be used with in-place optimizations.
    */
+  std::vector<TensorDim> out_dims;
+  for (auto &spec : init_context.getOutSpecs()) {
+    out_dims.push_back(spec.variable_spec.dim);
+  }
   unsigned int max_fwd_exec_order = graph.size();
   const std::vector<Var_Grad *> &outputs = tensor_manager->requestOutputs(
-    gnode, init_context.getOutputDimensions(), inputs_name, max_fwd_exec_order,
-    shared_var, shared_grad);
+    gnode, out_dims, inputs_name, max_fwd_exec_order, shared_var, shared_grad);
 
   /** create shared weight names if requested */
   std::vector<std::string> shared_weight_names;
index d75a743..66e8b64 100644 (file)
@@ -116,7 +116,7 @@ void InitLayerContext::requestOutputs(std::vector<VarGradSpecV2> &&out_specs) {
   }
 }
 
-const std::vector<VarGradSpecV2> &InitLayerContext::getOutSpecs() {
+const std::vector<VarGradSpecV2> &InitLayerContext::getOutSpecs() const {
   return output_specs;
 }
 
index 0db6447..3f0a0c7 100644 (file)
@@ -105,19 +105,6 @@ public:
   }
 
   /**
-   * @brief Get the Output Dimensions object
-   *
-   * @return std::vector<TensorDim>& Output dimensions
-   */
-  const std::vector<TensorDim> getOutputDimensions() const {
-    std::vector<TensorDim> output_dim;
-    for (auto &spec : output_specs) {
-      output_dim.push_back(spec.variable_spec.dim);
-    }
-    return output_dim;
-  }
-
-  /**
    * @brief Set the Output Dimensions object
    *
    * @param out_dim the output dimension to set to
@@ -261,7 +248,7 @@ public:
    *
    * @return std::vector<VarGradSpecV2> out specification
    */
-  const std::vector<VarGradSpecV2> &getOutSpecs();
+  const std::vector<VarGradSpecV2> &getOutSpecs() const;
 
   /**
    * @brief Validate the context
index 6d37c87..e2ee521 100644 (file)
@@ -58,8 +58,8 @@ TEST_P(LayerSemantics, finalizeValidateLayerNode_p) {
   if (!must_fail) {
     nntrainer::InitLayerContext init_context = lnode->finalize();
 
-    for (auto const &dim : init_context.getOutputDimensions())
-      EXPECT_GT(dim.getDataLen(), size_t(0));
+    for (auto const &spec : init_context.getOutSpecs())
+      EXPECT_GT(spec.variable_spec.dim.getDataLen(), size_t(0));
     for (auto const &ws : init_context.getWeightsSpec())
       EXPECT_GT(std::get<0>(ws).getDataLen(), size_t(0));
     for (auto const &ts : init_context.getTensorsSpec())
index d53985f..4842f1f 100644 (file)
@@ -10,6 +10,7 @@
  * @bug No known bugs except for NYI items
  */
 #include <layers_common_tests.h>
+#include <tensor_wrap_specs.h>
 
 #include <fstream>
 #include <type_traits>
@@ -80,6 +81,18 @@ static TensorPacks prepareTensors(const InitLayerContext &context,
     return vg;
   };
 
+  auto allocate_tensors_v2 = [](const std::vector<VarGradSpecV2> &specs) {
+    std::vector<Var_Grad> vg;
+    vg.reserve(specs.size());
+
+    for (auto &spec : specs) {
+      /// todo initializer should be depending is as well
+      vg.emplace_back(spec.variable_spec.dim, Tensor::Initializer::NONE, true,
+                      true, "golden");
+    }
+    return vg;
+  };
+
   auto allocate_weights = [&file](const auto &specs) {
     std::vector<Weight> weights;
     weights.reserve(specs.size());
@@ -96,7 +109,7 @@ static TensorPacks prepareTensors(const InitLayerContext &context,
   return {
     allocate_weights(context.getWeightsSpec()),
     allocate_inouts(context.getInputDimensions()),
-    allocate_inouts(context.getOutputDimensions()),
+    allocate_tensors_v2(context.getOutSpecs()),
     allocate_tensors(context.getTensorsSpec()),
   };
 }
index 223ae47..a828c36 100644 (file)
@@ -51,8 +51,8 @@ TEST_P(LayerSemantics, finalizeValidate_p) {
   if (!must_fail) {
     EXPECT_NO_THROW(layer->finalize(init_context));
 
-    for (auto const &dim : init_context.getOutputDimensions())
-      EXPECT_GT(dim.getDataLen(), size_t(0));
+    for (auto const &spec : init_context.getOutSpecs())
+      EXPECT_GT(spec.variable_spec.dim.getDataLen(), size_t(0));
     for (auto const &ws : init_context.getWeightsSpec())
       EXPECT_GT(std::get<0>(ws).getDataLen(), size_t(0));
     for (auto const &ts : init_context.getTensorsSpec())