30 : _input(nullptr), _weights(nullptr), _bias(nullptr), _output(nullptr),
31 _activation(ir::Activation::
NONE), _temp_arena(new
nnfw::cker::FCTempArena()),
32 _external_context(nullptr), _is_hybrid(false), _is_shuffled16x1float32(false)
42 float output_activation_min = 0;
43 float output_activation_max = 0;
63 double real_multiplier = 0.0;
64 int32_t output_multiplier = 0;
65 int32_t output_shift = 0;
66 int32_t output_activation_min = 0;
67 int32_t output_activation_max = 0;
71 &output_activation_max);
108 (_cached_weights) ?
reinterpret_cast<const int8_t *
>(_cached_weights)
113 if (_cached_weights ==
nullptr || _is_weights_freed)
126 auto weight_tensor = nnfw::misc::polymorphic_downcast<const Tensor *>(
_weights);
130 auto tensor =
const_cast<Tensor *
>(weight_tensor);
131 if (tensor->buffer() ==
nullptr)
133 _is_weights_freed =
true;
137 tensor->decrease_ref();
138 if (tensor->buffer() ==
nullptr)
140#if defined(__ANDROID__) && (__ANDROID_API__ >= 26)
144 _is_weights_freed =
true;
158 if (block_size.size() == 0)
165 else if (block_size.size() == 2 && block_size[0] == 16 && block_size[1] == 1)
173 throw std::runtime_error{
"FullyConnected: unsupported sparsity"};
179 throw std::runtime_error{
"FullyConnected: GGML weights format does not support bias yet."};
186 output.op = GGML_OP_MUL_MAT;
187 output.src[0] = &weights;
188 output.src[1] = &input;
190 auto *nodes = &output;
193 struct ggml_cgraph graph;
195 memset(&graph, 0,
sizeof(graph));
197 graph.nodes = &nodes;
202 std::vector<uint8_t> buf(cplan.work_size);
203 cplan.work_data = buf.data();
206 ggml_graph_compute(&graph, &cplan);
211#if defined(__aarch64__) && defined(USE_NEON)
212 float output_activation_min = 0, output_activation_max = 0;
223 throw std::runtime_error{
"FullyConnected: Shuffled16x1Float32 weights_format is not supported."};
231 const std::shared_ptr<ExternalContext> &external_context)
238 _is_hybrid = input->data_type() == OperandType::FLOAT32 &&
239 weights->
data_type() == OperandType::QUANT_INT8_SYMM;
241#if !defined(__aarch64__) || !defined(USE_NEON)
244 throw std::runtime_error{
245 "FullyConnected: Shuffled16x1Float32 weights_format is not supported."};
280 throw std::runtime_error{
"FullyConnected: unsupported data type"};
295#if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && defined(USE_RUY_GEMV)
void prepare(const Shape &input_shape, const Shape &weights_shape)
int32_t Dims(int i) const
A tensor class that is portable for other backends.
const ir::Sparsity * sparsity() const
float data_scale() const override final
int32_t data_zero_point() const override final
ir::DataType data_type() const override final
bool is_dynamic() const override final
Return true if the tensor needs dynamic allocation, meaning that during compile-time the outpus shape...
bool is_constant() const override final
Return true if the tensor is constant.
virtual uint8_t * buffer() const =0
ir::Activation _activation
void fullyConnected16x1Float32()
void fullyConnectedSparseWeight()
const IPortableTensor * _weights
const IPortableTensor * _bias
bool _is_shuffled16x1float32
void fullyConnectedFloat32()
IPortableTensor * _output
std::unique_ptr< nnfw::cker::FCTempArena > _temp_arena
std::shared_ptr< ExternalContext > _external_context
const IPortableTensor * _input
void fullyConnectedHybrid()
void fullyConnectedGGMLWeight()
void configure(const IPortableTensor *input, const IPortableTensor *weights, const IPortableTensor *bias, ir::Activation activation, ir::FullyConnectedWeightsFormat weights_format, IPortableTensor *output, const std::shared_ptr< ExternalContext > &external_context)
void fullyConnectedQuant8()
void FullyConnectedSparseWeightRandom(const FullyConnectedParams ¶ms, const Shape &input_shape, const float *input_data, const Shape &weights_shape, const float *weights_data, const Shape &bias_shape, const float *bias_data, const Shape &output_shape, float *output_data, const uint16_t *w1_segments, const uint16_t *w1_indices)
void FullyConnectedSparseWeight16x1(const FullyConnectedParams ¶ms, const Shape &input_shape, const float *input_data, const Shape &weights_shape, const float *weights_data, const Shape &bias_shape, const float *bias_data, const Shape &output_shape, float *output_data, const uint16_t *w1_segments, const uint16_t *w1_indices)
void FullyConnectedHybrid(const FullyConnectedParams ¶ms, const Shape &input_shape, const float *input_data, const Shape &filter_shape, const int8_t *filter_data, const Shape &, const float *bias_data, const Shape &output_shape, float *output_data, FCTempArena &temp_arena, ruy::Context *ruy_context)
void FullyConnected(const FullyConnectedParams ¶ms, const Shape &input_shape, const float *input_data, const Shape &weights_shape, const float *weights_data, const Shape &, const float *bias_data, const Shape &, float *output_data)
bool IsZeroVector(const float *vector, int v_size)
nnfw::cker::FusedActivationFunctionType convertActivationType(const ir::Activation activation)
nnfw::cker::Shape getShape(const IPortableTensor *tensor)
struct ggml_tensor getGGMLTensor(const IPortableTensor *tensor)
void QuantizeMultiplier(double double_multiplier, int32_t *quantized_multiplier, int *shift)
void CalculateActivationRangeQuantized(ir::Activation activation, const IPortableTensor *output, int32_t *act_min, int32_t *act_max)
void GetQuantizedConvolutionMultiplier(const IPortableTensor *input, const IPortableTensor *filter, const IPortableTensor *bias, const IPortableTensor *output, double *multiplier)
FullyConnectedWeightsFormat
void CalculateActivationRange(ir::Activation activation, T *activation_min, T *activation_max)
int32_t output_multiplier
FusedActivationFunctionType activation
float float_activation_max
int32_t quantized_activation_min
float float_activation_min
int32_t quantized_activation_max
const std::vector< int32_t > & block_size() const
Returns block size which is used for block sparsity.
const uint16_t * w1_segments() const
Returns segments array. See compressed sparse row format.
const uint16_t * w1_indices() const
Returns indices array. See compressed sparse row format.