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.

flip.cpp 2.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * \file dnn/test/cuda/flip.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2020 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 <gtest/gtest.h>
  12. #include "megdnn.h"
  13. #include "megdnn/oprs.h"
  14. #include "test/common/tensor.h"
  15. #include "test/common/flip.h"
  16. #include "test/common/checker.h"
  17. #include "test/common/benchmarker.h"
  18. #include "test/cuda/fixture.h"
  19. namespace megdnn {
  20. namespace test {
  21. TEST_F(CUDA, FLIP) {
  22. using namespace flip;
  23. std::vector<TestArg> args = get_args();
  24. Checker<Flip> checker(handle_cuda());
  25. checker.set_dtype(0, dtype::Int32());
  26. checker.set_dtype(1, dtype::Int32());
  27. //! test for batch size exceed CUDNN_MAX_BATCH_X_CHANNEL_SIZE
  28. Flip::Param cur_param;
  29. for (bool vertical : {false, true}) {
  30. for (bool horizontal : {false, true}) {
  31. cur_param.horizontal = horizontal;
  32. cur_param.vertical = vertical;
  33. args.emplace_back(cur_param, TensorShape{65535, 3, 4, 1});
  34. args.emplace_back(cur_param, TensorShape{65540, 3, 4, 3});
  35. }
  36. }
  37. for (auto &&arg : args) {
  38. checker.execs({arg.src, {}});
  39. }
  40. }
  41. TEST_F(CUDA, FLIP_BENCHMARK) {
  42. auto run = [&](const TensorShapeArray& shapes) {
  43. Benchmarker<Flip> benchmarker(handle_cuda());
  44. benchmarker.set_dtype(0, dtype::Int32());
  45. benchmarker.set_dtype(1, dtype::Int32());
  46. benchmarker.set_times(5);
  47. Flip::Param param;
  48. #define BENCHMARK_FLIP(is_vertical, is_horizontal) \
  49. param.vertical = is_vertical; \
  50. param.horizontal = is_horizontal; \
  51. benchmarker.set_param(param); \
  52. printf("src:%s vertical==%d horizontal==%d\n", shape.to_string().c_str(), \
  53. is_vertical, is_horizontal); \
  54. benchmarker.execs({shape, {}});
  55. for (auto&& shape : shapes) {
  56. BENCHMARK_FLIP(false, false);
  57. BENCHMARK_FLIP(false, true);
  58. BENCHMARK_FLIP(true, false);
  59. BENCHMARK_FLIP(true, true);
  60. }
  61. #undef BENCHMARK_FLIP
  62. };
  63. TensorShapeArray shapes = {
  64. {3, 101, 98, 1},
  65. {3, 101, 98, 3}
  66. };
  67. run(shapes);
  68. }
  69. } // namespace test
  70. } // namespace megdnn
  71. // vim: syntax=cpp.doxygen

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台