forked from Samsung/ONE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKernelGenerator.cc
More file actions
70 lines (58 loc) · 2.29 KB
/
KernelGenerator.cc
File metadata and controls
70 lines (58 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "KernelGenerator.h"
#include <exec/DynamicShapeInferer.h>
#include <memory>
#include <stdexcept>
namespace onert::backend::cpu
{
KernelGenerator::KernelGenerator(const ir::Graph &graph,
const std::shared_ptr<TensorBuilder> &tensor_builder,
const std::shared_ptr<basic::TensorRegistry> &tensor_reg,
const std::shared_ptr<ExternalContext> &external_context)
: basic::KernelGeneratorBase{graph}, _ctx(graph.operands()), _operations_ctx{graph.operations()},
_tensor_builder(tensor_builder), _tensor_reg{tensor_reg}, _external_context(external_context)
{
// DO NOTHING
}
std::unique_ptr<exec::FunctionSequence> KernelGenerator::generate(ir::OperationIndex ind)
{
auto ret = std::make_unique<exec::FunctionSequence>();
assert(_tensor_builder->dynamicTensorManager());
assert(_tensor_reg);
// Prepare to handle dynamic tensors later
auto dyn_ctx = std::make_shared<exec::FunctionSequence::DynamicTensorCtx>();
{
dyn_ctx->op = &_operations_ctx.at(ind);
dyn_ctx->dynamic_shape_inferer = std::make_shared<exec::DynamicShapeInferer>(_tensor_reg);
}
ret->dynamic_tensor_ctx(dyn_ctx);
auto &op = _graph.operations().at(ind);
op.accept(*this);
assert(_return_fn); // _return_fn must have been generated
ret->append(std::move(_return_fn));
for (auto &&ind : (op.getInputs() | ir::Remove::UNDEFINED) + op.getOutputs())
{
auto tensor = _tensor_reg->getNativeTensor(ind);
if (tensor)
{
tensor->increase_ref();
}
}
return ret;
}
// Visitors for each operation is in ops/<InternalName>Layer.cc file
} // namespace onert::backend::cpu