2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __ONERT_EXEC_EXEC_TIME_H__
18 #define __ONERT_EXEC_EXEC_TIME_H__
20 #include "backend/Backend.h"
21 #include "backend/IConfig.h"
22 #include "JSONExecTime.h"
26 #include <unordered_map>
36 explicit ExecTime(const std::vector<const backend::Backend *> &backends)
37 : _json(backends, _measurements)
43 * @brief Get exec time of an operation with input size
44 * or linearly interpolated value based on size if there is no record for given size
46 * @param[in] backend id of a backend
47 * @param[in] operation name of an operation
48 * @param[in] quant if input type quantized
49 * @param[in] op_size sum of operation's flattened sizes of inputs and outputs
50 * @return execution time for given input sizes
51 * -1 if there are no records for given parameters (backend, op, quantization).
53 int64_t getOperationExecTime(const backend::Backend *backend, const std::string &operation,
54 bool quant, uint32_t op_size) const;
56 * @brief Update exec time of the operation on a backend with given input size or
57 * add new entity if there is no one.
59 * @param[in] backend id of a backend
60 * @param[in] operation name of an operation
61 * @param[in] quant if input type quantized
62 * @param[in] op_size sum of operation's flattened sizes of inputs and outputs
63 * @param[in] time real measured value
65 void updateOperationExecTime(const backend::Backend *backend, const std::string &operation,
66 bool quant, uint32_t op_size, int64_t time);
68 * @brief Get the permute time from one backend to another
70 * @param[in] from_backend
71 * @param[in] to_backend
72 * @param[in] quant if input type quantized
73 * @param[in] op_size sum of operation's flattened sizes of inputs and outputs
74 * @return permutation time for operation size
76 int64_t getPermuteTime(const backend::Backend *from_backend, const backend::Backend *to_backend,
77 bool quant, uint32_t op_size) const;
79 * @brief Update permute time from one backend to another
81 * @param[in] from_backend
82 * @param[in] to_backend
83 * @param[in] quant if input type quantized
84 * @param[in] time measured permutation time
85 * @param[in] op_size sum of operation's flattened sizes of inputs and outputs
87 void updatePermuteTime(const backend::Backend *from_backend, const backend::Backend *to_backend,
88 bool quant, uint32_t op_size, int64_t time);
90 * @brief Get the max value of int32_t in int64_t
93 static int64_t getMax() { return _MAX; }
95 * @brief Update metrics file with new data.
97 void uploadOperationsExecTime() const { _json.uploadOperationsExecTime(); }
98 static const int64_t NOT_FOUND = -1;
101 /// @brief Measurement data, which is shared with serializer
102 MeasurementData _measurements;
103 // int64_t::max may cause integer overflow
104 static const int64_t _MAX = std::numeric_limits<int32_t>::max();
105 /// @brief Serializer
112 #endif // __ONERT_EXEC_EXEC_TIME_H__