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_format.cpp 2.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * \file dnn/test/cuda/relayout_format.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 "megdnn/dtype.h"
  12. #include "megdnn/oprs.h"
  13. #include "test/common/checker.h"
  14. #include "test/common/rng.h"
  15. #include "test/cuda/fixture.h"
  16. using namespace megdnn;
  17. using namespace test;
  18. TEST_F(CUDA, RELAYOUT_FORMAT) {
  19. Checker<RelayoutFormat> checker(handle_cuda());
  20. UniformIntRNG rng{-50, 50};
  21. param::RelayoutFormat param;
  22. param.mode = param::RelayoutFormat::Mode::NCHW4_CHWN4;
  23. checker.set_dtype(0, dtype::QuantizedS8{0.1f})
  24. .set_rng(0, &rng)
  25. .set_param(param)
  26. .execs({{22, 23, 24, 25, 4}, {}});
  27. param.mode = param::RelayoutFormat::Mode::CHWN4_NCHW4;
  28. checker.execs({{22, 23, 24, 25, 4}, {}});
  29. }
  30. TEST_F(CUDA, RELAYOUT_FORMAT_NCHW4) {
  31. Checker<RelayoutFormat> checker(handle_cuda());
  32. UniformIntRNG rng{-50, 50};
  33. param::RelayoutFormat param;
  34. param.mode = param::RelayoutFormat::Mode::NCHW_NCHW4_IC_SMALL;
  35. for (DType dtype :
  36. std::vector<DType>({dtype::QuantizedS8{0.1f}, dtype::Float32{}})) {
  37. checker.set_dtype(0, dtype).set_rng(0, &rng);
  38. checker.set_param(param).execs({{2, 4, 35, 36}, {}});
  39. checker.set_param(param).execs({{2, 3, 35, 36}, {}});
  40. checker.set_param(param).execs({{2, 1, 35, 36}, {}});
  41. param.mode = param::RelayoutFormat::Mode::
  42. NCHW_NCHW4_IC_SMALL_CONV_DENSE_WEIGHT;
  43. checker.set_param(param).execs({{4, 3, 3, 3}, {}});
  44. checker.set_param(param).execs({{4, 4, 3, 3}, {}});
  45. checker.set_param(param).execs({{1, 4, 3, 3}, {}});
  46. }
  47. }
  48. // vim: syntax=cpp.doxygen

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