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.

handle_impl.h 6.8 kB

feat(bazel/windows/xp/sp2/inference): implement inference on windows xp (os vesion >= sp2) build with bazel * bazel build support(define __DEPLOY_ON_XP_SP2__ when deploy on xp sp2): (dbg)./bazel build //brain/megbrain:load_and_run --cpu='x86_windows_xp' --compiler='clang_cl' -c dbg --copt "-D__DEPLOY_ON_XP_SP2__=1" (opt)./bazel build //brain/megbrain:load_and_run --cpu='x86_windows_xp' --compiler='clang_cl' -c opt --copt "-D__DEPLOY_ON_XP_SP2__=1" * internal behavior: will define MGB_HAVE_THREAD=0 when enable __DEPLOY_ON_XP_SP2__ * refer to https://docs.microsoft.com/en-us/cpp/build/configuring-programs-for-windows-xp?view=msvc-160 xp sp2(x86) do not support vc runtime fully, casused by KERNEL32.dll do not implement some base apis for c++ std function, for example, std::mutex/std::thread/std::condition_variable as a workround, we will disable some MegEngine features on xp sp2 env, for exampe, multi-thread etc! * about DNN_MUTEX/MGB_MUTEX, if your code will build in inference code (even CPU backends), please replace std::mutex to DNN_MUTEX/MGB_MUTEX, * about multi-thread, if you code need multi-thread support, please enable it when MGB_HAVE_THREAD=1 * about test build env status 1: Visual Studio 2019(MSVC version <= 14.26.28801)---- pass 2: Visual Studio 2019(MSVC version > 14.26.28801) ---- failed caused by this 'new' version will put VCR depends on win7 KERNEL32.DLL, this may be fixed at Visual Studio 2019 later version but we do not test at this MR merge point 3: Visual Studio 2017 ---------- pass 4: Visual Studio 2014 ---------- pass GitOrigin-RevId: 65ac48b95e99f2c510fe5db449cc8182d682e113
3 years ago
feat(bazel/windows/xp/sp2/inference): implement inference on windows xp (os vesion >= sp2) build with bazel * bazel build support(define __DEPLOY_ON_XP_SP2__ when deploy on xp sp2): (dbg)./bazel build //brain/megbrain:load_and_run --cpu='x86_windows_xp' --compiler='clang_cl' -c dbg --copt "-D__DEPLOY_ON_XP_SP2__=1" (opt)./bazel build //brain/megbrain:load_and_run --cpu='x86_windows_xp' --compiler='clang_cl' -c opt --copt "-D__DEPLOY_ON_XP_SP2__=1" * internal behavior: will define MGB_HAVE_THREAD=0 when enable __DEPLOY_ON_XP_SP2__ * refer to https://docs.microsoft.com/en-us/cpp/build/configuring-programs-for-windows-xp?view=msvc-160 xp sp2(x86) do not support vc runtime fully, casused by KERNEL32.dll do not implement some base apis for c++ std function, for example, std::mutex/std::thread/std::condition_variable as a workround, we will disable some MegEngine features on xp sp2 env, for exampe, multi-thread etc! * about DNN_MUTEX/MGB_MUTEX, if your code will build in inference code (even CPU backends), please replace std::mutex to DNN_MUTEX/MGB_MUTEX, * about multi-thread, if you code need multi-thread support, please enable it when MGB_HAVE_THREAD=1 * about test build env status 1: Visual Studio 2019(MSVC version <= 14.26.28801)---- pass 2: Visual Studio 2019(MSVC version > 14.26.28801) ---- failed caused by this 'new' version will put VCR depends on win7 KERNEL32.DLL, this may be fixed at Visual Studio 2019 later version but we do not test at this MR merge point 3: Visual Studio 2017 ---------- pass 4: Visual Studio 2014 ---------- pass GitOrigin-RevId: 65ac48b95e99f2c510fe5db449cc8182d682e113
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /**
  2. * \file dnn/src/common/handle_impl.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/handle.h"
  13. #include "megdnn/oprs.h"
  14. #include "src/common/utils.h"
  15. #include <mutex>
  16. #include "midout.h"
  17. MIDOUT_DECL(dnn_src_common_handle_impl)
  18. namespace megdnn {
  19. class HandleImplHelper : public Handle {
  20. public:
  21. using Handle::Handle;
  22. //! global matmul opr
  23. virtual MatrixMul* matmul_opr() { megdnn_throw("Unimplement matmul opr.\n"); }
  24. //! global matmul opr with first operand transposed
  25. virtual MatrixMul* matmul_aT_opr() { megdnn_throw("Unimplement matmul_aT opr.\n"); }
  26. //! global matmul opr with second operand transposed
  27. virtual MatrixMul* matmul_bT_opr() { megdnn_throw("Unimplement matmul_bT opr.\n"); }
  28. //! global matmul opr with both operand transposed
  29. virtual MatrixMul* matmul_aT_bT_opr() {
  30. megdnn_throw("Unimplement matmul_aT_bT opr.\n");
  31. }
  32. //! global relayout opr
  33. virtual Relayout* relayout_opr() { megdnn_throw("Unimplement Relayout opr.\n"); }
  34. virtual Checksum* checksum_opr() { megdnn_throw("Unimplement Checksum opr.\n"); }
  35. virtual MaxTensorDiff* max_tensor_diff_opr() {
  36. megdnn_throw("Unimplement MaxTensorDiff opr.\n");
  37. }
  38. protected:
  39. static constexpr size_t NR_HELPER_OPRS = 7;
  40. template <class Opr, size_t idx, class Self>
  41. static Opr* get_helper_opr(Self self, const typename Opr::Param& param = {}) {
  42. MIDOUT_BEGIN(dnn_src_common_handle_impl, Opr, idx) {
  43. static_assert(idx < NR_HELPER_OPRS, "invalid idx");
  44. if (!self->m_helper_oprs[idx]) {
  45. MEGDNN_LOCK_GUARD(self->m_helper_oprs_mtx);
  46. if (!self->m_helper_oprs[idx]) {
  47. self->m_helper_oprs[idx] = self->template create_operator<Opr>();
  48. auto ret = static_cast<Opr*>(self->m_helper_oprs[idx].get());
  49. ret->param() = param;
  50. megdnn_assert(ret->is_thread_safe());
  51. return ret;
  52. }
  53. }
  54. return static_cast<Opr*>(self->m_helper_oprs[idx].get());
  55. }
  56. MIDOUT_END();
  57. }
  58. private:
  59. std::array<std::unique_ptr<OperatorBase>, NR_HELPER_OPRS> m_helper_oprs;
  60. DNN_MUTEX m_helper_oprs_mtx;
  61. };
  62. } // namespace megdnn
  63. /*!
  64. * \brief iterate though each operator class name; useful for explicit
  65. * instantialization of create_operator<> templates
  66. */
  67. // clang-format off
  68. #define MEGDNN_FOREACH_OPR_CLASS(cb) \
  69. cb(ConvolutionForward) \
  70. cb(ConvolutionBackwardData) \
  71. cb(ConvolutionBackwardFilter) \
  72. cb(ConvPoolingForward) \
  73. cb(ConvBiasForward) \
  74. cb(Images2NeibsForward) \
  75. cb(Images2NeibsBackward) \
  76. cb(SlidingWindowTransposeForward) \
  77. cb(SlidingWindowTransposeBackward) \
  78. cb(ElemwiseForward) \
  79. cb(ElemwiseMultiType) \
  80. cb(AddUpdateForward) \
  81. cb(RelayoutForward) \
  82. cb(PoolingForward) \
  83. cb(PoolingBackward) \
  84. cb(LocalForward) \
  85. cb(LocalBackwardData) \
  86. cb(LocalBackwardFilter) \
  87. cb(LRNForward) \
  88. cb(LRNBackward) \
  89. cb(ROIPoolingForward) \
  90. cb(ROIPoolingBackward) \
  91. cb(WarpPerspectiveForward) \
  92. cb(WarpPerspectiveBackwardData) \
  93. cb(WarpPerspectiveBackwardMat) \
  94. cb(DotForward) \
  95. cb(MatrixInverse) \
  96. cb(MatrixMulForward) \
  97. cb(BatchedMatrixMulForward) \
  98. cb(SVDForward) \
  99. cb(ReduceForward) \
  100. cb(CondTake) \
  101. cb(CumsumForward) \
  102. cb(ArgmaxForward) \
  103. cb(ArgminForward) \
  104. cb(TransposeForward) \
  105. cb(ConcatForward) \
  106. cb(SplitForward) \
  107. cb(TileForward) \
  108. cb(TileBackward) \
  109. cb(RepeatForward) \
  110. cb(RepeatBackward) \
  111. cb(ArgsortForward) \
  112. cb(ArgsortBackward) \
  113. cb(TypeCvt) \
  114. cb(IndexingRemapForward) \
  115. cb(IndexingRemapBackward) \
  116. cb(ChecksumForward) \
  117. cb(IndexingOneHotForward) \
  118. cb(IndexingSetOneHotForward) \
  119. cb(IndexingMultiAxisVec) \
  120. cb(IndexingSetMultiAxisVec) \
  121. cb(IndexingIncrMultiAxisVec) \
  122. cb(MeshIndexing) \
  123. cb(IncrMeshIndexing) \
  124. cb(SetMeshIndexing) \
  125. cb(BatchedMeshIndexing) \
  126. cb(BatchedIncrMeshIndexing) \
  127. cb(BatchedSetMeshIndexing) \
  128. cb(Linspace) \
  129. cb(Eye) \
  130. cb(SleepForward) \
  131. cb(UniformRNG) \
  132. cb(GaussianRNG) \
  133. cb(GammaRNG) \
  134. cb(BetaRNG) \
  135. cb(PoissonRNG) \
  136. cb(PermutationRNG) \
  137. cb(ShuffleRNGForward) \
  138. cb(ShuffleRNGBackward) \
  139. cb(SeparableConvForward) \
  140. cb(SeparableFilterForward) \
  141. cb(BNForward) \
  142. cb(BNBackward) \
  143. cb(GroupLocalForward) \
  144. cb(GroupLocalBackwardData) \
  145. cb(GroupLocalBackwardFilter) \
  146. cb(Flip) \
  147. cb(Rotate) \
  148. cb(ROICopy) \
  149. cb(CvtColor) \
  150. cb(WarpAffine) \
  151. cb(GaussianBlur) \
  152. cb(Resize) \
  153. cb(ResizeBackward) \
  154. cb(ParamPackConcat) \
  155. cb(MaxTensorDiff) \
  156. cb(MaskConvForward) \
  157. cb(MaskPropagate) \
  158. cb(Convolution3DForward) \
  159. cb(Convolution3DBackwardData) \
  160. cb(Convolution3DBackwardFilter) \
  161. cb(DeformableConvForward) \
  162. cb(DeformableConvBackwardFilter) \
  163. cb(DeformableConvBackwardData) \
  164. cb(DeformablePSROIPoolingForward) \
  165. cb(DeformablePSROIPoolingBackward) \
  166. cb(RelayoutFormat) \
  167. cb(TopK) \
  168. cb(PowC) \
  169. cb(LocalShareForward) \
  170. cb(LocalShareBackwardData) \
  171. cb(LocalShareBackwardFilter) \
  172. cb(ROIAlignForward) \
  173. cb(ROIAlignBackward) \
  174. cb(CorrelationForward) \
  175. cb(CorrelationBackwardData1) \
  176. cb(CorrelationBackwardData2) \
  177. cb(BatchConvBiasForward) \
  178. cb(Remap) \
  179. cb(RemapBackwardData) \
  180. cb(RemapBackwardMat) \
  181. cb(AdaptivePoolingForward) \
  182. cb(AdaptivePoolingBackward) \
  183. cb(DctChannelSelectForward) \
  184. cb(FakeQuantForward) \
  185. cb(FakeQuantBackward) \
  186. cb(TQTForward) \
  187. cb(TQTBackward) \
  188. cb(CheckNonFinite) \
  189. cb(LSQForward) \
  190. cb(LSQBackward) \
  191. cb(Fill) \
  192. cb(PaddingForward) \
  193. cb(PaddingBackward)
  194. // clang-format on
  195. /*!
  196. * \brief specialize HandleImpl::create_operator for a single opr type;
  197. * implemented by <opr>Impl class
  198. */
  199. #define MEGDNN_SPECIALIZE_CREATE_OPERATOR(opr) \
  200. template <> \
  201. std::unique_ptr<megdnn::opr> HandleImpl::create_operator() { \
  202. return megdnn::make_unique<opr##Impl>(this); \
  203. }
  204. /*!
  205. * \brief for explicit instantiation for HandleImpl::create_operator methods
  206. */
  207. #define MEGDNN_INST_CREATE_OPERATOR(opr) \
  208. template std::unique_ptr<megdnn::opr> HandleImpl::create_operator();
  209. // vim: syntax=cpp.doxygen