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 3.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * \file dnn/test/rocm/matrix_mul.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 "hcc_detail/hcc_defs_prologue.h"
  12. #include "test/rocm/fixture.h"
  13. #include "test/common/checker.h"
  14. #include "test/common/matrix_mul.h"
  15. #include "src/rocm/utils.h"
  16. namespace megdnn {
  17. namespace test {
  18. TEST_F(ROCM, MATRIX_MUL) {
  19. Checker<MatrixMul> checker(handle_rocm());
  20. using Param = MatrixMul::Param;
  21. size_t m = 12, n = 16, k = 20;
  22. //! result error for Int8x8x32, not test correctness
  23. std::vector<DType> dtypes{DNN_INC_FLOAT16(dtype::Float16() MEGDNN_COMMA)
  24. dtype::Float32() /*, dtype::Int32()*/};
  25. for (auto dtype : dtypes) {
  26. for (unsigned mask = 0; mask < 4; ++mask) {
  27. Param param;
  28. param.transposeA = mask & 1;
  29. param.transposeB = mask & 2;
  30. DType stype = dtype == dtype::Int32() ? dtype::Int8() : dtype;
  31. TensorShape A, B;
  32. if (param.transposeA)
  33. A = TensorShape{k, m};
  34. else
  35. A = TensorShape{m, k};
  36. if (param.transposeB)
  37. B = TensorShape{n, k};
  38. else
  39. B = TensorShape{k, n};
  40. checker.set_param(param)
  41. .set_dtype(0, stype)
  42. .set_dtype(1, stype)
  43. .set_dtype(2, dtype)
  44. .set_epsilon(
  45. DNN_FLOAT16_SELECT(dtype == dtype::Float16(), false) ? 5e-2
  46. : 5e-3)
  47. .execs({A, B, {}});
  48. }
  49. }
  50. // general tests
  51. auto args = matrix_mul::get_matmul_args();
  52. for (auto arg : args) {
  53. auto m = arg.m, n = arg.n, k = arg.k;
  54. auto mask = arg.mask;
  55. Param param;
  56. param.transposeA = mask & 1;
  57. param.transposeB = mask & 2;
  58. TensorShape AS, BS, CS;
  59. if (param.transposeA)
  60. AS = TensorShape{k, m};
  61. else
  62. AS = TensorShape{m, k};
  63. if (param.transposeB)
  64. BS = TensorShape{n, k};
  65. else
  66. BS = TensorShape{k, n};
  67. CS = TensorShape{m, n};
  68. TensorLayout AL, BL, CL;
  69. if (arg.A_stride == 0) {
  70. AL = TensorLayout(AS, dtype::Float32());
  71. } else {
  72. AL = TensorLayout(AS, {ptrdiff_t(arg.A_stride), 1}, dtype::Float32());
  73. }
  74. if (arg.B_stride == 0) {
  75. BL = TensorLayout(BS, dtype::Float32());
  76. } else {
  77. BL = TensorLayout(BS, {ptrdiff_t(arg.B_stride), 1}, dtype::Float32());
  78. }
  79. if (arg.C_stride == 0) {
  80. CL = TensorLayout(CS, dtype::Float32());
  81. } else {
  82. CL = TensorLayout(CS, {ptrdiff_t(arg.C_stride), 1}, dtype::Float32());
  83. }
  84. checker.set_param(param).execl({AL, BL, CL});
  85. }
  86. }
  87. } // namespace test
  88. } // namespace megdnn
  89. // vim: syntax=cpp.doxygen

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