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.

reduce.cpp 2.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * \file dnn/test/naive/reduce.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 implied.
  10. */
  11. #include "test/naive/fixture.h"
  12. #include "megdnn/oprs/nn.h"
  13. #include "test/common/checker.h"
  14. #include "test/common/random_state.h"
  15. using namespace megdnn;
  16. using namespace test;
  17. TEST_F(NAIVE, REDUCE_QUANTIZED) {
  18. using Mode = Reduce::Param::Mode;
  19. Checker<Reduce> checker(handle(), /* check_dispatch */false);
  20. Reduce::Param param;
  21. param.mode = Mode::SUM;
  22. param.data_type = param::Reduce::DataType::QUINT_I8xO32;
  23. param.axis = 0;
  24. checker.set_param(param).exect(
  25. Testcase{TensorValue({3, 4},
  26. dtype::Quantized8Asymm(0.1f, (uint8_t)128),
  27. {6, 97, 210, 47, 213, 246, 92, 121, 132, 133,
  28. 222, 166}),
  29. {}},
  30. Testcase{{},
  31. TensorValue({1, 4}, dtype::QuantizedS32(0.1f),
  32. {-33, 92, 140, -50})});
  33. param.data_type = param::Reduce::DataType::DEFAULT;
  34. param.mode = Mode::MEAN;
  35. checker.set_param(param).exect(
  36. Testcase{TensorValue({3, 4},
  37. dtype::Quantized8Asymm(1.f, (uint8_t)128),
  38. {6, 97, 210, 47, 213, 246, 92, 121, 132, 133,
  39. 222, 166}),
  40. {}},
  41. Testcase{{},
  42. TensorValue({1, 4},
  43. dtype::Quantized8Asymm(1.f, (uint8_t)128),
  44. {117, 159, 175, 111})});
  45. checker.exect(
  46. Testcase{TensorValue({3, 4},
  47. dtype::Quantized8Asymm(0.00233f, (uint8_t)128),
  48. {6, 97, 210, 47, 213, 246, 92, 121, 132, 133,
  49. 222, 166}),
  50. {}},
  51. Testcase{{},
  52. TensorValue({1, 4},
  53. dtype::Quantized8Asymm(0.00233f, (uint8_t)128),
  54. {117, 159, 175, 111})});
  55. checker.exect(
  56. Testcase{TensorValue({3, 4},
  57. dtype::Quantized8Asymm(7e-10f, (uint8_t)45),
  58. {6, 97, 210, 47, 213, 246, 92, 121, 132, 133,
  59. 222, 166}),
  60. {}},
  61. Testcase{{},
  62. TensorValue({1, 4},
  63. dtype::Quantized8Asymm(7e-10f, (uint8_t)45),
  64. {117, 159, 175, 111})});
  65. }
  66. // vim: syntax=cpp.doxygen

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