Introduce TensorInfo for interpreter (#4780)
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Tue, 19 Mar 2019 06:45:52 +0000 (15:45 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 19 Mar 2019 06:45:52 +0000 (15:45 +0900)
Introduce TensorInfo for interpreter
Current implementation is copy of compiler::TensorInfo

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
runtimes/neurun/core/src/exec/interp/TensorInfo.h [new file with mode: 0644]

diff --git a/runtimes/neurun/core/src/exec/interp/TensorInfo.h b/runtimes/neurun/core/src/exec/interp/TensorInfo.h
new file mode 100644 (file)
index 0000000..167f83a
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file  TensorInfo.h
+ * @brief This file contains TensorInfo class
+ * @note  Current implementation is copy of compiler::TensorInfo
+ */
+#ifndef __NEURUN_EXEC_INTERP_TENSOR_INFO_H__
+#define __NEURUN_EXEC_INTERP_TENSOR_INFO_H__
+
+#include "model/operand/Shape.h"
+#include "model/operand/TypeInfo.h"
+
+#include <numeric>
+
+namespace neurun
+{
+namespace exec
+{
+namespace interp
+{
+
+/**
+ * @brief Class to save tensor's shape and type
+ */
+class TensorInfo
+{
+public:
+  /**
+   * @brief Construct a new Tensor Info object (deleted)
+   */
+  TensorInfo() = delete;
+  /**
+   * @brief     Construct a new Tensor Info object
+   * @param[in] shape     Tensor shape
+   * @param[in] typeInfo  Tensor data type
+   */
+  TensorInfo(const ::neurun::model::operand::Shape &shape,
+             const ::neurun::model::operand::TypeInfo &typeInfo)
+      : _shape(shape), _typeInfo(typeInfo)
+  {
+    // DO NOTHING
+  }
+  /**
+   * @brief     Construct a new Tensor Info object
+   * @param[in] origin Tensor info for copy
+   */
+  TensorInfo(const TensorInfo &origin) : _shape(origin.shape), _typeInfo(origin.typeInfo)
+  {
+    // DO NOTHING
+  }
+
+public:
+  /**
+   * @brief   Return tensor shape
+   * @return  Tensor shape
+   */
+  const ::neurun::model::operand::Shape &shape() const { return _shape; }
+  /**
+   * @brief   Return tensor data type info
+   * @return  Tensor data type
+   */
+  const ::neurun::model::operand::TypeInfo &typeInfo() const { return _typeInfo; }
+  /**
+   * @brief   Return size of tensor (bytes)
+   * @return  Tensor size
+   */
+  size_t total_size() const
+  {
+    const auto &dims = _shape.dims();
+    return std::accumulate(dims.begin(), dims.end(), sizeOfDataType(_typeInfo.type()),
+                           std::multiplies<size_t>());
+  }
+
+private:
+  ::neurun::model::operand::Shape _shape;
+  ::neurun::model::operand::TypeInfo _typeInfo;
+};
+
+} // namespace interp
+} // namespace exec
+} // namespace neurun
+
+#endif // __NEURUN_EXEC_INTERP_TENSOR_INFO_H__