17 #include <arm_compute/runtime/NEON/functions/NEFullyConnectedLayer.h>
21 using namespace armcomputetensorutils;
31 const arm_compute::TensorInfo aclInput = BuildArmComputeTensorInfo(input);
32 const arm_compute::TensorInfo aclOutput = BuildArmComputeTensorInfo(output);
33 arm_compute::TensorInfo aclWeights = BuildArmComputeTensorInfo(weights);
34 aclWeights.set_are_values_constant(weights.
IsConstant());
36 arm_compute::TensorInfo aclBiases;
37 arm_compute::TensorInfo* optionalAclBiases =
nullptr;
41 aclBiases = BuildArmComputeTensorInfo(biases.
value());
42 aclBiases.set_are_values_constant(biases.
value().IsConstant());
43 optionalAclBiases = &aclBiases;
46 const arm_compute::FullyConnectedLayerInfo fullyConnectedLayerInfo =
48 return arm_compute::NEFullyConnectedLayer::validate(&aclInput,
52 fullyConnectedLayerInfo);
62 arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(
m_Data.
m_Inputs[0])->GetTensor();
63 arm_compute::ITensor& weights = PolymorphicDowncast<IAclTensorHandle*>(
m_Data.
m_Inputs[1])->GetTensor();
64 m_WeightsTensorInfo =
info.m_InputTensorInfos[1];
65 weights.info()->set_are_values_constant(m_WeightsTensorInfo.
IsConstant());
66 arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(
m_Data.
m_Outputs[0])->GetTensor();
70 m_WeightsTensor = std::make_unique<arm_compute::Tensor>();
71 BuildArmComputeTensor(*m_WeightsTensor, m_WeightsTensorInfo);
72 m_WeightsTensor->info()->set_are_values_constant(m_WeightsTensorInfo.
IsConstant());
78 m_BiasesTensor = std::make_unique<arm_compute::Tensor>();
79 m_BiasesTensorInfo =
info.m_InputTensorInfos[2];
80 BuildArmComputeTensor(*m_BiasesTensor, m_BiasesTensorInfo);
81 m_BiasesTensor->info()->set_are_values_constant(m_BiasesTensorInfo.
IsConstant());
85 arm_compute::FullyConnectedLayerInfo fc_info =
88 auto layer = std::make_unique<arm_compute::NEFullyConnectedLayer>(memoryManager);
91 layer->configure(&input, m_WeightsTensor.get(), m_BiasesTensor.get(), &output, fc_info);
95 layer->configure(&input, &weights, m_BiasesTensor.get(), &output, fc_info);
97 m_FullyConnectedLayer.reset(layer.release());
121 m_WeightsTensor->info()->set_are_values_constant(m_WeightsTensorInfo.
IsConstant());
127 m_BiasesTensor->info()->set_are_values_constant(m_BiasesTensorInfo.
IsConstant());
131 FreeTensorIfUnused(m_WeightsTensor);
135 FreeTensorIfUnused(m_BiasesTensor);
139 m_FullyConnectedLayer->run();