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.

local.h 6.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /**
  2. * \file dnn/test/common/local.h
  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. #pragma once
  12. #include "megdnn/opr_param_defs.h"
  13. #include "megdnn/basic_types.h"
  14. #include <cstddef>
  15. namespace megdnn {
  16. namespace test {
  17. namespace local {
  18. struct TestArg {
  19. param::Convolution param;
  20. size_t n, ic, ih, iw, oc, oh, ow, fh, fw;
  21. TestArg(param::Convolution param, size_t n, size_t ic, size_t ih, size_t iw,
  22. size_t oc, size_t oh, size_t ow, size_t fh, size_t fw)
  23. : param(param),
  24. n(n),
  25. ic(ic),
  26. ih(ih),
  27. iw(iw),
  28. oc(oc),
  29. oh(oh),
  30. ow(ow),
  31. fh(fh),
  32. fw(fw) {}
  33. TensorShape sshape() const { return {n, ic, ih, iw}; }
  34. TensorShape fshape() const { return {oh, ow, ic, fh, fw, oc}; }
  35. TensorShape dshape() { return {n, oc, oh, ow}; }
  36. };
  37. static inline std::vector<TestArg> get_args_for_cuda() {
  38. std::vector<TestArg> test_args;
  39. // clang-format off
  40. for (size_t N: {32, 64})
  41. for (size_t IC: {1, 3, 8, 32, 33, 65})
  42. for (size_t OC: {1, 3, 8, 32, 33, 65}) {
  43. test_args.emplace_back(
  44. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION,
  45. 0, 0, 1, 1},
  46. N, IC, 7, 7, OC, 5, 5, 3, 3);
  47. }
  48. // clang-format on
  49. return test_args;
  50. }
  51. static inline std::vector<TestArg> get_args_for_intel_gpu() {
  52. std::vector<TestArg> test_args;
  53. // clang-format off
  54. for (size_t N: {32, 64})
  55. for (size_t IC: {1, 3, 8, 32, 33, 65})
  56. for (size_t OC : {1, 3, 8, 32, 33, 65}) {
  57. test_args.emplace_back(
  58. param::Convolution{
  59. param::Convolution::Mode::CROSS_CORRELATION, 0, 0,
  60. 1, 1},
  61. N, IC, 7, 7, OC, 5, 5, 3, 3);
  62. }
  63. // clang-format on
  64. return test_args;
  65. }
  66. static inline std::vector<TestArg> get_args_bwd_data_for_cuda() {
  67. std::vector<TestArg> test_args;
  68. // clang-format off
  69. for (size_t N: {32, 64})
  70. for (size_t IC: {1, 3, 8, 32, 64})
  71. for (size_t OC : {1, 3, 8, 32, 33, 65}) {
  72. test_args.emplace_back(
  73. param::Convolution{
  74. param::Convolution::Mode::CROSS_CORRELATION, 0, 0,
  75. 1, 1},
  76. N, IC, 7, 7, OC, 5, 5, 3, 3);
  77. }
  78. // clang-format on
  79. return test_args;
  80. }
  81. static inline std::vector<TestArg> get_args_bwd_filter_for_cuda() {
  82. std::vector<TestArg> test_args;
  83. // clang-format off
  84. for (size_t N: {32, 64})
  85. for (size_t IC: {1, 3, 8, 32, 56, 80})
  86. for (size_t OC : {1, 3, 8, 32, 33, 65}) {
  87. test_args.emplace_back(
  88. param::Convolution{
  89. param::Convolution::Mode::CROSS_CORRELATION, 0, 0,
  90. 1, 1},
  91. N, IC, 7, 7, OC, 5, 5, 3, 3);
  92. }
  93. // clang-format on
  94. return test_args;
  95. }
  96. static inline std::vector<TestArg> get_args_for_fp16() {
  97. std::vector<TestArg> test_args;
  98. test_args.emplace_back(
  99. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 1,
  100. 1, 1, 1},
  101. 64, 16, 8, 7, 16, 8, 7, 3, 3);
  102. test_args.emplace_back(
  103. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 0,
  104. 0, 1, 1},
  105. 15, 15, 7, 7, 16, 5, 5, 3, 3);
  106. test_args.emplace_back(
  107. param::Convolution{param::Convolution::Mode::CONVOLUTION, 0, 0, 1,
  108. 1},
  109. 15, 15, 7, 7, 16, 5, 5, 3, 3);
  110. test_args.emplace_back(
  111. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 1,
  112. 1, 1, 1},
  113. 15, 15, 5, 5, 16, 5, 5, 3, 3);
  114. test_args.emplace_back(
  115. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 0,
  116. 0, 2, 2},
  117. 15, 15, 7, 7, 16, 3, 3, 3, 3);
  118. /*! \warning: this operator need reduce values along the axis of IC, so this
  119. * will results in large error in fp16 situation. so in the test cases, we
  120. * use small IC values.
  121. */
  122. // clang-format off
  123. for (size_t N: {1, 2})
  124. for (size_t OC : {16, 32, 48, 64}) {
  125. test_args.emplace_back(
  126. param::Convolution{
  127. param::Convolution::Mode::CROSS_CORRELATION, 0, 0,
  128. 1, 1},
  129. N, 16, 7, 7, OC, 5, 5, 3, 3);
  130. test_args.emplace_back(
  131. param::Convolution{param::Convolution::Mode::CONVOLUTION, 0,
  132. 0, 1, 1},
  133. N, 32, 7, 7, OC, 5, 5, 3, 3);
  134. }
  135. // clang-format on
  136. return test_args;
  137. }
  138. static inline std::vector<TestArg> get_args() {
  139. std::vector<TestArg> test_args;
  140. test_args.emplace_back(
  141. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 1,
  142. 1, 1, 1},
  143. 64, 16, 8, 7, 16, 8, 7, 3, 3);
  144. test_args.emplace_back(
  145. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 0,
  146. 0, 1, 1},
  147. 15, 15, 7, 7, 16, 5, 5, 3, 3);
  148. test_args.emplace_back(
  149. param::Convolution{param::Convolution::Mode::CONVOLUTION, 0, 0, 1,
  150. 1},
  151. 15, 15, 7, 7, 16, 5, 5, 3, 3);
  152. test_args.emplace_back(
  153. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 1,
  154. 1, 1, 1},
  155. 15, 15, 5, 5, 16, 5, 5, 3, 3);
  156. test_args.emplace_back(
  157. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 0,
  158. 0, 2, 2},
  159. 15, 15, 7, 7, 16, 3, 3, 3, 3);
  160. for (size_t N : {1, 2})
  161. // clang-format off
  162. for (size_t OC : {16, 32, 48, 64}) {
  163. test_args.emplace_back(
  164. param::Convolution{
  165. param::Convolution::Mode::CROSS_CORRELATION, 0, 0,
  166. 1, 1},
  167. N, 32, 7, 7, OC, 5, 5, 3, 3);
  168. test_args.emplace_back(
  169. param::Convolution{param::Convolution::Mode::CONVOLUTION, 0,
  170. 0, 1, 1},
  171. N, 32, 7, 7, OC, 5, 5, 3, 3);
  172. }
  173. // clang-format on
  174. return test_args;
  175. }
  176. } // namespace local
  177. } // namespace test
  178. } // namespace megdnn
  179. // vim: syntax=cpp.doxygen

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