[Ahub] Fix Ahub issue
authorSeoHyungjun <hyungjun.seo@samsung.com>
Thu, 24 Aug 2023 08:10:51 +0000 (17:10 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Wed, 20 Sep 2023 06:47:40 +0000 (15:47 +0900)
Previously, nntrainer only supported fp32. nntrainer didn't need to
change the data type, but it needs to be changed to support fp16. If
the tensor type is fp16, get input_dim of InitLayerContext through
getInputDimentions and call setDataType. For getInputDimentions,
return a const object. Added getMutableInputDimentions function
because return object of getInputDimentions cannot be modified.

Signed-off-by: SeoHyungjun <hyungjun.seo@samsung.com>
nntrainer/layers/layer_context.h
test/unittest/layers/layers_golden_tests.cpp

index 35653bde0f46d5f3d35149af702994bfd2fc10f2..9fc7abff69ef73bde1925fe6a09d17ee92d0cbae 100644 (file)
@@ -112,6 +112,13 @@ public:
    */
   const std::vector<TensorDim> &getInputDimensions() const { return input_dim; }
 
+  /**
+   * @brief Get the Mutable Input Dimensions object
+   *
+   * @return std::vector<TensorDim>& Input dimensions
+   */
+  std::vector<TensorDim> &getMutableInputDimensions() { return input_dim; }
+
   /**
    * @brief Set Data Type for Input Dimensions
    *
index 4980cde10b22d03060ecb212147c6d0a80f8fe13..eac8872750509cef424df757edf8881bcda843e0 100644 (file)
@@ -70,7 +70,7 @@ createInitContext(Layer *layer, const std::string &input_shape_str,
                            "golden_test", "", 0.0, tensor_type);
   layer->finalize(context);
 
-  for (auto dim : context.getInputDimensions()) {
+  for (auto &dim : context.getMutableInputDimensions()) {
     if (tensor_type[2] == "fp16") {
       dim.setDataType(ml::train::TensorDim::DataType::FP16);
     }