提交 8e2d2bc3 编写于 作者: 刘琦

Merge branch 'update_tuner_test' into 'master'

update tuner test

See merge request !362
......@@ -20,7 +20,8 @@ class TunerTest : public ::testing::Test {
TEST_F(TunerTest, SimpleRun) {
int expect = 1;
auto TunerFunc = [&](const std::vector<unsigned int> &params) -> int {
auto TunerFunc = [&](const std::vector<unsigned int> &params, Timer *timer,
std::vector<uint32_t> *tuning_result) -> int {
if (params.front() == 1) {
return expect;
} else {
......@@ -43,13 +44,30 @@ TEST_F(TunerTest, SimpleRun) {
TEST_F(TunerTest, SimpleTune) {
int expect = 3;
auto TunerFunc = [&](const std::vector<unsigned int> &params) -> int {
if (params.front() == expect) {
return expect;
auto TunerFunc = [&](const std::vector<unsigned int> &params, Timer *timer,
std::vector<uint32_t> *tuning_result) -> int {
int res = 0;
if (timer) {
timer->ClearTiming();
timer->StartTiming();
if (params.front() == expect) {
timer->AccumulateTiming();
res = expect;
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
timer->AccumulateTiming();
res = params.front();
}
tuning_result->assign(params.begin(), params.end());
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
return params.front();
if (params.front() == expect) {
res = expect;
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
res = params.front();
}
}
return res;
};
std::vector<unsigned int> default_params(1, 1);
......
//
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#include <thread> // NOLINT(build/c++11)
#include "gtest/gtest.h"
#include "mace/utils/tuner.h"
namespace mace {
class TunerTest : public ::testing::Test {
protected:
virtual void SetUp() {
remove("/data/local/tmp/mace.config");
setenv("MACE_RUN_PARAMETER_PATH", "/data/local/tmp/mace.config", 1);
setenv("MACE_TUNING", "1", 1);
}
};
TEST_F(TunerTest, SimpleRun) {
int expect = 1;
auto TunerFunc = [&](const std::vector<unsigned int> &params) -> int {
if (params.front() == 1) {
return expect;
} else {
return expect + 1;
}
};
WallClockTimer timer;
std::vector<unsigned int> default_params(1, 1);
int res = Tuner<unsigned int>::Get()->template TuneOrRun<unsigned int>(
"SimpleRun", default_params, nullptr, TunerFunc, &timer);
EXPECT_EQ(expect, res);
default_params[0] = 2;
res = Tuner<unsigned int>::Get()->template TuneOrRun<unsigned int>(
"SimpleRun", default_params, nullptr, TunerFunc, &timer);
EXPECT_EQ(expect + 1, res);
}
TEST_F(TunerTest, SimpleTune) {
int expect = 3;
auto TunerFunc = [&](const std::vector<unsigned int> &params) -> int {
if (params.front() == expect) {
return expect;
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
return params.front();
}
};
std::vector<unsigned int> default_params(1, 1);
auto params_generator = []() -> std::vector<std::vector<unsigned int>> {
return {{1}, {2}, {3}, {4}};
};
// tune
WallClockTimer timer;
int res = Tuner<unsigned int>::Get()->template TuneOrRun<unsigned int>(
"SimpleRun", default_params, *params_generator, TunerFunc, &timer);
EXPECT_EQ(expect, res);
// run
res = Tuner<unsigned int>::Get()->template TuneOrRun<unsigned int>(
"SimpleRun", default_params, nullptr, TunerFunc, &timer);
EXPECT_EQ(expect, res);
}
} // namespace mace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册