ONE - On-device Neural Engine
Loading...
Searching...
No Matches
BCQFullyConnected.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "BCQFullyConnected.h"
18
19#include "Convert.h"
20
21namespace circlechef
22{
23
24void CircleOpBCQFullyConnected::filler(const circle::Operator *op, CircleImport *import,
25 circlechef::ModelRecipe *model_recipe) const
26{
27 const std::vector<int32_t> &inputs = as_index_vector(op->inputs());
28
29 import->set_tensor_filler(inputs[1]);
30 import->set_tensor_filler(inputs[3]);
31
32 const circle::Tensor *tensor2 = import->tensors()->Get(inputs[2]);
33 assert(tensor2->type() == circle::TensorType::TensorType_INT32);
34 const circle::Buffer *buffer2 = import->buffers()->Get(tensor2->buffer());
35 auto vec2 = extract_buffer<int32_t>(buffer2);
36 import->set_tensor_filler(inputs[2], vec2);
37
38 const circle::Tensor *tensor4 = import->tensors()->Get(inputs[4]);
39 assert(tensor4->type() == circle::TensorType::TensorType_INT32);
40 const circle::Buffer *buffer4 = import->buffers()->Get(tensor4->buffer());
41 auto vec4 = extract_buffer<int32_t>(buffer4);
42 import->set_tensor_filler(inputs[4], vec4);
43}
44
45circlechef::Operation *CircleOpBCQFullyConnected::build(const circle::Operator *op,
46 CircleImport *import,
47 circlechef::ModelRecipe *model_recipe) const
48{
49 auto op_params = op->builtin_options_as_BCQFullyConnectedOptions();
50 assert(op_params != nullptr);
51
52 auto operation = model_recipe->add_operation();
53
54 operation->set_type("BCQFullyConnected");
55
56 auto op_options = operation->mutable_bcq_fully_connected_options();
57
58 op_options->set_weights_hidden_size(op_params->weights_hidden_size());
59 op_options->set_activation(as_circlechef_activation(op_params->fused_activation_function()));
60
61 return operation;
62}
63
64} // namespace circlechef
Loads TF lite file and provides helpers to access attributes.
void filler(const circle::Operator *op, CircleImport *import, circlechef::ModelRecipe *model_recipe) const override
circlechef::Operation * build(const circle::Operator *op, CircleImport *import, circlechef::ModelRecipe *model_recipe) const override
std::vector< T > as_index_vector(const flatbuffers::Vector< T > *flat_array)
Definition Convert.h:43
circlechef::Activation as_circlechef_activation(const circle::ActivationFunctionType type)
Definition Convert.cpp:55