Introduce subtensor map (#3493)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 7 Nov 2018 07:17:33 +0000 (16:17 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 7 Nov 2018 07:17:33 +0000 (16:17 +0900)
- Introduce subtensor map in ACL tensor builder
- TensorBuilder::at() and TensorBuilder::tensorAt() can return subtensor

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 4ad7c36..ec717b8 100644 (file)
@@ -66,7 +66,9 @@ void TensorBuilder::prepare(void)
 
   // TODO Handle SubTensor(subsumption)
   //      Currently this TensorBuilder does not have subsumption info yet
+  //      Allocated subtensor will be mapped to _subtensors instead of _tensors
   assert(_subtensor_info_map.size() == 0);
+  assert(_subtensors.size() == 0);
 
   for (auto &entry : _tensor_info_map)
   {
@@ -91,7 +93,14 @@ void TensorBuilder::allocate(void)
 
 std::shared_ptr<::arm_compute::ITensor> TensorBuilder::tensorAt(const graph::operand::Index &ind)
 {
-  return _tensors.at(ind);
+  if (_tensors.find(ind) != _tensors.end())
+  {
+    return _tensors.at(ind);
+  }
+  else
+  {
+    return _subtensors.at(ind);
+  }
 }
 
 std::shared_ptr<backend::operand::IObject>
@@ -108,10 +117,17 @@ void TensorBuilder::iterate(const IterateFunction &fn)
   }
 }
 
-std::shared_ptr<::arm_compute::CLTensor>
+std::shared_ptr<::arm_compute::ICLTensor>
 TensorBuilder::at(const ::neurun::graph::operand::Index &ind)
 {
-  return _tensors.at(ind);
+  if (_tensors.find(ind) != _tensors.end())
+  {
+    return _tensors.at(ind);
+  }
+  else
+  {
+    return _subtensors.at(ind);
+  }
 }
 
 } // namespace acl_cl
index 307e827..12bb6ed 100644 (file)
@@ -22,6 +22,7 @@
 #include <unordered_map>
 
 #include <arm_compute/runtime/CL/CLTensor.h>
+#include <arm_compute/runtime/CL/CLSubTensor.h>
 
 namespace neurun
 {
@@ -62,12 +63,14 @@ public:
   wrapTensor(const graph::operand::Index &ind) override;
   virtual void iterate(const IterateFunction &fn) override;
 
-  std::shared_ptr<::arm_compute::CLTensor> at(const ::neurun::graph::operand::Index &ind);
+  std::shared_ptr<::arm_compute::ICLTensor> at(const ::neurun::graph::operand::Index &ind);
 
 private:
   std::unordered_map<graph::operand::Index, ::arm_compute::TensorInfo> _tensor_info_map;
   std::unordered_map<graph::operand::Index, backend::operand::SubTensorInfo> _subtensor_info_map;
   std::unordered_map<graph::operand::Index, std::shared_ptr<::arm_compute::CLTensor>> _tensors;
+  std::unordered_map<graph::operand::Index, std::shared_ptr<::arm_compute::CLSubTensor>>
+      _subtensors;
 };
 
 } // namespace acl_cl