[nnc backend] Add OperationImpl class (#396)
authorVladimir Plazun/AI Tools Lab /SRR/Engineer/삼성전자 <v.plazun@partner.samsung.com>
Mon, 2 Jul 2018 15:09:12 +0000 (19:09 +0400)
committerSergey Vostokov/AI Tools Lab /SRR/Staff Engineer/삼성전자 <s.vostokov@samsung.com>
Mon, 2 Jul 2018 15:09:12 +0000 (00:09 +0900)
Add OperationImpl class

Base class used as a base for other operation implementations

Signed-off-by: Vladimir Plazun <v.plazun@partner.samsung.com>
contrib/nnc/libs/backend/interpreter/core/include/interpreter/ops/OperationImpl.h [new file with mode: 0644]

diff --git a/contrib/nnc/libs/backend/interpreter/core/include/interpreter/ops/OperationImpl.h b/contrib/nnc/libs/backend/interpreter/core/include/interpreter/ops/OperationImpl.h
new file mode 100644 (file)
index 0000000..d489037
--- /dev/null
@@ -0,0 +1,58 @@
+#ifndef _NNC_CORE_BACKEND_INTERPRETER_OPERATION_IMPL_
+#define _NNC_CORE_BACKEND_INTERPRETER_OPERATION_IMPL_
+
+#include <vector>
+
+#include "nnc/core/linalg/Tensor.h"
+#include "nnc/core/linalg/TensorVariant.h"
+
+#include "nncc/core/ADT/tensor/Shape.h"
+
+namespace nncc
+{
+namespace contrib
+{
+namespace backend
+{
+namespace interpreter
+{
+namespace impl
+{
+
+using namespace nncc::contrib::core::data;
+using nncc::contrib::core::ADT::TensorVariant;
+
+using nncc::core::ADT::tensor::Shape;
+
+template <typename T> class OperationImpl
+{
+public:
+  virtual std::vector<TensorVariant> operator()() = 0;
+
+protected:
+  TensorVariant allocate_tensor(const Shape &shape)
+  {
+    size_t data_size = 1;
+    for (uint32_t i = 0; i < shape.rank(); ++i)
+    {
+      data_size *= shape.dim(i);
+    }
+
+    auto od = new T[data_size]();
+
+    std::shared_ptr<T> data(od, [](const T* d) { delete[] d; });
+    // Use hardcoded DTYPE for now, since theres no support for operations on types other than
+    // floats
+    TensorVariant t(shape, data, TensorVariant::DTYPE::FLOAT);
+
+    return t;
+  }
+};
+
+} // namespace impl
+} // namespace interpreter
+} // namespace backend
+} // namespace contrib
+} // namespace nncc
+
+#endif //_NNC_CORE_BACKEND_INTERPRETER_OPERATION_IMPL_