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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 <cstddef>
  13. #include "megdnn/basic_types.h"
  14. #include "megdnn/opr_param_defs.h"
  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, 0, 1,
  74. 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, 1, 1,
  79. 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, 1, 1, 1},
  118. 64, 16, 8, 7, 16, 8, 7, 3, 3);
  119. test_args.emplace_back(
  120. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 0, 0, 1, 1},
  121. 15, 15, 7, 7, 16, 5, 5, 3, 3);
  122. test_args.emplace_back(
  123. param::Convolution{param::Convolution::Mode::CONVOLUTION, 0, 0, 1, 1}, 15,
  124. 15, 7, 7, 16, 5, 5, 3, 3);
  125. test_args.emplace_back(
  126. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 1, 1, 1, 1},
  127. 15, 15, 5, 5, 16, 5, 5, 3, 3);
  128. test_args.emplace_back(
  129. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 0, 0, 2, 2},
  130. 15, 15, 7, 7, 16, 3, 3, 3, 3);
  131. /*! \warning: this operator need reduce values along the axis of IC, so this
  132. * will results in large error in fp16 situation. so in the test cases, we
  133. * use small IC values.
  134. */
  135. // clang-format off
  136. for (size_t N: {1, 2})
  137. for (size_t OC : {16, 32, 48, 64}) {
  138. test_args.emplace_back(
  139. param::Convolution{
  140. param::Convolution::Mode::CROSS_CORRELATION, 0, 0,
  141. 1, 1},
  142. N, 16, 7, 7, OC, 5, 5, 3, 3);
  143. test_args.emplace_back(
  144. param::Convolution{param::Convolution::Mode::CONVOLUTION, 0,
  145. 0, 1, 1},
  146. N, 32, 7, 7, OC, 5, 5, 3, 3);
  147. }
  148. // clang-format on
  149. return test_args;
  150. }
  151. static inline std::vector<TestArg> get_args() {
  152. std::vector<TestArg> test_args;
  153. test_args.emplace_back(
  154. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 1, 1, 1, 1},
  155. 64, 16, 8, 7, 16, 8, 7, 3, 3);
  156. test_args.emplace_back(
  157. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 0, 0, 1, 1},
  158. 15, 15, 7, 7, 16, 5, 5, 3, 3);
  159. test_args.emplace_back(
  160. param::Convolution{param::Convolution::Mode::CONVOLUTION, 0, 0, 1, 1}, 15,
  161. 15, 7, 7, 16, 5, 5, 3, 3);
  162. test_args.emplace_back(
  163. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 1, 1, 1, 1},
  164. 15, 15, 5, 5, 16, 5, 5, 3, 3);
  165. test_args.emplace_back(
  166. param::Convolution{param::Convolution::Mode::CROSS_CORRELATION, 0, 0, 2, 2},
  167. 15, 15, 7, 7, 16, 3, 3, 3, 3);
  168. for (size_t N : {1, 2})
  169. // clang-format off
  170. for (size_t OC : {16, 32, 48, 64}) {
  171. test_args.emplace_back(
  172. param::Convolution{
  173. param::Convolution::Mode::CROSS_CORRELATION, 0, 0,
  174. 1, 1},
  175. N, 32, 7, 7, OC, 5, 5, 3, 3);
  176. test_args.emplace_back(
  177. param::Convolution{param::Convolution::Mode::CONVOLUTION, 0,
  178. 0, 1, 1},
  179. N, 32, 7, 7, OC, 5, 5, 3, 3);
  180. }
  181. // clang-format on
  182. return test_args;
  183. }
  184. } // namespace local
  185. } // namespace test
  186. } // namespace megdnn
  187. // vim: syntax=cpp.doxygen

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