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_JSON_EXEC_TIME_H__
18 #define __ONERT_EXEC_JSON_EXEC_TIME_H__
21 #include <unordered_map>
24 #include "backend/Backend.h"
25 #include "backend/IConfig.h"
33 * @brief table, that contains execution time of an operation on some backend for different input
34 * sizes and transfer time from one backend to another for various input sizes (permutation time)
36 * backend -> op -> quant-> size --> time
37 * _measurements[Backend*]["string"][bool][uint32_t] = int64_t
39 using MeasurementData = std::unordered_map<
40 const backend::Backend *,
41 std::unordered_map<std::string, std::unordered_map<bool, std::map<uint32_t, int64_t>>>>;
46 explicit JSON(const std::vector<const backend::Backend *> &backends,
47 MeasurementData &measurements)
48 : _measurement_file("exec_time.json"), _backends(), _measurements(measurements)
50 for (const auto b : backends)
52 _backends.emplace(b->config()->id(), b);
54 loadOperationsExecTime();
57 * @brief Update _operations_exec_time_file with new data.
59 void uploadOperationsExecTime() const;
62 ///@brief file containing measurements
63 std::string _measurement_file;
64 std::unordered_map<std::string, const backend::Backend *> _backends;
66 const backend::Backend *,
67 std::unordered_map<std::string, std::unordered_map<bool, std::map<uint32_t, int64_t>>>>
70 * @brief Helper function for inserting data to OperationExecTimes
72 * @param backend String name of backend
73 * @param operation String name of operation
74 * @param quant if input type quantized
75 * @param stream File stream
77 void readOperation(const std::string &backend, const std::string &operation, bool quant,
78 std::ifstream &stream);
81 * @brief Helper function for writing OperationExecTimes to stream
83 * @param operation_info Map of operations execution information
84 * @param stream File stream
86 void printOperation(const std::map<uint32_t, int64_t> &operation_info,
87 std::ofstream &stream) const;
89 * @brief Parse and load operations_exec_time from _operations_exec_time_file.
91 void loadOperationsExecTime();
97 #endif // __ONERT_EXEC_JSON_EXEC_TIME_H__