ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::backend::cpu::ops::TransposeLayer Class Reference

#include <TransposeLayer.h>

Collaboration diagram for onert::backend::cpu::ops::TransposeLayer:

Public Member Functions

 TransposeLayer ()
 
template<typename T >
void transpose ()
 
void transposeQuant8 ()
 
void configure (const IPortableTensor *input, const IPortableTensor *perm, IPortableTensor *output)
 
void run () override
 
- Public Member Functions inherited from onert::exec::IFunction
virtual ~IFunction ()=default
 
virtual void prepare ()
 

Detailed Description

Definition at line 33 of file TransposeLayer.h.

Constructor & Destructor Documentation

◆ TransposeLayer()

onert::backend::cpu::ops::TransposeLayer::TransposeLayer ( )

Definition at line 33 of file TransposeLayer.cc.

33 : _input(nullptr), _perm(nullptr), _output(nullptr)
34{
35 // DO NOTHING
36}

Member Function Documentation

◆ configure()

void onert::backend::cpu::ops::TransposeLayer::configure ( const IPortableTensor input,
const IPortableTensor perm,
IPortableTensor output 
)

Definition at line 80 of file TransposeLayer.cc.

82{
83 _input = input;
84 _perm = perm;
85 _output = output;
86}

◆ run()

void onert::backend::cpu::ops::TransposeLayer::run ( )
overridevirtual

Implements onert::exec::IFunction.

Definition at line 88 of file TransposeLayer.cc.

89{
90 if (_input->data_type() == OperandType::FLOAT32)
91 {
92 transpose<float>();
93 }
94 else if (_input->data_type() == OperandType::INT32)
95 {
96 transpose<int32_t>();
97 }
98 else if (_input->data_type() == OperandType::QUANT_UINT8_ASYMM)
99 {
101 }
102 else
103 {
104 throw std::runtime_error{"Transpose: unsupported data type"};
105 }
106}
ir::DataType data_type() const override final

References onert::backend::IPortableTensor::data_type(), and transposeQuant8().

Referenced by package.infer.session::inference().

◆ transpose()

template<typename T >
void onert::backend::cpu::ops::TransposeLayer::transpose ( )

Definition at line 38 of file TransposeLayer.cc.

39{
41 auto perm_shape = _perm->getShape();
42 assert(perm_shape.rank() == 1);
43
44 param.perm_count = _input->getShape().rank();
45 if (perm_shape.dim(0) == 0) // This means _perm is (n-1...0)
46 {
47 const auto begin = param.perm;
48 const auto end = param.perm + _input->getShape().rank();
49 std::iota(begin, end, 0);
50 std::reverse(begin, end);
51 }
52 else
53 {
54 assert(param.perm_count == static_cast<int>(perm_shape.dim(0)));
55 for (auto i = 0; i < param.perm_count; i++)
56 {
57 param.perm[i] = *(getBuffer<int32_t>(_perm) + i);
58 }
59 }
60
61 nnfw::cker::Transpose(param, getShape(_input), getBuffer<T>(_input), getShape(_output),
62 getBuffer<T>(_output));
63}
ir::Shape getShape() const override final
Get ir::Shape of tensor.
ShapeIterator end(const Shape &s)
void Transpose(const TransposeParams &unshrunk_params, const Shape &unshrunk_input_shape, const T *input_data, const Shape &unshrunk_output_shape, T *output_data)
Definition Transpose.h:509
nnfw::cker::Shape getShape(const IPortableTensor *tensor)
int32_t begin[5]
Definition Slice.cpp:33

References begin, onert::backend::IPortableTensor::getShape(), onert::backend::cpu::ops::getShape(), nnfw::cker::TransposeParams::perm, nnfw::cker::TransposeParams::perm_count, and nnfw::cker::Transpose().

◆ transposeQuant8()

void onert::backend::cpu::ops::TransposeLayer::transposeQuant8 ( )

Definition at line 65 of file TransposeLayer.cc.

66{
67 if (_input->data_zero_point() != _output->data_zero_point())
68 {
69 throw std::runtime_error("TransposeLayer : qassym8 input and output offsets unmatched");
70 }
71
72 if (_input->data_scale() != _output->data_scale())
73 {
74 throw std::runtime_error("TransposeLayer : qassym8 input and output scales unmatched");
75 }
76
77 transpose<uint8_t>();
78}
float data_scale() const override final
int32_t data_zero_point() const override final

References onert::backend::IPortableTensor::data_scale(), and onert::backend::IPortableTensor::data_zero_point().

Referenced by run().


The documentation for this class was generated from the following files: