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 #include "exec/ExecTime.h"
18 #include "backend/IConfig.h"
19 #include "backend/Backend.h"
20 #include <gtest/gtest.h>
25 using namespace onert;
27 using namespace backend;
29 struct MockConfig : public IConfig
31 std::string id() override { return "b1"; }
32 bool initialize() override { return true; };
33 bool supportPermutation() override { return false; }
34 ir::Layout supportLayout(const ir::Operation &, ir::Layout) override
36 return ir::Layout::UNKNOWN;
38 bool supportDynamicTensor() override { return false; }
39 bool supportFP16() override { return false; }
42 struct MockBackend : public ::onert::backend::Backend
44 std::shared_ptr<onert::backend::IConfig> config() const override
46 return std::make_shared<MockConfig>();
48 std::unique_ptr<BackendContext> newContext(const ir::Graph &,
49 const std::shared_ptr<custom::IKernelBuilder> &kb,
56 TEST(ExecTime, roundtrip_ok)
58 const auto *b = new MockBackend();
59 std::vector<const Backend *> bs = {b};
62 et.updateOperationExecTime(b, "op1", true, 100, 100);
63 et.updateOperationExecTime(b, "op1", true, 200, 200);
64 et.updateOperationExecTime(b, "op1", false, 100, 888);
65 et.uploadOperationsExecTime();
69 auto time = et.getOperationExecTime(b, "op1", true, 100);
71 // Check interpolation
72 time = et.getOperationExecTime(b, "op1", true, 150);
74 time = et.getOperationExecTime(b, "op1", false, 100);
76 et.uploadOperationsExecTime();
79 EXPECT_EQ(remove("exec_time.json"), 0);
82 TEST(ExecTime, structure)
85 const auto *b = new MockBackend();
86 std::vector<const Backend *> bs = {b};
89 et.updateOperationExecTime(b, "op1", true, 100, 100);
90 et.updateOperationExecTime(b, "op1", true, 200, 200);
91 et.uploadOperationsExecTime();
95 auto time = et.getOperationExecTime(b, "op1", true, 100);
97 // Check interpolation
98 time = et.getOperationExecTime(b, "op1", true, 200);
100 et.uploadOperationsExecTime();
103 EXPECT_EQ(remove("exec_time.json"), 0);
105 } // unnamed namespace