* Move `TypeInfo.h` and `Shape.h` in `ir` directory.
* Move `TypeInfo`, `Shape`, `FeatureShape` to `neurun::ir` namespace, fixing uses where possible.
Signed-off-by: Sergei Barannikov <s.barannikov@samsung.com>
// Check for reshaping input's shape into rank-2
bool needs_reshape = false;
- neurun::model::Shape reshape(2);
+ ir::Shape reshape(2);
if (input_rank == 4)
{
const auto feature_size = _ctx.at(input_index).shape().num_elements();
// TODO remove const_cast later. For example, _ctx may need to be a non const variable or
// a node to extend shape may be inserted in front of this operation
- const_cast<::neurun::model::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
}
}
{
const auto output_index{node.getOutputs().at(0)};
if (_ctx.at(output_index).shape().rank() == 0)
- const_cast<::neurun::model::Shape &>(_ctx.at(output_index).shape()).extendRank(1);
+ const_cast<ir::Shape &>(_ctx.at(output_index).shape()).extendRank(1);
const auto input_index{node.getInputs().at(model::operation::Squeeze::Input::INPUT)};
_tensor_builder->dimCorrection(input_index, false);
_tensor_builder->dimCorrection(output_index, false);
{
const auto broadcast_rank =
std::max(_ctx.at(lhs_index).shape().rank(), _ctx.at(rhs_index).shape().rank());
- const_cast<::neurun::model::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
}
}
// TODO remove const_cast later. For example, _ctx may need to be a non const variable or
// a node to extend shape may be inserted in front of this operation
- const_cast<::neurun::model::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
}
}
// TODO remove const_cast later. For example, _ctx may need to be a non const variable or
// a node to extend shape may be inserted in front of this operation
- const_cast<::neurun::model::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
}
}
// TODO remove const_cast later. For example, _ctx may need to be a non const variable or
// a node to extend shape may be inserted in front of this operation
- const_cast<::neurun::model::Shape &>(_ctx.at(input0_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(input1_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(input0_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(input1_index).shape()).extendRank(broadcast_rank);
}
}
// TODO remove const_cast later. For example, _ctx may need to be a non const variable or
// a node to extend shape may be inserted in front of this operation
- const_cast<::neurun::model::Shape &>(_ctx.at(input0_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(input1_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(input0_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(input1_index).shape()).extendRank(broadcast_rank);
}
}
{
const auto broadcast_rank =
std::max(_ctx.at(ifm_index).shape().rank(), _ctx.at(alpha_index).shape().rank());
- const_cast<::neurun::model::Shape &>(_ctx.at(ifm_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(alpha_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(ifm_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(alpha_index).shape()).extendRank(broadcast_rank);
}
}
{
const auto broadcast_rank =
std::max(_ctx.at(input0_index).shape().rank(), _ctx.at(input1_index).shape().rank());
- const_cast<::neurun::model::Shape &>(_ctx.at(input0_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(input1_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(input0_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(input1_index).shape()).extendRank(broadcast_rank);
}
}
{
const auto broadcast_rank =
std::max(_ctx.at(lhs_index).shape().rank(), _ctx.at(rhs_index).shape().rank());
- const_cast<neurun::model::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
- const_cast<neurun::model::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
}
}
namespace acl_common
{
-::arm_compute::TensorShape asTensorShape(const ::neurun::model::Shape &shape,
- ir::Layout frontend_layout, ir::Layout backend_layout,
- bool apply_dim_correction)
+::arm_compute::TensorShape asTensorShape(const ir::Shape &shape, ir::Layout frontend_layout,
+ ir::Layout backend_layout, bool apply_dim_correction)
{
const uint32_t rank = shape.rank();
return ::arm_compute::QuantizationInfo(scale, offset);
}
-::arm_compute::TensorInfo asTensorInfo(const ::neurun::model::Shape &shape,
- const ::neurun::model::TypeInfo &typeInfo,
+::arm_compute::TensorInfo asTensorInfo(const ir::Shape &shape, const ir::TypeInfo &typeInfo,
ir::Layout frontend_layout, ir::Layout backend_layout,
bool apply_dim_correction)
{
#include "ir/Layout.h"
#include "ir/InternalType.h"
#include "model/Operand.h"
-#include "model/Shape.h"
-#include "model/TypeInfo.h"
+#include "ir/Shape.h"
+#include "ir/TypeInfo.h"
#include "misc/feature/Shape.h"
#include "misc/kernel/Shape.h"
namespace acl_common
{
-::arm_compute::TensorShape asTensorShape(const ::neurun::model::Shape &shape,
- ir::Layout frontend_layout, ir::Layout backend_layout,
+::arm_compute::TensorShape asTensorShape(const ir::Shape &shape, ir::Layout frontend_layout,
+ ir::Layout backend_layout,
bool apply_dim_correction = true);
::arm_compute::Coordinates asTensorCoordinate(const ::neurun::util::Coordinates &coord,
ir::Layout frontend_layout,
ir::Layout backend_layout);
::arm_compute::DataType asDataType(ir::DataType type);
-::arm_compute::TensorInfo asTensorInfo(const ::neurun::model::Shape &shape,
- const ::neurun::model::TypeInfo &typeInfo,
+::arm_compute::TensorInfo asTensorInfo(const ir::Shape &shape, const ir::TypeInfo &typeInfo,
ir::Layout frontend_layout, ir::Layout backend_layout,
bool apply_dim_correction = true);
// Check for reshaping input's shape into rank-2
bool needs_reshape = false;
- neurun::model::Shape reshape(2);
+ ir::Shape reshape(2);
if (input_rank == 4)
{
- model::FeatureShape ifm_shape_feature =
+ ir::FeatureShape ifm_shape_feature =
_ctx.at(input_index).shape().asFeature(_current_subg_layout);
auto feature_size =
ifm_shape_feature.N * ifm_shape_feature.C * ifm_shape_feature.H * ifm_shape_feature.W;
// TODO remove const_cast later. For example, _ctx may need to be a non const variable or
// a node to extend shape may be inserted in front of this operation
- const_cast<::neurun::model::Shape &>(_ctx.at(input0_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(input1_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(input0_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(input1_index).shape()).extendRank(broadcast_rank);
}
}
// TODO remove const_cast later. For example, _ctx may need to be a non const variable or
// a node to extend shape may be inserted in front of this operation
- const_cast<::neurun::model::Shape &>(_ctx.at(input0_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(input1_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(input0_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(input1_index).shape()).extendRank(broadcast_rank);
}
}
// TODO remove const_cast later. For example, _ctx may need to be a non const variable or
// a node to extend shape may be inserted in front of this operation
- const_cast<::neurun::model::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
}
}
{
const auto broadcast_rank =
std::max(_ctx.at(ifm_index).shape().rank(), _ctx.at(alpha_index).shape().rank());
- const_cast<::neurun::model::Shape &>(_ctx.at(ifm_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(alpha_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(ifm_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(alpha_index).shape()).extendRank(broadcast_rank);
}
}
// TODO remove const_cast later. For example, _ctx may need to be a non const variable or
// a node to extend shape may be inserted in front of this operation
- const_cast<::neurun::model::Shape &>(_ctx.at(input0_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(input1_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(input0_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(input1_index).shape()).extendRank(broadcast_rank);
}
}
// TODO remove const_cast later. For example, _ctx may need to be a non const variable or
// a node to extend shape may be inserted in front of this operation
- const_cast<::neurun::model::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
}
}
std::max(_ctx.at(lhs_index).shape().rank(), _ctx.at(rhs_index).shape().rank());
// TODO remove const_cast later. For example, _ctx may need to be a non const variable or
// a node to extend shape may be inserted in front of this operation
- const_cast<::neurun::model::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
}
}
{
const auto broadcast_rank =
std::max(_ctx.at(lhs_index).shape().rank(), _ctx.at(rhs_index).shape().rank());
- const_cast<::neurun::model::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
}
}
// TODO remove const_cast later. For example, _ctx may need to be a non const variable or
// a node to extend shape may be inserted in front of this operation
- const_cast<::neurun::model::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
}
}
throw std::runtime_error{"ShapeFixer: NYI for broadcast Add"};
const auto broadcast_rank =
std::max(_ctx.at(lhs_index).shape().rank(), _ctx.at(rhs_index).shape().rank());
- const_cast<::neurun::model::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
}
}
throw std::runtime_error{"ShapeFixer: NYI for broadcast Sub"};
const auto broadcast_rank =
std::max(_ctx.at(lhs_index).shape().rank(), _ctx.at(rhs_index).shape().rank());
- const_cast<::neurun::model::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
}
}
void ShapeFixer::visit(const model::operation::Mul &node)
throw std::runtime_error{"ShapeFixer: NYI for broadcast Mul"};
const auto broadcast_rank =
std::max(_ctx.at(lhs_index).shape().rank(), _ctx.at(rhs_index).shape().rank());
- const_cast<::neurun::model::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
- const_cast<::neurun::model::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(lhs_index).shape()).extendRank(broadcast_rank);
+ const_cast<ir::Shape &>(_ctx.at(rhs_index).shape()).extendRank(broadcast_rank);
}
}
void PermuteLayer::configure(std::shared_ptr<backend::operand::ITensor> input,
std::shared_ptr<backend::operand::ITensor> output,
- const model::Shape &output_shape, Type type, ir::DataType dataType)
+ const ir::Shape &output_shape, Type type, ir::DataType dataType)
{
_input = input;
_output = output;
public:
void configure(std::shared_ptr<backend::operand::ITensor> input,
- std::shared_ptr<backend::operand::ITensor> output,
- const model::Shape &output_shape, model::operation::Permute::Type type,
- ir::DataType dataType);
+ std::shared_ptr<backend::operand::ITensor> output, const ir::Shape &output_shape,
+ model::operation::Permute::Type type, ir::DataType dataType);
void run();
void runSync()
{
private:
std::shared_ptr<backend::operand::ITensor> _input{nullptr};
std::shared_ptr<backend::operand::ITensor> _output{nullptr};
- model::Shape _output_shape{};
+ ir::Shape _output_shape{};
model::operation::Permute::Type _type{model::operation::Permute::Type::COPY};
ir::DataType _dataType{ir::DataType::FLOAT32};
};
namespace srcn
{
-model::Shape asKernelShape(const model::Shape &shape, kernel::FilterLayout frontend_layout,
- kernel::FilterLayout backend_layout)
+ir::Shape asKernelShape(const ir::Shape &shape, kernel::FilterLayout frontend_layout,
+ kernel::FilterLayout backend_layout)
{
assert(shape.rank() == 4);
if (frontend_layout == backend_layout)
{
- return model::Shape{shape.dim(0), shape.dim(1), shape.dim(2), shape.dim(3)};
+ return ir::Shape{shape.dim(0), shape.dim(1), shape.dim(2), shape.dim(3)};
}
const auto permutation = getFilterPermutation(frontend_layout, backend_layout);
{
throw std::runtime_error("Not supported FilterLayout");
}
- return model::Shape{shape.dim(permutation[0]), shape.dim(permutation[1]),
- shape.dim(permutation[2]), shape.dim(permutation[3])};
+ return ir::Shape{shape.dim(permutation[0]), shape.dim(permutation[1]), shape.dim(permutation[2]),
+ shape.dim(permutation[3])};
}
-model::Shape asTensorShape(const model::Shape &shape, ir::Layout frontend_layout,
- ir::Layout backend_layout)
+ir::Shape asTensorShape(const ir::Shape &shape, ir::Layout frontend_layout,
+ ir::Layout backend_layout)
{
const uint32_t rank = shape.rank();
- model::Shape ret(rank);
+ ir::Shape ret(rank);
for (uint32_t axis = 0; axis < rank; ++axis)
{
const auto ncnn_axis = ToNCNNAxis(rank, axis, frontend_layout, backend_layout);
return ret;
}
-model::OperandInfo asTensorInfo(const model::Shape &shape, const model::TypeInfo &typeInfo,
+model::OperandInfo asTensorInfo(const ir::Shape &shape, const ir::TypeInfo &typeInfo,
ir::Layout frontend_layout, ir::Layout backend_layout)
{
model::OperandInfo info(asTensorShape(shape, frontend_layout, backend_layout), typeInfo);
#include "kernel/OperationUtils.h"
#include <ir/Layout.h>
-#include <model/Shape.h>
-#include <model/TypeInfo.h>
+#include <ir/Shape.h>
+#include <ir/TypeInfo.h>
#include <model/OperandInfo.h>
namespace neurun
namespace srcn
{
-model::Shape asKernelShape(const model::Shape &shape, kernel::FilterLayout frontend_layout,
- kernel::FilterLayout backend_layout);
+ir::Shape asKernelShape(const ir::Shape &shape, kernel::FilterLayout frontend_layout,
+ kernel::FilterLayout backend_layout);
-model::Shape asTensorShape(const model::Shape &shape, ir::Layout frontend_layout,
- ir::Layout backend_layout);
+ir::Shape asTensorShape(const ir::Shape &shape, ir::Layout frontend_layout,
+ ir::Layout backend_layout);
-model::OperandInfo asTensorInfo(const model::Shape &shape, const model::TypeInfo &typeInfo,
+model::OperandInfo asTensorInfo(const ir::Shape &shape, const ir::TypeInfo &typeInfo,
ir::Layout frontend_layout, ir::Layout backend_layout);
} // namespace srcn
namespace
{
-neurun::model::Shape permuteTensorShape(const neurun::model::Shape &shape,
- neurun::ir::Layout frontend_layout,
- neurun::ir::Layout backend_layout)
+neurun::ir::Shape permuteTensorShape(const neurun::ir::Shape &shape,
+ neurun::ir::Layout frontend_layout,
+ neurun::ir::Layout backend_layout)
{
assert(shape.rank() <= 4);
- neurun::model::Shape backend_shape{shape};
+ neurun::ir::Shape backend_shape{shape};
if (shape.rank() == 4 && frontend_layout == neurun::ir::Layout::NHWC &&
backend_layout == neurun::ir::Layout::NCHW)
{
* @brief Return tensor shape
* @return Tensor shape
*/
- const model::Shape shape(void) const { return _shape; }
+ const ir::Shape &shape(void) const { return _shape; }
/**
* @brief Return tensor type
* @return Tensor type
*/
- const model::TypeInfo type(void) const { return _type; }
+ const ir::TypeInfo &type(void) const { return _type; }
/**
* @brief Return tensor's offset in parent tensor
* @return Tensor offset
private:
const model::OperandIndex _parent;
- const model::Shape _shape;
- const model::TypeInfo _type;
+ const ir::Shape _shape;
+ const ir::TypeInfo _type;
const neurun::util::Coordinates _offset;
};
* @param[in] length Input data's length
* @param[in] layout Input data's data format
*/
- void setInput(const model::IOIndex &index, const model::TypeInfo &type, const model::Shape &shape,
+ void setInput(const model::IOIndex &index, const ir::TypeInfo &type, const ir::Shape &shape,
const void *buffer, size_t length, ir::Layout layout = ir::Layout::NHWC);
/**
* @brief Set output data's information
* @param[in] length Output data's length
* @param[in] layout Output data's data format
*/
- void setOutput(const model::IOIndex &index, const model::TypeInfo &type,
- const model::Shape &shape, void *buffer, size_t length,
- ir::Layout layout = ir::Layout::NHWC);
+ void setOutput(const model::IOIndex &index, const ir::TypeInfo &type, const ir::Shape &shape,
+ void *buffer, size_t length, ir::Layout layout = ir::Layout::NHWC);
/**
* @brief Set input data's data format
* @param[in] index Input index
// Graph Building
public:
- model::OperandIndex addOperand(const model::Shape &shape, const model::TypeInfo &type);
+ model::OperandIndex addOperand(const ir::Shape &shape, const ir::TypeInfo &type);
model::OperationIndex addOperation(std::unique_ptr<model::Operation> &&node);
void setOperandValue(const model::OperandIndex &ind, std::unique_ptr<model::Data> &&data);
void addInput(const model::OperandIndex &ind);
* limitations under the License.
*/
-#ifndef __NEURUN_MODEL_SHAPE_H__
-#define __NEURUN_MODEL_SHAPE_H__
+#ifndef __NEURUN_IR_SHAPE_H__
+#define __NEURUN_IR_SHAPE_H__
#include "ir/Layout.h"
#include "misc/feature/Shape.h"
namespace neurun
{
-namespace model
+namespace ir
{
// TODO Remove this dependency.
inline bool operator==(const Shape &lhs, const Shape &rhs) { return lhs.dims() == rhs.dims(); }
+} // namespace ir
+
+// TODO Remove after merging 'graph' and 'model' namespaces.
+namespace model
+{
+using FeatureShape = ir::FeatureShape;
+using Shape = ir::Shape;
} // namespace model
} // namespace neurun
-#endif // __NEURUN_MODEL_SHAPE_H__
+#endif // __NEURUN_IR_SHAPE_H__
* limitations under the License.
*/
-#ifndef __NEURUN_MODEL_TYPEINFO_H__
-#define __NEURUN_MODEL_TYPEINFO_H__
+#ifndef __NEURUN_IR_TYPEINFO_H__
+#define __NEURUN_IR_TYPEINFO_H__
#include <cstdint>
namespace neurun
{
-namespace model
+namespace ir
{
class TypeInfo
bool operator==(const TypeInfo &lhs, const TypeInfo &rhs);
bool operator!=(const TypeInfo &lhs, const TypeInfo &rhs);
+} // namespace ir
+
+// TODO Remove after merging 'graph' and 'model' namespaces.
+namespace model
+{
+using TypeInfo = ir::TypeInfo;
} // namespace model
+
} // namespace neurun
-#endif // __NEURUN_MODEL_TYPEINFO_H__
+#endif // __NEURUN_IR_TYPEINFO_H__
#ifndef __NEURUN_MODEL_OPERAND_INFO_H__
#define __NEURUN_MODEL_OPERAND_INFO_H__
-#include "Shape.h"
-#include "TypeInfo.h"
+#include "ir/Shape.h"
+#include "ir/TypeInfo.h"
#include "ir/Layout.h"
namespace neurun
#include <stdint.h>
-#include "model/Shape.h"
+#include "ir/Shape.h"
#include "ir/InternalType.h"
namespace neurun
{
ir::ExplicitPadding validPadding(void);
-ir::ExplicitPadding samePadding(const model::FeatureShape &ifm_shape,
- const model::FeatureShape &ofm_shape, const ir::Stride &stride,
+ir::ExplicitPadding samePadding(const ir::FeatureShape &ifm_shape,
+ const ir::FeatureShape &ofm_shape, const ir::Stride &stride,
uint32_t kw, uint32_t kh);
-ir::ExplicitPadding calculatePadding(const ir::Padding &padding,
- const model::FeatureShape &ifm_shape,
- const model::FeatureShape &ofm_shape, const ir::Stride &stride,
+ir::ExplicitPadding calculatePadding(const ir::Padding &padding, const ir::FeatureShape &ifm_shape,
+ const ir::FeatureShape &ofm_shape, const ir::Stride &stride,
uint32_t kw, uint32_t kh);
} // namespace util
namespace shape_inference
{
-using Shapes = std::vector<model::Shape>;
+using Shapes = std::vector<ir::Shape>;
-Shapes inferEltwiseShape(const model::Shape &lhs_shape, const model::Shape &rhs_shape);
+Shapes inferEltwiseShape(const ir::Shape &lhs_shape, const ir::Shape &rhs_shape);
-Shapes inferAvgPoolShape(const model::Shape &in_shape,
- const model::operation::AvgPool2D::Param ¶m,
+Shapes inferAvgPoolShape(const ir::Shape &in_shape, const model::operation::AvgPool2D::Param ¶m,
ir::Layout layout = ir::Layout::NHWC);
Shapes inferConcatShape(const Shapes &in_shapes, const model::operation::Concat::Param ¶m);
-Shapes inferMaxPoolShape(const model::Shape &in_shape,
- const model::operation::MaxPool2D::Param ¶m,
+Shapes inferMaxPoolShape(const ir::Shape &in_shape, const model::operation::MaxPool2D::Param ¶m,
ir::Layout layout = ir::Layout::NHWC);
-Shapes inferConv2DShape(const model::Shape &in_shape, const model::Shape &ker_shape,
+Shapes inferConv2DShape(const ir::Shape &in_shape, const ir::Shape &ker_shape,
const model::operation::Conv2D::Param ¶m,
ir::Layout layout = ir::Layout::NHWC);
-Shapes inferDepthwiseConv2DShape(const model::Shape &in_shape, const model::Shape &ker_shape,
+Shapes inferDepthwiseConv2DShape(const ir::Shape &in_shape, const ir::Shape &ker_shape,
const model::operation::DepthwiseConv2D::Param ¶m,
ir::Layout layout = ir::Layout::NHWC);
-Shapes inferFullyConnectedShape(const model::Shape &in_shape, const model::Shape &ker_shape);
+Shapes inferFullyConnectedShape(const ir::Shape &in_shape, const ir::Shape &ker_shape);
} // namespace shape_inference
} // namespace neurun
}
// TODO Remove default parameter
-void Execution::setInput(const model::IOIndex &index, const model::TypeInfo &type,
- const model::Shape &shape, const void *buffer, size_t length,
+void Execution::setInput(const model::IOIndex &index, const ir::TypeInfo &type,
+ const ir::Shape &shape, const void *buffer, size_t length,
ir::Layout layout)
{
const model::OperandInfo info{shape, type};
}
// TODO Remove default parameter
-void Execution::setOutput(const model::IOIndex &index, const model::TypeInfo &type,
- const model::Shape &shape, void *buffer, size_t length, ir::Layout layout)
+void Execution::setOutput(const model::IOIndex &index, const ir::TypeInfo &type,
+ const ir::Shape &shape, void *buffer, size_t length, ir::Layout layout)
{
const model::OperandInfo info{shape, type};
// DO NOTHING
}
-std::unique_ptr<ISource> ExecutorBase::source(const model::IOIndex &index,
- const model::TypeInfo &type, const void *buffer,
- size_t length, ir::Layout io_layout)
+std::unique_ptr<ISource> ExecutorBase::source(const model::IOIndex &index, const ir::TypeInfo &type,
+ const void *buffer, size_t length,
+ ir::Layout io_layout)
{
using ir::DataType;
switch (type.type())
}
}
-std::unique_ptr<ISink> ExecutorBase::sink(const model::IOIndex &index, const model::TypeInfo &type,
+std::unique_ptr<ISink> ExecutorBase::sink(const model::IOIndex &index, const ir::TypeInfo &type,
void *buffer, size_t length, ir::Layout io_layout)
{
using ir::DataType;
void addObserver(std::unique_ptr<IExecutionObserver> ref) { _subject.add(std::move(ref)); };
private:
- std::unique_ptr<ISource> source(const model::IOIndex &index, const model::TypeInfo &type,
+ std::unique_ptr<ISource> source(const model::IOIndex &index, const ir::TypeInfo &type,
const void *buffer, size_t length, ir::Layout io_layout);
- std::unique_ptr<ISink> sink(const model::IOIndex &index, const model::TypeInfo &type,
- void *buffer, size_t length, ir::Layout io_layout);
+ std::unique_ptr<ISink> sink(const model::IOIndex &index, const ir::TypeInfo &type, void *buffer,
+ size_t length, ir::Layout io_layout);
template <typename T>
std::unique_ptr<ISource> source(const model::IOIndex &index, const void *buffer, size_t length,
template <typename T> class ITemplSink : public ISink
{
public:
- ITemplSink(void *output_buffer, const size_t &output_size, const model::Shape &shape,
+ ITemplSink(void *output_buffer, const size_t &output_size, const ir::Shape &shape,
const bool copy, ir::Layout io_layout)
: _output_buffer{reinterpret_cast<T *>(output_buffer)}, _output_size{output_size},
_shape{shape}, _copy{copy}, _io_layout{io_layout}
private:
T *_output_buffer;
const size_t _output_size;
- const model::Shape _shape;
+ const ir::Shape _shape;
const bool _copy;
const ir::Layout _io_layout;
};
template <typename T> class PermutateSink final : public ITemplSink<T>
{
public:
- PermutateSink(void *output_buffer, const size_t &output_size, const model::Shape &shape,
+ PermutateSink(void *output_buffer, const size_t &output_size, const ir::Shape &shape,
ir::Layout io_layout)
: ITemplSink<T>(output_buffer, output_size, shape, false, io_layout)
{
template <typename T> class CopySink final : public ITemplSink<T>
{
public:
- CopySink(void *output_buffer, const size_t &output_size, const model::Shape &shape,
+ CopySink(void *output_buffer, const size_t &output_size, const ir::Shape &shape,
ir::Layout io_layout = ir::Layout::UNKNOWN)
: ITemplSink<T>(output_buffer, output_size, shape, true, io_layout)
{
#include "util/Utils.h"
#include <misc/feature/IndexIterator.h>
#include <ir/Layout.h>
-#include "model/Shape.h"
+#include "ir/Shape.h"
namespace neurun
{
template <typename T> class ITemplSource : public ISource
{
public:
- ITemplSource(const void *input_buffer, const size_t &input_size, const model::Shape &shape,
+ ITemplSource(const void *input_buffer, const size_t &input_size, const ir::Shape &shape,
const bool copy, ir::Layout io_layout)
: _input_buffer{reinterpret_cast<const T *>(input_buffer)}, _input_size{input_size},
_shape{shape}, _copy(copy), _io_layout{io_layout}
private:
const T *_input_buffer;
const size_t _input_size;
- const model::Shape _shape;
+ const ir::Shape _shape;
const bool _copy;
const ir::Layout _io_layout;
};
template <typename T> class PermutateSource final : public ITemplSource<T>
{
public:
- PermutateSource(const void *input_buffer, const size_t &input_size, const model::Shape &shape,
+ PermutateSource(const void *input_buffer, const size_t &input_size, const ir::Shape &shape,
ir::Layout io_layout)
: ITemplSource<T>(input_buffer, input_size, shape, false, io_layout)
{
template <typename T> class CopySource final : public ITemplSource<T>
{
public:
- CopySource(const void *input_buffer, const size_t &input_size, const model::Shape &shape,
+ CopySource(const void *input_buffer, const size_t &input_size, const ir::Shape &shape,
ir::Layout io_layout = ir::Layout::UNKNOWN)
: ITemplSource<T>(input_buffer, input_size, shape, true, io_layout)
{
assert(num_units == bias_tensor->dimension(0));
// Make output tensor info
- model::Shape output_shape(2);
+ ir::Shape output_shape(2);
output_shape.dim(0) = batch_size;
output_shape.dim(1) = num_units;
const model::OperandInfo out_info{output_shape, in_tensor->tensorInfo().typeInfo()};
#ifndef __NEURUN_EXEC_INTERP_OPERATIONS_OPERATION_UTILS_H_
#define __NEURUN_EXEC_INTERP_OPERATIONS_OPERATION_UTILS_H_
-#include "model/Shape.h"
+#include "ir/Shape.h"
#include "ir/InternalType.h"
#include <cker/Shape.h>
namespace interp
{
-inline nnfw::cker::Shape convertShape(const model::Shape &shape)
+inline nnfw::cker::Shape convertShape(const ir::Shape &shape)
{
auto dimensions = std::vector<uint32_t>(shape.dims().begin(), shape.dims().end());
return nnfw::cker::GetShape(raw_shape);
}
-inline nnfw::cker::Shape convertExtendShape(const model::Shape &shape)
+inline nnfw::cker::Shape convertExtendShape(const ir::Shape &shape)
{
auto dimensions = std::vector<uint32_t>(shape.dims().begin(), shape.dims().end());
Graph::~Graph(void) = default;
-model::OperandIndex Graph::addOperand(const model::Shape &shape, const model::TypeInfo &type)
+model::OperandIndex Graph::addOperand(const ir::Shape &shape, const ir::TypeInfo &type)
{
return _operands.emplace(shape, type);
}
* limitations under the License.
*/
-#include "model/Shape.h"
+#include "ir/Shape.h"
#include "util/Utils.h"
#include <cassert>
namespace neurun
{
-namespace model
+namespace ir
{
FeatureShape Shape::asFeature(Layout layout) const
std::multiplies<uint64_t>());
}
-} // namespace model
+} // namespace ir
} // namespace neurun
* limitations under the License.
*/
-#include "model/TypeInfo.h"
+#include "ir/TypeInfo.h"
namespace neurun
{
-namespace model
+namespace ir
{
bool operator==(const TypeInfo &lhs, const TypeInfo &rhs)
bool operator!=(const TypeInfo &lhs, const TypeInfo &rhs) { return !(lhs == rhs); }
-} // namespace model
+} // namespace ir
} // namespace neurun
namespace operand
{
-inline LowerInfo::Shape4D asShape4D(const model::Shape &shape)
+inline LowerInfo::Shape4D asShape4D(const ir::Shape &shape)
{
switch (shape.rank())
{
return padding;
}
-ir::ExplicitPadding samePaddingUsingIFM(const model::FeatureShape &ifm_shape,
- const ir::Stride &stride, uint32_t kw, uint32_t kh)
+ir::ExplicitPadding samePaddingUsingIFM(const ir::FeatureShape &ifm_shape, const ir::Stride &stride,
+ uint32_t kw, uint32_t kh)
{
ir::ExplicitPadding padding;
return padding;
}
-ir::ExplicitPadding samePadding(const model::FeatureShape &ifm_shape,
- const model::FeatureShape &ofm_shape, const ir::Stride &stride,
+ir::ExplicitPadding samePadding(const ir::FeatureShape &ifm_shape,
+ const ir::FeatureShape &ofm_shape, const ir::Stride &stride,
uint32_t kw, uint32_t kh)
{
const int32_t vertical_expected_output = (ifm_shape.H + stride.vertical - 1) / stride.vertical;
return samePaddingUsingIFM(ifm_shape, stride, kw, kh);
}
-ir::ExplicitPadding calculatePadding(const ir::Padding &padding,
- const model::FeatureShape &ifm_shape,
- const model::FeatureShape &ofm_shape, const ir::Stride &stride,
+ir::ExplicitPadding calculatePadding(const ir::Padding &padding, const ir::FeatureShape &ifm_shape,
+ const ir::FeatureShape &ofm_shape, const ir::Stride &stride,
uint32_t kw, uint32_t kh)
{
if (padding.type == ir::PaddingType::EXPLICIT)
#include "util/Utils.h"
#include "ir/InternalType.h"
-#include "model/Shape.h"
+#include "ir/Shape.h"
#include "model/operation/AvgPool2D.h"
#include "model/operation/MaxPool2D.h"
#include "util/ShapeInference.h"
}
// Calculate the result of broadcast of two shapes
-model::Shape broadcastShapes(const model::Shape &lhs_shape, const model::Shape &rhs_shape)
+ir::Shape broadcastShapes(const ir::Shape &lhs_shape, const ir::Shape &rhs_shape)
{
- model::Shape out_shape;
+ ir::Shape out_shape;
auto max_rank = std::max(lhs_shape.rank(), rhs_shape.rank());
for (int idx = 0; idx < max_rank; ++idx)
// Shape inference
//
-Shapes inferEltwiseShape(const model::Shape &lhs_shape, const model::Shape &rhs_shape)
+Shapes inferEltwiseShape(const ir::Shape &lhs_shape, const ir::Shape &rhs_shape)
{
return {broadcastShapes(lhs_shape, rhs_shape)};
}
-Shapes inferAvgPoolShape(const model::Shape &in_shape,
- const model::operation::AvgPool2D::Param ¶m, const ir::Layout layout)
+Shapes inferAvgPoolShape(const ir::Shape &in_shape, const model::operation::AvgPool2D::Param ¶m,
+ const ir::Layout layout)
{
assert(layout == ir::Layout::NHWC);
auto ifm_shape = in_shape.asFeature(layout);
const auto out_h_w = calcConvLikeHeightAndWidth(ifm_shape.H, ifm_shape.W, param.kh, param.kw,
param.padding, param.stride);
// Pooling don't change number of channels and batch size
- return {model::Shape{ifm_shape.N, out_h_w.first, out_h_w.second, ifm_shape.C}};
+ return {ir::Shape{ifm_shape.N, out_h_w.first, out_h_w.second, ifm_shape.C}};
}
Shapes inferConcatShape(const Shapes &in_shapes, const model::operation::Concat::Param ¶m)
}
// Calculate output shape
- model::Shape out_shape(first_in_shape);
+ ir::Shape out_shape(first_in_shape);
out_shape.dim(concat_axis) = 0;
for (const auto &in_shape : in_shapes)
out_shape.dim(concat_axis) += in_shape.dim(concat_axis);
return {out_shape};
}
-Shapes inferMaxPoolShape(const model::Shape &in_shape,
- const model::operation::MaxPool2D::Param ¶m, const ir::Layout layout)
+Shapes inferMaxPoolShape(const ir::Shape &in_shape, const model::operation::MaxPool2D::Param ¶m,
+ const ir::Layout layout)
{
assert(layout == ir::Layout::NHWC);
auto ifm_shape = in_shape.asFeature(layout);
const auto out_h_w = calcConvLikeHeightAndWidth(ifm_shape.H, ifm_shape.W, param.kh, param.kw,
param.padding, param.stride);
// Pooling don't change number of channels and batch size
- return {model::Shape{ifm_shape.N, out_h_w.first, out_h_w.second, ifm_shape.C}};
+ return {ir::Shape{ifm_shape.N, out_h_w.first, out_h_w.second, ifm_shape.C}};
}
-Shapes inferConv2DShape(const model::Shape &in_shape, const model::Shape &ker_shape,
+Shapes inferConv2DShape(const ir::Shape &in_shape, const ir::Shape &ker_shape,
const model::operation::Conv2D::Param ¶m, ir::Layout layout)
{
assert(layout == ir::Layout::NHWC);
const auto out_h_w = calcConvLikeHeightAndWidth(ifm_shape.H, ifm_shape.W, kf_shape.H, kf_shape.W,
param.padding, param.stride);
- return {model::Shape{ifm_shape.N, out_h_w.first, out_h_w.second, kf_shape.N}};
+ return {ir::Shape{ifm_shape.N, out_h_w.first, out_h_w.second, kf_shape.N}};
}
-Shapes inferDepthwiseConv2DShape(const model::Shape &in_shape, const model::Shape &ker_shape,
+Shapes inferDepthwiseConv2DShape(const ir::Shape &in_shape, const ir::Shape &ker_shape,
const model::operation::DepthwiseConv2D::Param ¶m,
ir::Layout layout)
{
const auto out_h_w = calcConvLikeHeightAndWidth(ifm_shape.H, ifm_shape.W, kf_shape.H, kf_shape.W,
param.padding, param.stride);
- return {model::Shape{ifm_shape.N, out_h_w.first, out_h_w.second, kf_shape.C}};
+ return {ir::Shape{ifm_shape.N, out_h_w.first, out_h_w.second, kf_shape.C}};
}
-Shapes inferFullyConnectedShape(const model::Shape &in_shape, const model::Shape &ker_shape)
+Shapes inferFullyConnectedShape(const ir::Shape &in_shape, const ir::Shape &ker_shape)
{
assert(in_shape.rank() >= 2);
assert(ker_shape.rank() == 2);
const auto batch_size = input_size_with_batch / input_size;
assert(input_size_with_batch % input_size == 0);
- return {{model::Shape({static_cast<int32_t>(batch_size), num_units})}};
+ return {{ir::Shape({static_cast<int32_t>(batch_size), num_units})}};
}
} // namespace shape_inference
template <typename LoaderDomain, typename SpecificLoader>
model::OperandIndex BaseLoader<LoaderDomain, SpecificLoader>::loadOperand(const Tensor *tensor)
{
- model::Shape shape;
+ ir::Shape shape;
// Shape
const auto *tensor_shape = tensor->shape();
for (const auto &dim : *tensor_shape)
throw std::runtime_error("Custom Quantization is not supported");
}
// Create TypeInfo
- model::TypeInfo type_info(data_type, scale, zero_point);
+ ir::TypeInfo type_info(data_type, scale, zero_point);
// Create operand
const auto operand_index = _graph.addOperand(shape, type_info);
void BaseLoader<LoaderDomain, SpecificLoader>::loadStridesAndPaddings(Param ¶m,
const OptionsType *options)
{
- model::Shape shape;
// Strides
param.stride.vertical = options->stride_w();
param.stride.horizontal = options->stride_h();
// Strides and Paddings
loadStridesAndPaddings(param, options);
// Filter width and height
- model::Shape shape;
// Strides
param.kw = options->filter_width();
param.kh = options->filter_height();
param.activation = convertActivation(options->fused_activation_function());
loadStridesAndPaddings(param, options);
// Multiplier
- model::Shape shape;
param.multiplier = options->depth_multiplier();
// Dilation h/w factor unused
std::unique_ptr<model::Operation> new_op(
model::operation::Concat::Param param;
const auto *options = op->builtin_options_as_ConcatenationOptions();
// Axis
- model::Shape shape;
param.axis = options->axis();
// activation unused
#include <NeuralNetworks.h>
-#include <model/TypeInfo.h>
-#include <model/Shape.h>
+#include <ir/TypeInfo.h>
+#include <ir/Shape.h>
#include <ir/InternalType.h>
class NNAPIConvert
* @param[in] type NNAPI's operand type
* @return neurun's internal operand type info
*/
- static ::neurun::model::TypeInfo getTypeInfo(const ANeuralNetworksOperandType *type);
+ static neurun::ir::TypeInfo getTypeInfo(const ANeuralNetworksOperandType *type);
/**
* @brief Convert operand shape info from NNAPI to internal operand shape
* @param[in] type NNAPI's operand type
* @return neurun's internal operand shape
*/
- static ::neurun::model::Shape getShape(const ANeuralNetworksOperandType *type);
+ static neurun::ir::Shape getShape(const ANeuralNetworksOperandType *type);
/**
* @brief Calcaulate operand size from NNAPI type
#include <backend/ExecTime.h>
#include <backend/IShapeFixer.h>
-#include <model/Shape.h>
+#include <ir/Shape.h>
#include <ir/InternalType.h>
-#include <model/TypeInfo.h>
+#include <ir/TypeInfo.h>
#include <ir/DataType.h>
#include <model/operation/Add.h>
{
neurun::model::Operands set;
- ::neurun::model::Shape shape0{1, 2, 3};
+ neurun::ir::Shape shape0{1, 2, 3};
- ::neurun::model::Shape shape1(4);
+ neurun::ir::Shape shape1(4);
shape1.dim(0) = 10;
shape1.dim(1) = 20;
shape1.dim(2) = 30;
shape1.dim(3) = 40;
- ::neurun::model::TypeInfo type{neurun::ir::DataType::INT32};
+ neurun::ir::TypeInfo type{neurun::ir::DataType::INT32};
set.emplace(shape0, type);
set.emplace(shape1, type);
neurun::graph::Graph graph;
neurun::graph::verifier::DAGChecker verifier;
- neurun::model::Shape shape(3);
- neurun::model::TypeInfo type{neurun::ir::DataType::INT32};
+ neurun::ir::Shape shape(3);
+ neurun::ir::TypeInfo type{neurun::ir::DataType::INT32};
// Model Input/Output
auto input_operand = graph.addOperand(shape, type);
{
neurun::graph::Graph graph;
- neurun::model::Shape shape{3};
- neurun::model::TypeInfo type{neurun::ir::DataType::INT32};
+ neurun::ir::Shape shape{3};
+ neurun::ir::TypeInfo type{neurun::ir::DataType::INT32};
// Add Conv
using Graph = neurun::model::operation::Conv2D;
{
neurun::graph::Graph graph;
- neurun::model::Shape shape{3};
+ neurun::ir::Shape shape{3};
- neurun::model::TypeInfo type{neurun::ir::DataType::INT32};
+ neurun::ir::TypeInfo type{neurun::ir::DataType::INT32};
using Graph = neurun::model::operation::Concat;
{
neurun::graph::Graph graph;
- ::neurun::model::Shape shape{3};
- ::neurun::model::TypeInfo type{neurun::ir::DataType::INT32};
+ neurun::ir::Shape shape{3};
+ neurun::ir::TypeInfo type{neurun::ir::DataType::INT32};
auto operand1 = graph.addOperand(shape, type);
auto operand2 = graph.addOperand(shape, type);