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.
19 #include "backend/IConfig.h"
20 #include "backend/Backend.h"
22 #include <gtest/gtest.h>
28 using namespace onert;
30 using namespace backend;
32 struct MockConfig : public IConfig
34 std::string id() override { return "b1"; }
35 bool initialize() override { return true; };
36 bool supportPermutation() override { return false; }
37 ir::Layout supportLayout(const ir::Operation &, ir::Layout) override
39 return ir::Layout::UNKNOWN;
41 bool supportDynamicTensor() override { return false; }
42 bool supportFP16() override { return false; }
45 struct MockBackend : public ::onert::backend::Backend
47 std::shared_ptr<onert::backend::IConfig> config() const override
49 return std::make_shared<MockConfig>();
51 std::unique_ptr<onert::backend::BackendContext> newContext(ContextData &&) const override
57 TEST(ExecTime, roundtrip_ok)
59 const auto *b = new MockBackend();
60 std::vector<const Backend *> bs = {b};
63 et.updateOperationExecTime(b, "op1", true, 100, 100);
64 et.updateOperationExecTime(b, "op1", true, 200, 200);
65 et.updateOperationExecTime(b, "op1", false, 100, 888);
66 et.storeOperationsExecTime();
70 auto time = et.getOperationExecTime(b, "op1", true, 100);
72 // Check interpolation
73 time = et.getOperationExecTime(b, "op1", true, 150);
75 time = et.getOperationExecTime(b, "op1", false, 100);
77 et.storeOperationsExecTime();
80 EXPECT_EQ(remove("exec_time.json"), 0);
83 TEST(ExecTime, structure)
86 const auto *b = new MockBackend();
87 std::vector<const Backend *> bs = {b};
90 et.updateOperationExecTime(b, "op1", true, 100, 100);
91 et.updateOperationExecTime(b, "op1", true, 200, 200);
92 et.storeOperationsExecTime();
96 auto time = et.getOperationExecTime(b, "op1", true, 100);
98 // Check interpolation
99 time = et.getOperationExecTime(b, "op1", true, 200);
100 ASSERT_EQ(time, 200);
101 et.storeOperationsExecTime();
104 EXPECT_EQ(remove("exec_time.json"), 0);
106 } // unnamed namespace