ONE - On-device Neural Engine
Loading...
Searching...
No Matches
FullyConnected.h File Reference
#include "Shape.h"
#include <cstdint>

Go to the source code of this file.

Functions

bool fullyConnectedPrepare (const Shape &input, const Shape &weights, const Shape &bias, Shape *output)
 

Function Documentation

◆ fullyConnectedPrepare()

bool fullyConnectedPrepare ( const Shape input,
const Shape weights,
const Shape bias,
Shape output 
)

Definition at line 28 of file FullyConnected.cpp.

30{
31 // Check all the parameters of tensor match within themselves and match the
32 // input configuration.
33 ASSERT(input.type == weights.type);
34 if (input.type == OperandType::TENSOR_QUANT8_ASYMM)
35 {
36 ASSERT(bias.type == OperandType::TENSOR_INT32);
37 }
38 else
39 {
40 ASSERT(input.type == bias.type);
41 }
42 ASSERT(getNumberOfDimensions(input) >= 2);
43 uint32_t input_size = getNumberOfElements(input);
44 uint32_t num_units = getSizeOfDimension(weights, 0);
45
46 // modified to resolve Coverity 118949 (Apr 25, 2018) by hyunsik.yoon
47 // Original Code:
48 // uint32_t batch_size = input_size / getSizeOfDimension(weights, 1);
49 //
50 // Coverity Detection: Division by zero
51 //
52 // Code below is modified code
53
54 uint32_t shape_size = getSizeOfDimension(weights, 1);
55 if (shape_size == 0)
56 {
57 return false;
58 }
59
60 uint32_t batch_size = input_size / shape_size;
61
62 ASSERT(getSizeOfDimension(bias, 0) == num_units);
63 ASSERT(getSizeOfDimension(weights, 1) * batch_size == input_size);
64 ASSERT(getNumberOfDimensions(weights) == 2);
65
66 output->type = input.type;
67 output->dimensions = {batch_size, num_units};
68
69 return true;
70}
#define ASSERT(v)
Definition Assert.h:24
uint32_t getNumberOfElements(const Shape &shape)
Definition Shape.cpp:48
uint32_t getSizeOfDimension(const Shape &shape, uint32_t dimensionIdx)
Definition Shape.cpp:60
uint32_t getNumberOfDimensions(const Shape &shape)
Definition Shape.cpp:58
OperandType type
Definition Shape.h:29

References ASSERT, getNumberOfDimensions(), getNumberOfElements(), getSizeOfDimension(), and Shape::type.