ONE - On-device Neural Engine
Loading...
Searching...
No Matches
BackendContext.h
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#ifndef __ONERT_BACKEND_XNNPACK_BACKEND_CONTEXT_H__
18#define __ONERT_BACKEND_XNNPACK_BACKEND_CONTEXT_H__
19
21#include <util/ConfigSource.h>
22#include "TensorBuilder.h"
23#include "KernelGenerator.h"
24#include "ExternalContext.h"
25
27
28namespace onert
29{
30namespace backend
31{
32namespace xnnpack
33{
34
36{
37public:
39 std::shared_ptr<ITensorRegistry> tensor_registry = nullptr,
40 std::shared_ptr<TensorBuilder> tensor_builder = nullptr,
41 std::shared_ptr<KernelGenerator> kernel_gen = nullptr)
43 tensor_builder{tensor_builder}, kernel_gen{kernel_gen}, _external_context(nullptr)
44 {
45 int num_threads = util::getConfigInt(util::config::NUM_THREADS);
46 if (num_threads < 1)
47 num_threads = kDefaultNumThreadpoolThreads; // default num of threads
48 _external_context.reset(new ExternalContext(static_cast<size_t>(num_threads)));
49 }
50
51 ITensorRegistry *genTensors() override;
52 FunctionMap genKernels() override;
53
54 std::shared_ptr<ExternalContext> external_context() { return _external_context; }
55
56public:
57 // TODO Make it private
58 std::shared_ptr<TensorBuilder> tensor_builder;
59 std::shared_ptr<KernelGenerator> kernel_gen;
60
61private:
62 std::shared_ptr<ExternalContext> _external_context;
63};
64
65} // namespace xnnpack
66} // namespace backend
67} // namespace onert
68
69#endif // __ONERT_BACKEND_XNNPACK_BACKEND_CONTEXT_H__
const int kDefaultNumThreadpoolThreads
std::shared_ptr< ITensorRegistry > tensor_registry
const ContextData & data() const
const Backend * backend() const
std::shared_ptr< ExternalContext > external_context()
std::shared_ptr< TensorBuilder > tensor_builder
ITensorRegistry * genTensors() override
std::shared_ptr< KernelGenerator > kernel_gen
BackendContext(const Backend *backend, ContextData &&data, std::shared_ptr< ITensorRegistry > tensor_registry=nullptr, std::shared_ptr< TensorBuilder > tensor_builder=nullptr, std::shared_ptr< KernelGenerator > kernel_gen=nullptr)
std::unordered_map< ir::OperationIndex, std::unique_ptr< exec::FunctionSequence > > FunctionMap
int getConfigInt(const std::string &key)