You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

relayout.cpp 1.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "test/common/relayout.h"
  2. #include "test/common/benchmarker.h"
  3. #include "test/common/checker.h"
  4. #include "test/common/tensor.h"
  5. #include "test/cpu/fixture.h"
  6. #include "megdnn/basic_types.h"
  7. using namespace megdnn;
  8. using namespace test;
  9. namespace {
  10. template <typename tag>
  11. class CPU_RELAYOUT : public CPU {};
  12. TYPED_TEST_CASE(CPU_RELAYOUT, relayout::test_types);
  13. TYPED_TEST(CPU_RELAYOUT, run) {
  14. relayout::run_test<TypeParam>(this->handle());
  15. }
  16. } // namespace
  17. #if MEGDNN_WITH_BENCHMARK
  18. TEST_F(CPU, BENCHMARK_RELAYOUT_CV) {
  19. relayout::run_cv_benchmark(handle());
  20. }
  21. TEST_F(CPU, BENCHMARK_RELAYOUT) {
  22. // Check if invoke fallback if it's not satisfied cv.
  23. using namespace relayout;
  24. std::vector<TestArg> args;
  25. args.emplace_back(
  26. TensorLayout(
  27. {1, 8, 3, 64, 64}, {64 * 64 * 3, 64 * 8, 64 * 64, 64, 1},
  28. dtype::Float32()),
  29. TensorLayout({1, 8, 3, 64, 64}, dtype::Float32()));
  30. auto handle_naive = create_cpu_handle(2);
  31. Benchmarker<Relayout> benchmarker(handle());
  32. Benchmarker<Relayout> benchmarker_naive(handle_naive.get());
  33. benchmarker_naive.set_times(1);
  34. benchmarker.set_times(1);
  35. for (auto&& arg : args) {
  36. float cpu_time = benchmarker.execl({arg.src, arg.dst});
  37. float naive_time = benchmarker_naive.execl({arg.src, arg.dst});
  38. ASSERT_LE(cpu_time * 5, naive_time);
  39. }
  40. }
  41. #endif
  42. // vim: syntax=cpp.doxygen