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.

images2neibs.cpp 2.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "test/cuda/fixture.h"
  2. #include "test/common/checker.h"
  3. #include "test/common/images2neibs.h"
  4. #include "test/common/rng.h"
  5. #include "test/cuda/benchmark.h"
  6. #include "test/cuda/utils.h"
  7. namespace megdnn {
  8. namespace test {
  9. TEST_F(CUDA, IMAGES2NEIBS_FORWARD) {
  10. auto args = images2neibs::get_args();
  11. for (auto&& arg : args) {
  12. Checker<Images2NeibsForward> checker(handle_cuda());
  13. checker.set_param(arg.param)
  14. .set_dtype(0, dtype::Float32())
  15. .exec(TensorShapeArray{arg.ishape, {}});
  16. checker.set_param(arg.param)
  17. .set_dtype(0, dtype::Float16())
  18. .exec(TensorShapeArray{arg.ishape, {}});
  19. }
  20. }
  21. #if MEGDNN_WITH_BENCHMARK
  22. TEST_F(CUDA, BENCHMARK_IMAGES2NEIBS_FORWARD) {
  23. auto args = images2neibs::get_benchmark_args();
  24. for (auto&& arg : args) {
  25. CUBenchmarker<Images2NeibsForward> bencher(handle_cuda());
  26. bencher.set_param(arg.param)
  27. .set_dtype(0, dtype::Float32())
  28. .exec(TensorShapeArray{arg.ishape, {}});
  29. }
  30. }
  31. #endif
  32. TEST_F(CUDA, IMAGES2NEIBS_BACKWARD) {
  33. require_compute_capability(6, 1);
  34. UniformFloatRNG rng(0, 1);
  35. auto args = images2neibs::get_args();
  36. for (auto&& arg : args) {
  37. Checker<Images2NeibsBackward> checker(handle_cuda());
  38. checker.set_epsilon(1e-2);
  39. checker.set_rng(0, &rng);
  40. TensorLayout ilayout = TensorLayout(arg.ishape, dtype::Float32());
  41. TensorLayout olayout;
  42. {
  43. auto opr = handle_cuda()->create_operator<Images2Neibs>();
  44. opr->param() = arg.param;
  45. opr->deduce_layout(ilayout, olayout);
  46. }
  47. auto set_dtype = [&checker](DType dtype) {
  48. checker.set_dtype(0, dtype).set_dtype(1, dtype);
  49. };
  50. set_dtype(dtype::Float32());
  51. checker.set_param(arg.param).exec(TensorShapeArray{olayout, ilayout});
  52. set_dtype(dtype::Float16());
  53. checker.set_param(arg.param).exec(TensorShapeArray{olayout, ilayout});
  54. }
  55. }
  56. } // namespace test
  57. } // namespace megdnn
  58. // vim: syntax=cpp.doxygen