ONE - On-device Neural Engine
Loading...
Searching...
No Matches
arm_compute::NEFullyConnectedReshapingLayer Class Reference

Class to run FullyConnected Layer after reshaping input tensor. More...

#include <NEFullyConnectedReshapingLayer.h>

Collaboration diagram for arm_compute::NEFullyConnectedReshapingLayer:

Public Types

enum class  KernelType { GENERAL , PREPROCESSED_WEIGHTS }
 

Public Member Functions

 NEFullyConnectedReshapingLayer (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 
void configure (const arm_compute::ITensor *input, const arm_compute::ITensor *weights, const arm_compute::ITensor *biases, arm_compute::ITensor *output, bool needs_reshape, const arm_compute::TensorShape &reshape, KernelType kernel_type)
 Configure the layer.
 
void run (void) override
 Run the operation. Must be called after configure().
 
void prepare (void) override
 Prepare the operation.
 

Detailed Description

Class to run FullyConnected Layer after reshaping input tensor.

Definition at line 35 of file NEFullyConnectedReshapingLayer.h.

Member Enumeration Documentation

◆ KernelType

Enumerator
GENERAL 
PREPROCESSED_WEIGHTS 

Definition at line 38 of file NEFullyConnectedReshapingLayer.h.

39 {
40 GENERAL, //< General FC
41 PREPROCESSED_WEIGHTS //< Weights are constants so it can be preprocessed
42 };

Constructor & Destructor Documentation

◆ NEFullyConnectedReshapingLayer()

arm_compute::NEFullyConnectedReshapingLayer::NEFullyConnectedReshapingLayer ( std::shared_ptr< IMemoryManager >  memory_manager = nullptr)
inline

Definition at line 45 of file NEFullyConnectedReshapingLayer.h.

46 : _memory_manager{memory_manager}, _input(nullptr), _weights(nullptr), _biases(nullptr),
47 _output(nullptr), _neon_buffer{}, _neon_fc{nullptr}, _neon_reshape{}, _needs_reshape(false)
48 {
49 // DO NOTHING
50 }

Member Function Documentation

◆ configure()

void NEFullyConnectedReshapingLayer::configure ( const arm_compute::ITensor *  input,
const arm_compute::ITensor *  weights,
const arm_compute::ITensor *  biases,
arm_compute::ITensor *  output,
bool  needs_reshape,
const arm_compute::TensorShape &  reshape,
KernelType  kernel_type 
)

Configure the layer.

Parameters
[in]inputThe source tensor
[in]weightsThe tensor that is filled with weight values
[in]biasesThe tensor that is filled with biase values
[in]outputThe destination tensor
[in]needs_reshapeWhether it needs to be reshaped or not
[in]reshapeThe tensor shape to be reshaped. Only valid when needs_reshape is true.
[in]kernel_typeThe kernel type for actual FullyConnected layer
Returns
N/A

Definition at line 27 of file NEFullyConnectedReshapingLayer.cpp.

33{
34 _input = input;
35 _weights = weights;
36 _biases = biases;
37 _output = output;
38 _needs_reshape = needs_reshape;
39
40 const ITensor *input_to_use = input;
41 if (_needs_reshape)
42 {
43 // reshape
44 auto_init_if_empty(*_neon_buffer.info(),
45 _input->info()->clone()->set_tensor_shape(reshape).set_data_layout(
46 _input->info()->data_layout()));
47 _neon_reshape.configure(_input, &_neon_buffer);
48 input_to_use = &_neon_buffer;
49 }
50
51 _neon_fc = [&]() {
52 if (kernel_type == KernelType::GENERAL)
53 {
54 auto fc = new arm_compute::NEFullyConnectedLayerEx{_memory_manager};
55 fc->configure(input_to_use, _weights, _biases, _output);
56 return std::unique_ptr<arm_compute::IFunction>(fc);
57 }
58 else if (kernel_type == KernelType::PREPROCESSED_WEIGHTS)
59 {
60 bool is_hybrid = (input->info()->data_type() == DataType::F32 ||
61 input->info()->data_type() == DataType::F16) &&
62 (weights->info()->data_type() == DataType::QSYMM8 ||
63 weights->info()->data_type() == DataType::QASYMM8_SIGNED);
64
65 if (is_hybrid)
66 {
67 auto fc = new arm_compute::NEFullyConnectedHybridLayer{_memory_manager};
68 ITensorInfo *weights_info = const_cast<ITensorInfo *>(_weights->info());
69 const auto orgin_weights_data_type = weights_info->data_type();
70 weights_info->set_data_type(DataType::QASYMM8_SIGNED);
71 fc->configure(input_to_use, _weights, _biases, _output);
72 weights_info->set_data_type(orgin_weights_data_type);
73 return std::unique_ptr<arm_compute::IFunction>(fc);
74 }
75 else
76 {
77 auto fc = new arm_compute::NEFullyConnectedLayer{_memory_manager};
78 fc->configure(input_to_use, _weights, _biases, _output);
79 return std::unique_ptr<arm_compute::IFunction>(fc);
80 }
81 }
82 else
83 {
84 throw std::runtime_error("NEFullyConnectedReshapingLayer: Unsupported kernel type");
85 }
86 }();
87
88 // NOTE _neon_buffer is inaccessible from outside, and thus it is safe to invoke allocate here.
89 if (_needs_reshape)
90 {
91 _neon_buffer.allocator()->allocate();
92 }
93}

References GENERAL, and PREPROCESSED_WEIGHTS.

◆ prepare()

void NEFullyConnectedReshapingLayer::prepare ( void  )
override

Prepare the operation.

Returns
N/A

Definition at line 103 of file NEFullyConnectedReshapingLayer.cpp.

103{ _neon_fc->prepare(); }

◆ run()

void NEFullyConnectedReshapingLayer::run ( void  )
override

Run the operation. Must be called after configure().

Returns
N/A

Definition at line 95 of file NEFullyConnectedReshapingLayer.cpp.

96{
97 if (_needs_reshape)
98 _neon_reshape.run();
99
100 _neon_fc->run();
101}

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


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