Imported Upstream version 1.9.0
[platform/core/ml/nnfw.git] / runtime / libs / benchmark / include / benchmark / Phases.h
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 __NNFW_BENCHMARK_PHASES_H__
18 #define __NNFW_BENCHMARK_PHASES_H__
19
20 #include "Phase.h"
21 #include "MemoryPoller.h"
22
23 #include <string>
24 #include <functional>
25 #include <unordered_map>
26
27 namespace benchmark
28 {
29
30 class Phases
31 {
32 public:
33   Phases(const PhaseOption &option);
34
35   using PhaseFunc = std::function<void(const Phase &, uint32_t)>;
36
37   void run(const std::string &tag, const PhaseFunc &exec, uint32_t loop_num = 1,
38            bool option_disable = false)
39   {
40     run(tag, exec, nullptr, loop_num, option_disable);
41   }
42
43   void run(const std::string &tag, const PhaseFunc &exec, const PhaseFunc &post,
44            uint32_t loop_num = 1, bool option_disable = false)
45   {
46     run(tag, exec, &post, loop_num, option_disable);
47   }
48
49   const PhaseOption &option() const { return _option; }
50   const MemoryPoller &mem_poll() const { return *_mem_poll; }
51   const Phase &at(const std::string &tag) const { return _phases.at(tag); }
52
53 private:
54   void run(const std::string &tag, const PhaseFunc &exec, const PhaseFunc *post, uint32_t loop_num,
55            bool option_disable);
56
57 private:
58   const PhaseOption _option;
59   std::unordered_map<std::string, Phase> _phases;
60   std::unique_ptr<MemoryPoller> _mem_poll;
61 };
62
63 } // namespace benchmark
64
65 #endif // __NNFW_BENCHMARK_PHASES_H__