Introduce subtensor allocation check API (#3510)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Thu, 8 Nov 2018 01:10:32 +0000 (10:10 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 8 Nov 2018 01:10:32 +0000 (10:10 +0900)
Check API will be used in codegen

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
runtimes/neurun/src/backend/acl_cl/TensorBuilder.cc
runtimes/neurun/src/backend/acl_cl/TensorBuilder.h

index ec717b8..e5fe4b7 100644 (file)
@@ -130,6 +130,27 @@ TensorBuilder::at(const ::neurun::graph::operand::Index &ind)
   }
 }
 
+bool TensorBuilder::isSubTensorOf(const graph::operand::Index &parent,
+                                  const graph::operand::Index &child)
+{
+  if (_subtensor_info_map.find(child) == _subtensor_info_map.end())
+  {
+    return false;
+  }
+
+  if (_subtensors.find(child) == _subtensors.end())
+  {
+    return false;
+  }
+
+  if (_subtensor_info_map.at(child).parent() != parent)
+  {
+    return false;
+  }
+
+  return true;
+}
+
 } // namespace acl_cl
 } // namespace backend
 } // namespace neurun
index 12bb6ed..e7ae3b3 100644 (file)
@@ -64,6 +64,13 @@ public:
   virtual void iterate(const IterateFunction &fn) override;
 
   std::shared_ptr<::arm_compute::ICLTensor> at(const ::neurun::graph::operand::Index &ind);
+  /**
+   * @brief     Check child tensor is allocated as subtensor of parent tensor
+   * @param[in] parent  Index of parent
+   * @param[in] child   Index of child
+   * @return    @c true if child is allocated as subtensor of parent, otherwise @c false
+   */
+  bool isSubTensorOf(const graph::operand::Index &parent, const graph::operand::Index &child);
 
 private:
   std::unordered_map<graph::operand::Index, ::arm_compute::TensorInfo> _tensor_info_map;