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.

accuracy_shake.cpp 3.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * \file dnn/test/x86/accuracy_shake.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
  10. * implied.
  11. */
  12. #include "test/x86/fixture.h"
  13. #include "megdnn/opr_param_defs.h"
  14. #include "megdnn/oprs.h"
  15. #include "test/common/accuracy_shake_checker.h"
  16. #include "test/common/convolution.h"
  17. #include "test/common/rng.h"
  18. #include "test/common/tensor.h"
  19. #include "test/common/workspace_wrapper.h"
  20. namespace megdnn {
  21. namespace test {
  22. TEST_F(X86, SHAKE_CONV_BIAS_FORWARD) {
  23. AccuracyShakeChecker<ConvBiasForward> checker(handle());
  24. NormalRNG default_rng;
  25. checker.set_dtype(0, dtype::Float32())
  26. .set_dtype(1, dtype::Float32())
  27. .set_dtype(2, dtype::Float32())
  28. .set_rng(0, &default_rng)
  29. .set_rng(1, &default_rng);
  30. checker.set_before_exec_callback(AlgoGenerator<ConvBiasForward>("X86"));
  31. // convolution
  32. checker.exec({{6, 16, 32, 32}, {64, 16, 3, 3}, {}, {}, {}});
  33. // convbias without z
  34. checker.exec({{6, 16, 32, 32}, {64, 16, 3, 3}, {1, 64, 1, 1}, {}, {}});
  35. // convbias with z
  36. checker.exec({{6, 16, 32, 32},
  37. {64, 16, 3, 3},
  38. {1, 64, 1, 1},
  39. {6, 64, 30, 30},
  40. {}});
  41. // group
  42. ConvBias::Param param;
  43. param.sparse = ConvBias::Param::Sparse::GROUP;
  44. checker.set_param(param);
  45. checker.exec({{6, 16, 32, 32}, {2, 32, 8, 3, 3}, {}, {}, {}});
  46. checker.exec({{6, 16, 32, 32}, {2, 32, 8, 3, 3}, {1, 64, 1, 1}, {}, {}});
  47. checker.exec({{6, 16, 32, 32},
  48. {2, 32, 8, 3, 3},
  49. {1, 64, 1, 1},
  50. {6, 64, 30, 30},
  51. {}});
  52. }
  53. TEST_F(X86, SHAKE_CONV_BIAS_FORWARD_INT8) {
  54. AccuracyShakeChecker<ConvBiasForward> checker(handle());
  55. UniformIntRNG rng{-50, 50};
  56. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  57. .set_dtype(1, dtype::QuantizedS8(2.5f))
  58. .set_dtype(2, dtype::QuantizedS32(6.25f))
  59. .set_dtype(3, dtype::QuantizedS32(6.25f))
  60. .set_dtype(4, {})
  61. .set_rng(0, &rng)
  62. .set_rng(1, &rng)
  63. .set_rng(2, &rng);
  64. checker.set_before_exec_callback(AlgoGenerator<ConvBiasForward>("X86"));
  65. // convolution
  66. checker.exec({{6, 16, 32, 32}, {64, 16, 3, 3}, {}, {}, {}});
  67. // convbias without z
  68. checker.exec({{6, 16, 32, 32}, {64, 16, 3, 3}, {1, 64, 1, 1}, {}, {}});
  69. // convbias with z
  70. checker.exec({{6, 16, 32, 32},
  71. {64, 16, 3, 3},
  72. {1, 64, 1, 1},
  73. {6, 64, 30, 30},
  74. {}});
  75. // group
  76. ConvBias::Param param;
  77. param.sparse = ConvBias::Param::Sparse::GROUP;
  78. checker.set_param(param);
  79. checker.exec({{6, 16, 32, 32}, {2, 32, 8, 3, 3}, {}, {}, {}});
  80. checker.exec({{6, 16, 32, 32}, {2, 32, 8, 3, 3}, {1, 64, 1, 1}, {}, {}});
  81. checker.exec({{6, 16, 32, 32},
  82. {2, 32, 8, 3, 3},
  83. {1, 64, 1, 1},
  84. {6, 64, 30, 30},
  85. {}});
  86. }
  87. TEST_F(X86, SHAKE_MATRIX_MUL_FORWARD) {
  88. AccuracyShakeChecker<MatrixMul> checker(handle());
  89. checker.set_dtype(0, dtype::Float32())
  90. .set_dtype(1, dtype::Float32())
  91. .set_dtype(2, dtype::Float32())
  92. .exec({{20, 100}, {100, 60}, {}});
  93. }
  94. } // namespace test
  95. } // namespace megdnn
  96. // vim: syntax=cpp.doxygen

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