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

#include <FullyConnectedLayer.h>

Collaboration diagram for onert::backend::ggml::ops::FullyConnectedLayer:

Public Member Functions

 FullyConnectedLayer ()
 
 ~FullyConnectedLayer ()
 
void fullyConnectedGGMLWeight ()
 
void configure (const IPortableTensor *input, const IPortableTensor *weights, const IPortableTensor *bias, ir::Activation activation, IPortableTensor *output, const std::shared_ptr< ExternalContext > &external_context)
 
void run () override
 
void prepare () override
 
- Public Member Functions inherited from onert::exec::IFunction
virtual ~IFunction ()=default
 

Protected Attributes

const IPortableTensor_input
 
const IPortableTensor_weights
 
const IPortableTensor_bias
 
IPortableTensor_output
 
ir::Activation _activation
 
std::shared_ptr< ExternalContext_external_context
 

Detailed Description

Definition at line 29 of file FullyConnectedLayer.h.

Constructor & Destructor Documentation

◆ FullyConnectedLayer()

onert::backend::ggml::ops::FullyConnectedLayer::FullyConnectedLayer ( )

◆ ~FullyConnectedLayer()

onert::backend::ggml::ops::FullyConnectedLayer::~FullyConnectedLayer ( )
default

Member Function Documentation

◆ configure()

void onert::backend::ggml::ops::FullyConnectedLayer::configure ( const IPortableTensor input,
const IPortableTensor weights,
const IPortableTensor bias,
ir::Activation  activation,
IPortableTensor output,
const std::shared_ptr< ExternalContext > &  external_context 
)

Definition at line 118 of file FullyConnectedLayer.cc.

122{
123 _input = input;
124 _weights = weights;
125 _bias = bias;
126 _activation = activation;
127 _output = output;
128 _external_context = external_context;
129}

References _activation, _bias, _external_context, _input, _output, and _weights.

◆ fullyConnectedGGMLWeight()

void onert::backend::ggml::ops::FullyConnectedLayer::fullyConnectedGGMLWeight ( )

Definition at line 85 of file FullyConnectedLayer.cc.

86{
87 if (_bias)
88 throw std::runtime_error{"FullyConnected: GGML weights format does not support bias yet."};
89
90 // convert tensor
92 auto weights = getGGMLTensor(_weights);
94 {
95 output.op = GGML_OP_MUL_MAT;
96 output.src[0] = &weights;
97 output.src[1] = &input;
98 }
99 auto *nodes = &output;
100
101 // create graph
102 struct ggml_cgraph graph;
103 {
104 memset(&graph, 0, sizeof(graph));
105 graph.n_nodes = 1;
106 graph.nodes = &nodes;
107 }
108
109 // get cplan
110 auto cplan = ggml_graph_plan(&graph, _external_context->maxNumThreads());
111 std::vector<uint8_t> buf(cplan.work_size);
112 cplan.work_data = buf.data();
113
114 // compute
115 ggml_graph_compute(&graph, &cplan);
116}
struct ggml_tensor getGGMLTensor(const IPortableTensor *tensor)
Definition GGMLHelper.cc:41

References _bias, _external_context, _input, _output, _weights, and onert::backend::ggml::ops::getGGMLTensor().

Referenced by run().

◆ prepare()

void onert::backend::ggml::ops::FullyConnectedLayer::prepare ( )
overridevirtual

Reimplemented from onert::exec::IFunction.

Definition at line 144 of file FullyConnectedLayer.cc.

145{
146 // DO NOTHING
147}

◆ run()

void onert::backend::ggml::ops::FullyConnectedLayer::run ( )
overridevirtual

Implements onert::exec::IFunction.

Definition at line 131 of file FullyConnectedLayer.cc.

132{
133 if (_weights->data_type() == ir::DataType::QUANT_GGML_Q4_0 ||
134 _weights->data_type() == ir::DataType::QUANT_GGML_Q8_0)
135 {
137 }
138 else
139 {
140 throw std::runtime_error{"FullyConnected: unsupported data type"};
141 }
142}
ir::DataType data_type() const override final

References _weights, onert::backend::IPortableTensor::data_type(), and fullyConnectedGGMLWeight().

Field Documentation

◆ _activation

ir::Activation onert::backend::ggml::ops::FullyConnectedLayer::_activation
protected

Definition at line 51 of file FullyConnectedLayer.h.

Referenced by configure().

◆ _bias

const IPortableTensor* onert::backend::ggml::ops::FullyConnectedLayer::_bias
protected

Definition at line 49 of file FullyConnectedLayer.h.

Referenced by configure(), and fullyConnectedGGMLWeight().

◆ _external_context

std::shared_ptr<ExternalContext> onert::backend::ggml::ops::FullyConnectedLayer::_external_context
protected

Definition at line 53 of file FullyConnectedLayer.h.

Referenced by configure(), and fullyConnectedGGMLWeight().

◆ _input

const IPortableTensor* onert::backend::ggml::ops::FullyConnectedLayer::_input
protected

Definition at line 47 of file FullyConnectedLayer.h.

Referenced by configure(), and fullyConnectedGGMLWeight().

◆ _output

IPortableTensor* onert::backend::ggml::ops::FullyConnectedLayer::_output
protected

Definition at line 50 of file FullyConnectedLayer.h.

Referenced by configure(), and fullyConnectedGGMLWeight().

◆ _weights

const IPortableTensor* onert::backend::ggml::ops::FullyConnectedLayer::_weights
protected

Definition at line 48 of file FullyConnectedLayer.h.

Referenced by configure(), fullyConnectedGGMLWeight(), and run().


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