ONE - On-device Neural Engine
Loading...
Searching...
No Matches
BCQGather.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 "BCQGather.h"
18
19#include "Convert.h"
20
21namespace circlechef
22{
23
24void CircleOpBCQGather::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[0]);
30
31 const circle::Tensor *tensor1 = import->tensors()->Get(inputs[1]);
32 assert(tensor1->type() == circle::TensorType::TensorType_INT32);
33 const circle::Buffer *buffer1 = import->buffers()->Get(tensor1->buffer());
34 auto vec1 = extract_buffer<int32_t>(buffer1);
35 import->set_tensor_filler(inputs[1], vec1);
36
37 const circle::Tensor *tensor2 = import->tensors()->Get(inputs[2]);
38 assert(tensor2->type() == circle::TensorType::TensorType_INT32);
39 const circle::Buffer *buffer2 = import->buffers()->Get(tensor2->buffer());
40 auto vec2 = extract_buffer<int32_t>(buffer2);
41 import->set_tensor_filler(inputs[2], vec2);
42
43 const circle::Tensor *tensor3 = import->tensors()->Get(inputs[3]);
44 assert(tensor3->type() == circle::TensorType::TensorType_INT32);
45 const circle::Buffer *buffer3 = import->buffers()->Get(tensor3->buffer());
46 auto vec3 = extract_buffer<int32_t>(buffer3);
47 import->set_tensor_filler(inputs[3], vec3);
48}
49
50circlechef::Operation *CircleOpBCQGather::build(const circle::Operator *op, CircleImport *import,
51 circlechef::ModelRecipe *model_recipe) const
52{
53 auto op_params = op->builtin_options_as_BCQGatherOptions();
54 assert(op_params != nullptr);
55
56 auto operation = model_recipe->add_operation();
57
58 operation->set_type("BCQGather");
59
60 auto op_options = operation->mutable_bcq_gather_options();
61
62 op_options->set_input_hidden_size(op_params->input_hidden_size());
63 op_options->set_axis(op_params->axis());
64
65 return operation;
66}
67
68} // namespace circlechef
Loads TF lite file and provides helpers to access attributes.
circlechef::Operation * build(const circle::Operator *op, CircleImport *import, circlechef::ModelRecipe *model_recipe) const override
Definition BCQGather.cpp:50
void filler(const circle::Operator *op, CircleImport *import, circlechef::ModelRecipe *model_recipe) const override
Definition BCQGather.cpp:24
std::vector< T > as_index_vector(const flatbuffers::Vector< T > *flat_array)
Definition Convert.h:43