--- /dev/null
+#ifndef _NNC_CORE_LINALG_TENSOR_UTIL_H_
+#define _NNC_CORE_LINALG_TENSOR_UTIL_H_
+
+#include <cstring>
+#include <memory>
+
+#include "nnc/core/linalg/TensorVariant.h"
+#include "nncc/core/ADT/tensor/Shape.h"
+#include "nncc/core/ADT/tensor/Index.h"
+#include "nncc/core/ADT/tensor/IndexRange.h"
+
+namespace nncc
+{
+namespace contrib
+{
+namespace core
+{
+namespace data
+{
+namespace util
+{
+
+using nncc::core::ADT::tensor::Shape;
+using namespace nncc::contrib::core::ADT;
+using namespace nncc::contrib::core::data;
+
+template<unsigned int... Ints>
+static std::shared_ptr <TensorVariant>
+transposeTensor(std::shared_ptr <TensorVariant> tensor)
+{
+ using nncc::core::ADT::tensor::Index;
+ using nncc::core::ADT::tensor::IndexRange;
+
+ const Shape &inShape = tensor->getShape();
+ Shape targetShape{inShape.dim(Ints)...};
+
+ uint64_t size = num_elements(targetShape);
+
+ std::shared_ptr<char> convertedTensorData(new char[size * tensor->getElementSize()],
+ [](char *d) { delete[] d; });
+
+ auto convertedTensor = std::make_shared<TensorVariant>(targetShape, convertedTensorData,
+ tensor->getDataType(),
+ tensor->getElementSize());
+
+ // Swaps two elements in the initial and new tensors
+ // according to the correct tensor dimension order
+ auto swap = [&convertedTensor, &tensor](const Index &idx) {
+ Index targetIndex{idx.at(Ints)...};
+
+ // Copy element_size bytes which constitute one number
+ std::memcpy(convertedTensor->at(targetIndex), tensor->at(idx),
+ convertedTensor->getElementSize());
+ };
+
+ IndexRange(tensor->getShape()).iterate() << swap;
+
+ return convertedTensor;
+}
+
+} // namespace util
+} // namespace data
+} // namespace core
+} // namespace contrib
+} // namespace nncc
+
+#endif // _NNC_CORE_LINALG_TENSOR_UTIL_H_
#include "nncc/core/ADT/tensor/Shape.h"
#include "nnc/core/IR/model/operations/variable_op.h"
+#include "nnc/core/linalg/TensorUtil.h"
#include "PluginException.h"
#include "shape_helper.h"
using VariableOp = nncc::contrib::core::IR::model::ops::VariableOp;
using nncc::core::ADT::tensor::Shape;
+using nncc::contrib::core::data::util::transposeTensor;
void ModelVisitor::visit(const NetParameter& np)
{
if (lp.has_convolution_param() && blob.shape().dim_size() == 4)
{
- params.emplace_back(common::transposeTensor<2, 3, 1, 0>(tensor));
+ params.emplace_back(transposeTensor<2, 3, 1, 0>(tensor));
}
else
{
#ifndef NNCC_SHAPE_HELPER_H
#define NNCC_SHAPE_HELPER_H
-#include <memory>
-#include <cstring>
-
-#include "nnc/core/linalg/TensorVariant.h"
#include "nncc/core/ADT/tensor/Shape.h"
-#include "nncc/core/ADT/tensor/Index.h"
-#include "nncc/core/ADT/tensor/IndexRange.h"
namespace nncc
{
{
using nncc::core::ADT::tensor::Shape;
-using TensorVariant = nncc::contrib::core::ADT::TensorVariant;
class ShapeHelper
{
return sh;
}
-template <unsigned int... Ints>
-static std::shared_ptr<TensorVariant>
-transposeTensor(std::shared_ptr<TensorVariant> tensor)
-{
- using nncc::core::ADT::tensor::Index;
- using nncc::core::ADT::tensor::IndexRange;
-
- const Shape &inShape = tensor->getShape();
- Shape targetShape{inShape.dim(Ints)...};
-
- uint64_t size = num_elements(targetShape);
-
- std::shared_ptr<char> convertedTensorData(new char[size * tensor->getElementSize()],
- [](char *d) { delete[] d; });
-
- auto convertedTensor = std::make_shared<TensorVariant>(targetShape, convertedTensorData,
- tensor->getDataType(),
- tensor->getElementSize());
-
-
- // Swaps two elements in the initial and new tensors
- // according to the correct tensor dimension order
- auto swap = [&convertedTensor, &tensor](const Index &idx) {
- Index targetIndex{idx.at(Ints)...};
-
- // Copy element_size bytes which constitute one number
- std::memcpy(convertedTensor->at(targetIndex), tensor->at(idx),
- convertedTensor->getElementSize());
- };
-
- IndexRange(tensor->getShape()).iterate() << swap;
-
- return convertedTensor;
-}
-
} // namespace common
} // namespace frontend
} // namespace contrib
#include "nncc/core/ADT/tensor/Shape.h"
#include "nncc/core/ADT/tensor/Index.h"
#include "nncc/core/ADT/tensor/IndexRange.h"
+#include "nnc/core/linalg/TensorUtil.h"
#include "nnc/core/IR/model/operations/variable_op.h"
#include "shape_helper.h"
using nncc::core::ADT::tensor::IndexRange;
using VariableOp = nncc::contrib::core::IR::model::ops::VariableOp;
using nncc::core::ADT::tensor::Shape;
+using nncc::contrib::core::data::util::transposeTensor;
IrVisitor::IrVisitor()
{
// This is needed because TFLite convolution weights are stored as NHWC, and we use HWCN.
// TODO: Currently this is only used by the interpreter and shape inference,
// don't forget to change this if tensor shape processing architecture changes.
- paramsForOp.emplace_back(common::transposeTensor<1, 2, 3, 0>(tensor));
+ paramsForOp.emplace_back(transposeTensor<1, 2, 3, 0>(tensor));
}
else
{