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.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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)
  46. ? 5e-2
  47. : 5e-3)
  48. .execs({A, B, {}});
  49. }
  50. }
  51. // general tests
  52. auto args = matrix_mul::get_matmul_args();
  53. for (auto arg : args) {
  54. auto m = arg.m, n = arg.n, k = arg.k;
  55. auto mask = arg.mask;
  56. Param param;
  57. param.transposeA = mask & 1;
  58. param.transposeB = mask & 2;
  59. TensorShape AS, BS, CS;
  60. if (param.transposeA)
  61. AS = TensorShape{k, m};
  62. else
  63. AS = TensorShape{m, k};
  64. if (param.transposeB)
  65. BS = TensorShape{n, k};
  66. else
  67. BS = TensorShape{k, n};
  68. CS = TensorShape{m, n};
  69. TensorLayout AL, BL, CL;
  70. if (arg.A_stride == 0) {
  71. AL = TensorLayout(AS, dtype::Float32());
  72. } else {
  73. AL = TensorLayout(AS, {ptrdiff_t(arg.A_stride), 1},
  74. dtype::Float32());
  75. }
  76. if (arg.B_stride == 0) {
  77. BL = TensorLayout(BS, dtype::Float32());
  78. } else {
  79. BL = TensorLayout(BS, {ptrdiff_t(arg.B_stride), 1},
  80. dtype::Float32());
  81. }
  82. if (arg.C_stride == 0) {
  83. CL = TensorLayout(CS, dtype::Float32());
  84. } else {
  85. CL = TensorLayout(CS, {ptrdiff_t(arg.C_stride), 1},
  86. dtype::Float32());
  87. }
  88. checker.set_param(param).execl({AL, BL, CL});
  89. }
  90. }
  91. } // namespace test
  92. } // namespace megdnn
  93. // vim: syntax=cpp.doxygen

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