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.

warp_perspective.cpp 21 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /**
  2. * \file dnn/test/arm_common/warp_perspective.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. */
  11. #include <string>
  12. #include <vector>
  13. #include "test/arm_common/fixture.h"
  14. #include "test/common/benchmarker.h"
  15. #include "test/common/checker.h"
  16. #include "test/common/random_state.h"
  17. #include "test/common/rng.h"
  18. #include "test/common/task_record_check.h"
  19. #include "test/common/warp_perspective.h"
  20. namespace megdnn {
  21. namespace test {
  22. TEST_F(ARM_COMMON, WARP_PERSPECTIVE_CV) {
  23. //! Just for the format NHWC
  24. Checker<WarpPerspective, WarpPerspectiveMatIdxProxy> checker(handle());
  25. param::WarpPerspective param;
  26. class ResizeMatRNG : public RNG {
  27. void gen(const TensorND& tensor_) override {
  28. auto& gen = RandomState::generator();
  29. std::uniform_real_distribution<dt_float32> pdist3(1.9f, 3.1f);
  30. std::uniform_real_distribution<dt_float32> pdist(0.9f, 1.1f);
  31. std::uniform_real_distribution<dt_float32> pdisth(0.4f, 0.6f);
  32. std::uniform_real_distribution<dt_float32> ndist(-1.1f, -0.9f);
  33. std::uniform_real_distribution<dt_float32> ndist3(-3.1f, -1.9f);
  34. std::uniform_real_distribution<dt_float32> ndisth(-0.6f, -0.4f);
  35. std::uniform_int_distribution<int> dice(0, 5);
  36. float* ptr = tensor_.ptr<dt_float32>();
  37. auto N = tensor_.layout.shape[0];
  38. for (size_t n = 0; n < N; ++n) {
  39. for (size_t i = 0; i < 9; ++i) {
  40. switch (dice(gen)) {
  41. case 0:
  42. ptr[i] = pdist3(gen);
  43. break;
  44. case 1:
  45. ptr[i] = pdist(gen);
  46. break;
  47. case 2:
  48. ptr[i] = pdisth(gen);
  49. break;
  50. case 3:
  51. ptr[i] = ndist(gen);
  52. break;
  53. case 4:
  54. ptr[i] = ndist3(gen);
  55. break;
  56. case 5:
  57. ptr[i] = ndisth(gen);
  58. break;
  59. }
  60. }
  61. // is resize?
  62. if (n & 1) {
  63. ptr[1] = 0;
  64. ptr[3] = 0;
  65. ptr[6] = ptr[7] = 0;
  66. }
  67. ptr += 9;
  68. }
  69. }
  70. } rng;
  71. using BMode = param::WarpPerspective::BorderMode;
  72. param.format = param::WarpPerspective::Format::NHWC;
  73. // add for nearest test
  74. param.imode = param::WarpPerspective::InterpolationMode::NEAREST;
  75. for (auto mode :
  76. {BMode::REFLECT_101, BMode::REPLICATE, BMode::REFLECT, BMode::WRAP,
  77. BMode::CONSTANT}) {
  78. param.bmode = mode;
  79. param.border_val = 1.737;
  80. checker.set_param(param);
  81. UniformIntRNG rng(0, 9);
  82. checker.set_rng(2, &rng);
  83. checker.set_dtype(2, dtype::Int32());
  84. checker.exec({{10, 128, 108, 3}, {20, 3, 3}, {20}, {20, 56, 128, 3}});
  85. }
  86. // resize nan case
  87. UniformFloatRNG rng_zero(0, 0);
  88. checker.set_rng(1, &rng_zero);
  89. {
  90. param.bmode = BMode::CONSTANT;
  91. param.border_val = 1.737;
  92. checker.set_param(param);
  93. UniformIntRNG rng(0, 999);
  94. checker.set_rng(2, &rng);
  95. checker.set_dtype(2, dtype::Int32());
  96. checker.exec({{1000, 2, 10, 3}, {1000, 3, 3}, {1000}, {1000, 2, 12, 3}});
  97. }
  98. // add linear test
  99. param.imode = param::WarpPerspective::InterpolationMode::INTER_LINEAR;
  100. for (auto mode :
  101. {BMode::REFLECT_101, BMode::REPLICATE, BMode::REFLECT, BMode::WRAP,
  102. BMode::CONSTANT}) {
  103. param.bmode = mode;
  104. param.border_val = 1.737;
  105. checker.set_param(param);
  106. UniformIntRNG rng(0, 9);
  107. checker.set_rng(2, &rng);
  108. checker.set_dtype(2, dtype::Int32());
  109. checker.exec({{10, 128, 108, 3}, {20, 3, 3}, {20}, {20, 56, 128, 3}});
  110. }
  111. // resize nan case
  112. checker.set_rng(1, &rng_zero);
  113. {
  114. param.bmode = BMode::CONSTANT;
  115. param.border_val = 1.737;
  116. checker.set_param(param);
  117. UniformIntRNG rng(0, 999);
  118. checker.set_rng(2, &rng);
  119. checker.set_dtype(2, dtype::Int32());
  120. checker.exec({{1000, 2, 10, 3}, {2000, 3, 3}, {2000}, {2000, 2, 12, 3}});
  121. }
  122. auto args = warp_perspective::get_cv_args();
  123. for (auto&& arg : args) {
  124. ConstValue rng(0.f);
  125. checker.set_param(arg.param)
  126. .set_rng(2, &rng)
  127. .set_dtype(0, dtype::Uint8())
  128. .set_dtype(1, dtype::Float32())
  129. .set_dtype(2, dtype::Int32())
  130. .set_dtype(3, dtype::Uint8())
  131. .execs({arg.src, arg.trans, arg.mat_idx, arg.dst});
  132. }
  133. for (auto&& arg : args) {
  134. ConstValue rng(0.f);
  135. checker.set_param(arg.param)
  136. .set_rng(2, &rng)
  137. .set_dtype(0, dtype::Float32())
  138. .set_dtype(1, dtype::Float32())
  139. .set_dtype(2, dtype::Int32())
  140. .set_dtype(3, dtype::Float32())
  141. .execs({arg.src, arg.trans, arg.mat_idx, arg.dst});
  142. }
  143. }
  144. TEST_F(ARM_COMMON, WARP_PERSPECTIVE_CV_RECORD) {
  145. //! Just for the format NHWC
  146. TaskRecordChecker<WarpPerspective, WarpPerspectiveMatIdxProxy> checker(0);
  147. param::WarpPerspective param;
  148. class ResizeMatRNG : public RNG {
  149. void gen(const TensorND& tensor_) override {
  150. auto& gen = RandomState::generator();
  151. std::uniform_real_distribution<dt_float32> pdist3(1.9f, 3.1f);
  152. std::uniform_real_distribution<dt_float32> pdist(0.9f, 1.1f);
  153. std::uniform_real_distribution<dt_float32> pdisth(0.4f, 0.6f);
  154. std::uniform_real_distribution<dt_float32> ndist(-1.1f, -0.9f);
  155. std::uniform_real_distribution<dt_float32> ndist3(-3.1f, -1.9f);
  156. std::uniform_real_distribution<dt_float32> ndisth(-0.6f, -0.4f);
  157. std::uniform_int_distribution<int> dice(0, 5);
  158. float* ptr = tensor_.ptr<dt_float32>();
  159. auto N = tensor_.layout.shape[0];
  160. for (size_t n = 0; n < N; ++n) {
  161. for (size_t i = 0; i < 9; ++i) {
  162. switch (dice(gen)) {
  163. case 0:
  164. ptr[i] = pdist3(gen);
  165. break;
  166. case 1:
  167. ptr[i] = pdist(gen);
  168. break;
  169. case 2:
  170. ptr[i] = pdisth(gen);
  171. break;
  172. case 3:
  173. ptr[i] = ndist(gen);
  174. break;
  175. case 4:
  176. ptr[i] = ndist3(gen);
  177. break;
  178. case 5:
  179. ptr[i] = ndisth(gen);
  180. break;
  181. }
  182. }
  183. // is resize?
  184. if (n & 1) {
  185. ptr[1] = 0;
  186. ptr[3] = 0;
  187. ptr[6] = ptr[7] = 0;
  188. }
  189. ptr += 9;
  190. }
  191. }
  192. } rng;
  193. using BMode = param::WarpPerspective::BorderMode;
  194. param.format = param::WarpPerspective::Format::NHWC;
  195. // add for nearest test
  196. param.imode = param::WarpPerspective::InterpolationMode::NEAREST;
  197. for (auto mode :
  198. {BMode::REFLECT_101, BMode::REPLICATE, BMode::REFLECT, BMode::WRAP,
  199. BMode::CONSTANT}) {
  200. param.bmode = mode;
  201. param.border_val = 1.737;
  202. checker.set_param(param);
  203. UniformIntRNG rng(0, 9);
  204. checker.set_rng(2, &rng);
  205. checker.set_dtype(2, dtype::Int32());
  206. checker.exec({{10, 128, 108, 3}, {20, 3, 3}, {20}, {20, 56, 128, 3}});
  207. }
  208. // resize nan case
  209. UniformFloatRNG rng_zero(0, 0);
  210. checker.set_rng(1, &rng_zero);
  211. {
  212. param.bmode = BMode::CONSTANT;
  213. param.border_val = 1.737;
  214. checker.set_param(param);
  215. UniformIntRNG rng(0, 999);
  216. checker.set_rng(2, &rng);
  217. checker.set_dtype(2, dtype::Int32());
  218. checker.exec({{1000, 2, 10, 3}, {1000, 3, 3}, {1000}, {1000, 2, 12, 3}});
  219. }
  220. // add linear test
  221. param.imode = param::WarpPerspective::InterpolationMode::INTER_LINEAR;
  222. for (auto mode :
  223. {BMode::REFLECT_101, BMode::REPLICATE, BMode::REFLECT, BMode::WRAP,
  224. BMode::CONSTANT}) {
  225. param.bmode = mode;
  226. param.border_val = 1.737;
  227. checker.set_param(param);
  228. UniformIntRNG rng(0, 9);
  229. checker.set_rng(2, &rng);
  230. checker.set_dtype(2, dtype::Int32());
  231. checker.exec({{10, 128, 108, 3}, {20, 3, 3}, {20}, {20, 56, 128, 3}});
  232. }
  233. // resize nan case
  234. checker.set_rng(1, &rng_zero);
  235. {
  236. param.bmode = BMode::CONSTANT;
  237. param.border_val = 1.737;
  238. checker.set_param(param);
  239. UniformIntRNG rng(0, 999);
  240. checker.set_rng(2, &rng);
  241. checker.set_dtype(2, dtype::Int32());
  242. checker.exec({{1000, 2, 10, 3}, {2000, 3, 3}, {2000}, {2000, 2, 12, 3}});
  243. }
  244. auto args = warp_perspective::get_cv_args();
  245. for (auto&& arg : args) {
  246. ConstValue rng(0.f);
  247. checker.set_param(arg.param)
  248. .set_rng(2, &rng)
  249. .set_dtype(0, dtype::Uint8())
  250. .set_dtype(1, dtype::Float32())
  251. .set_dtype(2, dtype::Int32())
  252. .set_dtype(3, dtype::Uint8())
  253. .execs({arg.src, arg.trans, arg.mat_idx, arg.dst});
  254. }
  255. for (auto&& arg : args) {
  256. ConstValue rng(0.f);
  257. checker.set_param(arg.param)
  258. .set_rng(2, &rng)
  259. .set_dtype(0, dtype::Float32())
  260. .set_dtype(1, dtype::Float32())
  261. .set_dtype(2, dtype::Int32())
  262. .set_dtype(3, dtype::Float32())
  263. .execs({arg.src, arg.trans, arg.mat_idx, arg.dst});
  264. }
  265. }
  266. TEST_F(ARM_COMMON_MULTI_THREADS, WARP_PERSPECTIVE_CV) {
  267. //! Just for the format NHWC
  268. Checker<WarpPerspective, WarpPerspectiveMatIdxProxy> checker(handle());
  269. param::WarpPerspective param;
  270. class ResizeMatRNG : public RNG {
  271. void gen(const TensorND& tensor_) override {
  272. auto& gen = RandomState::generator();
  273. std::uniform_real_distribution<dt_float32> pdist3(1.9f, 3.1f);
  274. std::uniform_real_distribution<dt_float32> pdist(0.9f, 1.1f);
  275. std::uniform_real_distribution<dt_float32> pdisth(0.4f, 0.6f);
  276. std::uniform_real_distribution<dt_float32> ndist(-1.1f, -0.9f);
  277. std::uniform_real_distribution<dt_float32> ndist3(-3.1f, -1.9f);
  278. std::uniform_real_distribution<dt_float32> ndisth(-0.6f, -0.4f);
  279. std::uniform_int_distribution<int> dice(0, 5);
  280. float* ptr = tensor_.ptr<dt_float32>();
  281. auto N = tensor_.layout.shape[0];
  282. for (size_t n = 0; n < N; ++n) {
  283. for (size_t i = 0; i < 9; ++i) {
  284. switch (dice(gen)) {
  285. case 0:
  286. ptr[i] = pdist3(gen);
  287. break;
  288. case 1:
  289. ptr[i] = pdist(gen);
  290. break;
  291. case 2:
  292. ptr[i] = pdisth(gen);
  293. break;
  294. case 3:
  295. ptr[i] = ndist(gen);
  296. break;
  297. case 4:
  298. ptr[i] = ndist3(gen);
  299. break;
  300. case 5:
  301. ptr[i] = ndisth(gen);
  302. break;
  303. }
  304. }
  305. // is resize?
  306. if (n & 1) {
  307. ptr[1] = 0;
  308. ptr[3] = 0;
  309. ptr[6] = ptr[7] = 0;
  310. }
  311. ptr += 9;
  312. }
  313. }
  314. } rng;
  315. using BMode = param::WarpPerspective::BorderMode;
  316. param.format = param::WarpPerspective::Format::NHWC;
  317. // add for nearest test
  318. param.imode = param::WarpPerspective::InterpolationMode::NEAREST;
  319. for (auto mode :
  320. {BMode::REFLECT_101, BMode::REPLICATE, BMode::REFLECT, BMode::WRAP,
  321. BMode::CONSTANT}) {
  322. param.bmode = mode;
  323. param.border_val = 1.737;
  324. checker.set_param(param);
  325. UniformIntRNG rng(0, 9);
  326. checker.set_rng(2, &rng);
  327. checker.set_dtype(2, dtype::Int32());
  328. checker.exec({{10, 128, 108, 3}, {10, 3, 3}, {10}, {10, 56, 128, 3}});
  329. }
  330. // resize nan case
  331. UniformFloatRNG rng_zero(0, 0);
  332. checker.set_rng(1, &rng_zero);
  333. {
  334. param.bmode = BMode::CONSTANT;
  335. param.border_val = 1.737;
  336. checker.set_param(param);
  337. UniformIntRNG rng(0, 999);
  338. checker.set_rng(2, &rng);
  339. checker.set_dtype(2, dtype::Int32());
  340. checker.exec({{1000, 2, 10, 3}, {2000, 3, 3}, {2000}, {2000, 2, 12, 3}});
  341. }
  342. // add linear test
  343. param.imode = param::WarpPerspective::InterpolationMode::INTER_LINEAR;
  344. for (auto mode :
  345. {BMode::REFLECT_101, BMode::REPLICATE, BMode::REFLECT, BMode::WRAP,
  346. BMode::CONSTANT}) {
  347. param.bmode = mode;
  348. param.border_val = 1.737;
  349. checker.set_param(param);
  350. UniformIntRNG rng(0, 9);
  351. checker.set_rng(2, &rng);
  352. checker.set_dtype(2, dtype::Int32());
  353. checker.exec({{10, 128, 108, 3}, {10, 3, 3}, {10}, {10, 56, 128, 3}});
  354. }
  355. // resize nan case
  356. checker.set_rng(1, &rng_zero);
  357. {
  358. param.bmode = BMode::CONSTANT;
  359. param.border_val = 1.737;
  360. checker.set_param(param);
  361. UniformIntRNG rng(0, 999);
  362. checker.set_rng(2, &rng);
  363. checker.set_dtype(2, dtype::Int32());
  364. checker.exec({{1000, 2, 10, 3}, {1000, 3, 3}, {1000}, {1000, 2, 12, 3}});
  365. }
  366. auto args = warp_perspective::get_cv_args();
  367. for (auto&& arg : args) {
  368. ConstValue rng(0.f);
  369. checker.set_param(arg.param)
  370. .set_rng(2, &rng)
  371. .set_dtype(0, dtype::Uint8())
  372. .set_dtype(1, dtype::Float32())
  373. .set_dtype(2, dtype::Int32())
  374. .set_dtype(3, dtype::Uint8())
  375. .execs({arg.src, arg.trans, arg.mat_idx, arg.dst});
  376. }
  377. for (auto&& arg : args) {
  378. ConstValue rng(0.f);
  379. checker.set_param(arg.param)
  380. .set_rng(2, &rng)
  381. .set_dtype(0, dtype::Float32())
  382. .set_dtype(1, dtype::Float32())
  383. .set_dtype(2, dtype::Int32())
  384. .set_dtype(3, dtype::Float32())
  385. .execs({arg.src, arg.trans, arg.mat_idx, arg.dst});
  386. }
  387. }
  388. #if MEGDNN_WITH_BENCHMARK
  389. TEST_F(ARM_COMMON, BENCHMARK_WARP_PERSPECTIVE_FORWARD) {
  390. Benchmarker<WarpPerspectiveForward> benchmarker(handle());
  391. auto handle_naive = create_cpu_handle(2);
  392. Benchmarker<WarpPerspectiveForward> benchmarker_naive(handle_naive.get());
  393. constexpr size_t NR_RUN = 50;
  394. using BMode = param::WarpPerspective::BorderMode;
  395. using IMode = param::WarpPerspective::InterpolationMode;
  396. WarpPerspective::Param param;
  397. param.border_val = 0.3f;
  398. param.format = param::WarpPerspective::Format::NHWC;
  399. auto run = [&](size_t N, size_t C, size_t IH, size_t IW, size_t OH, size_t OW,
  400. size_t scale) {
  401. printf("src={%zu, %zu, %zu, %zu}, dst={%zu, %zu, %zu, %zu}\n", N, IH, IW, C, N,
  402. OH, OW, C);
  403. auto time_ms =
  404. benchmarker.exec({{N, IH, IW, C}, {N, 3, 3}, {N, OH, OW, C}}) / NR_RUN;
  405. auto time_naive_ms =
  406. benchmarker_naive.exec({{N, IH, IW, C}, {N, 3, 3}, {N, OH, OW, C}}) /
  407. NR_RUN;
  408. auto bandwidth = N * C * (scale * OH * OW) * dtype::Float32().size();
  409. printf("aarch64: %.3f, perf: %.3f GBPS naive: %.3f, perf %.3f GBPS "
  410. "speedup: %f\n",
  411. time_ms, bandwidth / time_ms / 1e6, time_naive_ms,
  412. bandwidth / time_naive_ms / 1e6, time_naive_ms / time_ms);
  413. };
  414. std::vector<std::string> bmodestringmap = {
  415. "REPLICATE", "REFLECT", "REFLECT_101", "WARP", "CONSTANT"};
  416. std::vector<std::string> imodestringmap = {"NEAREST", "INTER_LINEAR"};
  417. size_t scales[2] = {2, 5};
  418. for (auto imode : {IMode::NEAREST, IMode::INTER_LINEAR}) {
  419. for (auto bmode :
  420. {BMode::REFLECT_101, BMode::REPLICATE, BMode::REFLECT, BMode::WRAP,
  421. BMode::CONSTANT}) {
  422. param.imode = imode;
  423. param.bmode = bmode;
  424. benchmarker.set_param(param).set_display(false).set_times(NR_RUN);
  425. benchmarker_naive.set_param(param).set_display(false).set_times(NR_RUN);
  426. size_t scale = scales[(int)imode];
  427. printf("\n\n\n warpperspective InterpolationMode::%s "
  428. "BorderMode::%s start\n",
  429. imodestringmap[(int)imode].c_str(),
  430. bmodestringmap[(int)bmode].c_str());
  431. for (auto&& shape : std::vector<std::pair<size_t, size_t>>{
  432. {700, 490},
  433. {500, 334},
  434. {472, 342},
  435. {448, 306},
  436. {626, 412},
  437. {140, 144},
  438. {120, 128},
  439. {180, 176}}) {
  440. for (size_t ch : {1, 2, 3}) {
  441. run(1, ch, shape.first, shape.second, 256, 256, scale);
  442. }
  443. }
  444. }
  445. }
  446. }
  447. namespace {
  448. void benchmark_impl(
  449. const typename WarpPerspective::Param& param,
  450. std::vector<SmallVector<TensorShape>> shapes, size_t RUNS,
  451. TaskExecutorConfig&& multi_thread_config,
  452. TaskExecutorConfig&& single_thread_config) {
  453. std::vector<float> multi_thread_times, single_thread_times;
  454. {
  455. auto multi_thread_hanle = create_cpu_handle(0, true, &multi_thread_config);
  456. auto benchmarker = Benchmarker<WarpPerspective>(multi_thread_hanle.get());
  457. benchmarker.set_times(RUNS).set_display(false).set_param(param);
  458. for (auto shape : shapes) {
  459. multi_thread_times.push_back(benchmarker.exec(shape) / RUNS);
  460. }
  461. }
  462. {
  463. auto single_thread_handle = create_cpu_handle(0, true, &single_thread_config);
  464. auto benchmarker = Benchmarker<WarpPerspective>(single_thread_handle.get());
  465. benchmarker.set_times(RUNS).set_display(false).set_param(param);
  466. for (auto shape : shapes) {
  467. single_thread_times.push_back(benchmarker.exec(shape) / RUNS);
  468. }
  469. }
  470. printf("Benchmark : Multi threads %zu, ", multi_thread_config.nr_thread);
  471. printf("core_ids:");
  472. for (size_t i = 0; i < multi_thread_config.affinity_core_set.size(); i++) {
  473. printf("%zu ", multi_thread_config.affinity_core_set[i]);
  474. }
  475. printf(", Single thread core_id %zu\n", single_thread_config.affinity_core_set[0]);
  476. for (size_t i = 0; i < shapes.size(); i++) {
  477. auto shape = shapes[i];
  478. printf("Case: ");
  479. for (auto sh : shape)
  480. printf("%s ", sh.to_string().c_str());
  481. printf("%zu threads time: %f,\n single thread time: "
  482. "%f. spead up = %f, speedup/cores=%f\n",
  483. multi_thread_config.nr_thread, multi_thread_times[i],
  484. single_thread_times[i], single_thread_times[i] / multi_thread_times[i],
  485. single_thread_times[i] / multi_thread_times[i] /
  486. multi_thread_config.nr_thread);
  487. }
  488. }
  489. } // namespace
  490. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_WARP_PERSPECTIVE) {
  491. constexpr size_t RUNS = 50;
  492. using BMode = param::WarpPerspective::BorderMode;
  493. using IMode = param::WarpPerspective::InterpolationMode;
  494. WarpPerspective::Param param;
  495. param.border_val = 0.3f;
  496. param.format = param::WarpPerspective::Format::NHWC;
  497. param.imode = IMode::INTER_LINEAR;
  498. param.bmode = BMode::REPLICATE;
  499. std::vector<SmallVector<TensorShape>> shapes;
  500. auto bench_case = [&](size_t N, size_t H, size_t W, size_t C) {
  501. SmallVector<TensorShape> shape{{N, H, W, C}, {N, 3, 3}, {N, 224, 224, C}};
  502. shapes.push_back(shape);
  503. };
  504. bench_case(1, 700, 490, 1);
  505. bench_case(1, 700, 490, 2);
  506. bench_case(1, 700, 490, 3);
  507. bench_case(1, 500, 334, 1);
  508. bench_case(1, 500, 334, 2);
  509. bench_case(1, 500, 334, 3);
  510. bench_case(1, 140, 144, 1);
  511. bench_case(1, 140, 144, 2);
  512. bench_case(1, 140, 114, 3);
  513. printf("Benchmark warp perspective\n");
  514. benchmark_impl(param, shapes, RUNS, {4, {4, 5, 6, 7}}, {1, {4}});
  515. benchmark_impl(param, shapes, RUNS, {4, {4, 5, 6, 7}}, {1, {7}});
  516. benchmark_impl(param, shapes, RUNS, {2, {4, 5}}, {1, {4}});
  517. }
  518. #endif
  519. } // namespace test
  520. } // namespace megdnn
  521. // vim: syntax=cpp.doxygen