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.

conv_bias.cpp 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * \file dnn/test/armv7/conv_bias.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 "test/armv7/fixture.h"
  12. #include "test/common/convolution.h"
  13. #include "test/common/conv_bias.h"
  14. #include "test/common/checker.h"
  15. #include "test/common/benchmarker.h"
  16. #include "test/common/rng.h"
  17. using namespace megdnn;
  18. using namespace test;
  19. namespace{
  20. TEST_F(ARMV7, CONV_BIAS_MATMUL_QU8) {
  21. using namespace conv_bias;
  22. std::vector<TestArg> args = get_quantized_args();
  23. Checker<ConvBiasForward> checker(handle());
  24. checker.set_before_exec_callback(
  25. conv_bias::ConvBiasAlgoChecker<ConvBias>("QU8MATMUL"));
  26. UniformIntRNG rng{0, 127};
  27. for (auto&& arg : args) {
  28. if (arg.bias.ndim == 4 && arg.bias[2] != 1 && arg.bias[3] != 1)
  29. continue;
  30. checker.set_dtype(0, dtype::Quantized8Asymm(2.5f,
  31. static_cast<uint8_t>(127)))
  32. .set_dtype(1, dtype::Quantized8Asymm(2.7f,
  33. static_cast<uint8_t>(129)))
  34. .set_dtype(2, dtype::QuantizedS32(6.75f))
  35. .set_dtype(4, dtype::Quantized8Asymm(60.25f,
  36. static_cast<uint8_t>(125)))
  37. .set_rng(0, &rng)
  38. .set_rng(1, &rng)
  39. .set_rng(2, &rng)
  40. .set_param(arg.param)
  41. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  42. }
  43. }
  44. TEST_F(ARMV7, CONV_BIAS_MATMUL_QS8) {
  45. using namespace conv_bias;
  46. std::vector<TestArg> args = get_quantized_args();
  47. Checker<ConvBiasForward> checker(handle());
  48. checker.set_before_exec_callback(
  49. conv_bias::ConvBiasAlgoChecker<ConvBias>("S8MATMUL"));
  50. UniformIntRNG rng{0, 127};
  51. for (auto&& arg : args) {
  52. if (arg.bias.ndim == 4 && arg.bias[2] != 1 && arg.bias[3] != 1)
  53. continue;
  54. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  55. .set_dtype(1, dtype::QuantizedS8(2.7f))
  56. .set_dtype(2, dtype::QuantizedS32(6.75f))
  57. .set_dtype(4, dtype::QuantizedS8(60.25f))
  58. .set_rng(0, &rng)
  59. .set_rng(1, &rng)
  60. .set_rng(2, &rng)
  61. .set_param(arg.param)
  62. .set_epsilon(1.0f)
  63. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  64. }
  65. }
  66. }
  67. // vim: syntax=cpp.doxygen

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