This comit adds permutation type member into PermuteNode.
Signed-off-by: jiseob.jang <jiseob.jang@samsung.com>
out_shape.dim(3) = shape.dim(2);
}
- // Find Permutation Type
- auto permuteType = [&]() {
+ const auto permute_type = node.getPermuteType();
+ // Check Permutation Type
+ const auto inferPermuteType = [&]() {
if (input_object->ptr()->layout() == model::Layout::NHWC &&
output_object->ptr()->layout() == model::Layout::NCHW)
{
return model::operation::PermuteNode::Type::COPY;
}
}();
+ UNUSED_RELEASE(inferPermuteType);
+ assert(permute_type == inferPermuteType);
- fn->configure(input_object, output_object, out_shape, permuteType, data_type);
+ fn->configure(input_object, output_object, out_shape, permute_type, data_type);
input_backend_ctx->tensor_builder->postVisit(node);
public:
PermuteNode(const OperandIndex &input, const OperandIndex &output,
const backend::BackendContext *input_backend_ctx,
- const backend::BackendContext *output_backend_ctx,
+ const backend::BackendContext *output_backend_ctx, Type type,
model::DataType data_type = model::DataType::FLOAT32);
public:
const Param ¶m() const { return _param; }
model::DataType getDataType() const { return _dataType; }
+ Type getPermuteType() const { return _type; }
private:
Param _param;
+ Type _type;
model::DataType _dataType;
};
void Dumper::visit(const PermuteNode &node)
{
- VERBOSE(LIR) << "* Permute" << std::endl;
+ std::string permute_type = "Unknown";
+ switch (node.getPermuteType())
+ {
+ case PermuteNode::Type::COPY:
+ permute_type = "Copy";
+ break;
+ case PermuteNode::Type::NHWC_TO_NCHW:
+ permute_type = "NHWC to NCHW";
+ break;
+ case PermuteNode::Type::NCHW_TO_NHWC:
+ permute_type = "NCHW to NHWC";
+ break;
+ }
+
+ VERBOSE(LIR) << "* Permute(" + permute_type + ")" << std::endl;
VERBOSE(LIR) << " - Inputs : Input(" << node.getInputs().at(0).value() << ")" << std::endl;
VERBOSE(LIR) << " - Output : Output(" << node.getOutputs().at(0).value() << ")" << std::endl;
}
auto output_backend_ctx = _graph.backend_resolver()->getBackendContext(output_backend);
// Insert permute operation to the graph
+ const auto input_layout =
+ _graph.getLowerInfo(operand_index)->def_factors().getOnlyElement().layout();
+ const auto output_layout = factor.layout();
using PermuteNode = model::operation::PermuteNode;
- auto insert_node = nnfw::cpp14::make_unique<PermuteNode>(operand_index, out_operand_index,
- input_backend_ctx, output_backend_ctx);
+ const auto permute_type = [&]() {
+ if (input_layout == model::Layout::NHWC && output_layout == model::Layout::NCHW)
+ {
+ return PermuteNode::Type::NHWC_TO_NCHW;
+ }
+ else if (input_layout == model::Layout::NCHW && output_layout == model::Layout::NHWC)
+ {
+ return PermuteNode::Type::NCHW_TO_NHWC;
+ }
+ else
+ {
+ return PermuteNode::Type::COPY;
+ }
+ }();
+ auto insert_node = nnfw::cpp14::make_unique<PermuteNode>(
+ operand_index, out_operand_index, input_backend_ctx, output_backend_ctx, permute_type);
auto node_index = _graph.operations().push(std::move(insert_node));
const auto &node = _graph.operations().at(node_index);
PermuteNode::PermuteNode(const OperandIndex &input, const OperandIndex &output,
const backend::BackendContext *input_backend_ctx,
- const backend::BackendContext *output_backend_ctx,
+ const backend::BackendContext *output_backend_ctx, Type type,
model::DataType data_type)
: model::Operation{OperandConstraint::createExact(1u)},
- _param{input_backend_ctx, output_backend_ctx}, _dataType{data_type}
+ _param{input_backend_ctx, output_backend_ctx}, _type{type}, _dataType{data_type}
{
setInputs({input});
setOutputs({output});