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.

matrix_mul.cpp 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * \file dnn/test/fallback/matrix_mul.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/fallback/fixture.h"
  12. #include "test/common/rng.h"
  13. #include "test/common/checker.h"
  14. #include "test/common/matrix_mul.h"
  15. namespace megdnn {
  16. namespace test {
  17. TEST_F(FALLBACK, MATRIX_MUL) {
  18. Checker<MatrixMul> checker(handle());
  19. using Param = MatrixMul::Param;
  20. auto args = matrix_mul::get_matmul_args();
  21. for (auto arg : args) {
  22. auto m = arg.m, n = arg.n, k = arg.k;
  23. auto mask = arg.mask;
  24. Param param;
  25. param.transposeA = mask & 1;
  26. param.transposeB = mask & 2;
  27. TensorShape AS, BS, CS;
  28. if (param.transposeA)
  29. AS = TensorShape{k, m};
  30. else
  31. AS = TensorShape{m, k};
  32. if (param.transposeB)
  33. BS = TensorShape{n, k};
  34. else
  35. BS = TensorShape{k, n};
  36. CS = TensorShape{m, n};
  37. TensorLayout AL, BL, CL;
  38. AL = TensorLayout(AS, dtype::Float32());
  39. BL = TensorLayout(BS, dtype::Float32());
  40. CL = TensorLayout(CS, dtype::Float32());
  41. checker.set_param(param);
  42. checker.execl({AL, BL, CL});
  43. }
  44. }
  45. TEST_F(FALLBACK, BATCHED_MATRIX_MUL) {
  46. Checker<BatchedMatrixMul> checker(handle());
  47. using Param = MatrixMul::Param;
  48. auto args = matrix_mul::get_batched_matmul_args();
  49. for (auto arg : args) {
  50. auto b = arg.b, m = arg.m, n = arg.n, k = arg.k;
  51. auto mask = arg.mask;
  52. Param param;
  53. param.transposeA = mask & 1;
  54. param.transposeB = mask & 2;
  55. TensorShape AS, BS, CS;
  56. if (param.transposeA)
  57. AS = TensorShape{b, k, m};
  58. else
  59. AS = TensorShape{b, m, k};
  60. if (param.transposeB)
  61. BS = TensorShape{b, n, k};
  62. else
  63. BS = TensorShape{b, k, n};
  64. TensorLayout AL, BL;
  65. AL = TensorLayout(AS, dtype::Float32());
  66. BL = TensorLayout(BS, dtype::Float32());
  67. checker.set_param(param);
  68. checker.execs({AL, BL, {}});
  69. }
  70. }
  71. } // namespace test
  72. } // namespace megdnn
  73. // vim: syntax=cpp.doxygen

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