relayout.cpp 1.4 KB
Newer Older
M
Megvii Engine Team 已提交
1
#include "test/common/relayout.h"
2
#include "test/common/benchmarker.h"
M
Megvii Engine Team 已提交
3
#include "test/common/checker.h"
4 5 6 7 8 9 10 11 12
#include "test/common/tensor.h"
#include "test/cpu/fixture.h"

#include "megdnn/basic_types.h"

using namespace megdnn;
using namespace test;

namespace {
M
Megvii Engine Team 已提交
13 14
template <typename tag>
class CPU_RELAYOUT : public CPU {};
15
TYPED_TEST_SUITE(CPU_RELAYOUT, relayout::test_types);
16 17 18
TYPED_TEST(CPU_RELAYOUT, run) {
    relayout::run_test<TypeParam>(this->handle());
}
M
Megvii Engine Team 已提交
19
}  // namespace
20

21
#if MEGDNN_WITH_BENCHMARK
22 23 24 25 26 27 28 29
TEST_F(CPU, BENCHMARK_RELAYOUT_CV) {
    relayout::run_cv_benchmark(handle());
}

TEST_F(CPU, BENCHMARK_RELAYOUT) {
    // Check if invoke fallback if it's not satisfied cv.
    using namespace relayout;
    std::vector<TestArg> args;
M
Megvii Engine Team 已提交
30 31 32 33 34
    args.emplace_back(
            TensorLayout(
                    {1, 8, 3, 64, 64}, {64 * 64 * 3, 64 * 8, 64 * 64, 64, 1},
                    dtype::Float32()),
            TensorLayout({1, 8, 3, 64, 64}, dtype::Float32()));
35 36 37 38 39 40
    auto handle_naive = create_cpu_handle(2);
    Benchmarker<Relayout> benchmarker(handle());
    Benchmarker<Relayout> benchmarker_naive(handle_naive.get());

    benchmarker_naive.set_times(1);
    benchmarker.set_times(1);
M
Megvii Engine Team 已提交
41
    for (auto&& arg : args) {
42 43 44 45 46
        float cpu_time = benchmarker.execl({arg.src, arg.dst});
        float naive_time = benchmarker_naive.execl({arg.src, arg.dst});
        ASSERT_LE(cpu_time * 5, naive_time);
    }
}
47
#endif
48 49

// vim: syntax=cpp.doxygen