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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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-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. #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_for_opencl() {
  67. std::vector<TestArg> test_args;
  68. for (size_t N : {32, 64})
  69. for (size_t IC : {1, 3, 32})
  70. for (size_t OC : {1, 3, 32}) {
  71. test_args.emplace_back(
  72. param::Convolution{
  73. param::Convolution::Mode::CROSS_CORRELATION, 0,
  74. 0, 1, 1},
  75. N, IC, 7, 7, OC, 5, 5, 3, 3);
  76. test_args.emplace_back(
  77. param::Convolution{
  78. param::Convolution::Mode::CROSS_CORRELATION, 1,
  79. 1, 1, 1},
  80. N, IC, 7, 7, OC, 7, 7, 3, 3);
  81. }
  82. return test_args;
  83. }
  84. static inline std::vector<TestArg> get_args_bwd_data_for_cuda() {
  85. std::vector<TestArg> test_args;
  86. // clang-format off
  87. for (size_t N: {32, 64})
  88. for (size_t IC: {1, 3, 8, 32, 64})
  89. for (size_t OC : {1, 3, 8, 32, 33, 65}) {
  90. test_args.emplace_back(
  91. param::Convolution{
  92. param::Convolution::Mode::CROSS_CORRELATION, 0, 0,
  93. 1, 1},
  94. N, IC, 7, 7, OC, 5, 5, 3, 3);
  95. }
  96. // clang-format on
  97. return test_args;
  98. }
  99. static inline std::vector<TestArg> get_args_bwd_filter_for_cuda() {
  100. std::vector<TestArg> test_args;
  101. // clang-format off
  102. for (size_t N: {32, 64})
  103. for (size_t IC: {1, 3, 8, 32, 56, 80})
  104. for (size_t OC : {1, 3, 8, 32, 33, 65}) {
  105. test_args.emplace_back(
  106. param::Convolution{
  107. param::Convolution::Mode::CROSS_CORRELATION, 0, 0,
  108. 1, 1},
  109. N, IC, 7, 7, OC, 5, 5, 3, 3);
  110. }
  111. // clang-format on
  112. return test_args;
  113. }
  114. static inline std::vector<TestArg> get_args_for_fp16() {
  115. std::vector<TestArg> test_args;
  116. test_args.emplace_back(
  117. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 1,
  118. 1, 1, 1},
  119. 64, 16, 8, 7, 16, 8, 7, 3, 3);
  120. test_args.emplace_back(
  121. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 0,
  122. 0, 1, 1},
  123. 15, 15, 7, 7, 16, 5, 5, 3, 3);
  124. test_args.emplace_back(
  125. param::Convolution{param::Convolution::Mode::CONVOLUTION, 0, 0, 1,
  126. 1},
  127. 15, 15, 7, 7, 16, 5, 5, 3, 3);
  128. test_args.emplace_back(
  129. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 1,
  130. 1, 1, 1},
  131. 15, 15, 5, 5, 16, 5, 5, 3, 3);
  132. test_args.emplace_back(
  133. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 0,
  134. 0, 2, 2},
  135. 15, 15, 7, 7, 16, 3, 3, 3, 3);
  136. /*! \warning: this operator need reduce values along the axis of IC, so this
  137. * will results in large error in fp16 situation. so in the test cases, we
  138. * use small IC values.
  139. */
  140. // clang-format off
  141. for (size_t N: {1, 2})
  142. for (size_t OC : {16, 32, 48, 64}) {
  143. test_args.emplace_back(
  144. param::Convolution{
  145. param::Convolution::Mode::CROSS_CORRELATION, 0, 0,
  146. 1, 1},
  147. N, 16, 7, 7, OC, 5, 5, 3, 3);
  148. test_args.emplace_back(
  149. param::Convolution{param::Convolution::Mode::CONVOLUTION, 0,
  150. 0, 1, 1},
  151. N, 32, 7, 7, OC, 5, 5, 3, 3);
  152. }
  153. // clang-format on
  154. return test_args;
  155. }
  156. static inline std::vector<TestArg> get_args() {
  157. std::vector<TestArg> test_args;
  158. test_args.emplace_back(
  159. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 1,
  160. 1, 1, 1},
  161. 64, 16, 8, 7, 16, 8, 7, 3, 3);
  162. test_args.emplace_back(
  163. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 0,
  164. 0, 1, 1},
  165. 15, 15, 7, 7, 16, 5, 5, 3, 3);
  166. test_args.emplace_back(
  167. param::Convolution{param::Convolution::Mode::CONVOLUTION, 0, 0, 1,
  168. 1},
  169. 15, 15, 7, 7, 16, 5, 5, 3, 3);
  170. test_args.emplace_back(
  171. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 1,
  172. 1, 1, 1},
  173. 15, 15, 5, 5, 16, 5, 5, 3, 3);
  174. test_args.emplace_back(
  175. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 0,
  176. 0, 2, 2},
  177. 15, 15, 7, 7, 16, 3, 3, 3, 3);
  178. for (size_t N : {1, 2})
  179. // clang-format off
  180. for (size_t OC : {16, 32, 48, 64}) {
  181. test_args.emplace_back(
  182. param::Convolution{
  183. param::Convolution::Mode::CROSS_CORRELATION, 0, 0,
  184. 1, 1},
  185. N, 32, 7, 7, OC, 5, 5, 3, 3);
  186. test_args.emplace_back(
  187. param::Convolution{param::Convolution::Mode::CONVOLUTION, 0,
  188. 0, 1, 1},
  189. N, 32, 7, 7, OC, 5, 5, 3, 3);
  190. }
  191. // clang-format on
  192. return test_args;
  193. }
  194. } // namespace local
  195. } // namespace test
  196. } // namespace megdnn
  197. // vim: syntax=cpp.doxygen

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