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.

base.h 21 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. /**
  2. * \file dnn/include/megdnn/oprs/base.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
  10. * implied.
  11. */
  12. #pragma once
  13. #include <type_traits>
  14. #include "megdnn/basic_types.h"
  15. #include "megdnn/handle.h"
  16. #include "megdnn/internal/visibility_prologue.h"
  17. namespace megdnn {
  18. class Handle;
  19. /**
  20. * \brief base class for all operators
  21. *
  22. * This is an helper class. Users should not use OperatorBase directly.
  23. * Operators should be created by handle->create_opr<>().
  24. *
  25. * Each operator must provides the following constexpr values:
  26. *
  27. * * NR_INPUTS: number of input vars
  28. * * NR_OUTPUTS: number of output vars
  29. * * OPERATOR_TYPE: operator type as an enum
  30. *
  31. * If the operator has dynamic inputs or in_out param, the corresponding
  32. * NR_INPUTS is -1.
  33. *
  34. * For an operator whose NR_INPUTS >= 0 and NR_OUTPUTS >= 0, the operator must
  35. * also provide following methods:
  36. *
  37. * * void exec(_megdnn_in inputs..., _megdnn_tensor_out outputs...,
  38. * _megdnn_workspace workspace)
  39. * * void deduce_layout(const TensorLayout& inputs...,
  40. * TensorLayout& outputs...)
  41. * * size_t get_workspace_in_bytes(const TensorLayout &inputs...,
  42. * const TensorLayout &outputs)
  43. */
  44. class OperatorBase {
  45. public:
  46. explicit OperatorBase(Handle* handle) : m_handle(handle) {}
  47. virtual ~OperatorBase();
  48. //! get the handle from which this operator is created
  49. Handle* handle() const { return m_handle; }
  50. //! whether this opr guarantees that its exec() is thread-safe
  51. virtual bool is_thread_safe() const { return false; }
  52. /*!
  53. * \brief set the tracker to be used with MegcoreAsyncErrorInfo
  54. *
  55. * Most operators do not have async errors so this function has a
  56. * default empty implementation.
  57. */
  58. virtual void set_error_tracker(void*) {}
  59. private:
  60. Handle* m_handle;
  61. };
  62. namespace detail {
  63. /**
  64. * \brief AlgoSelectionStrategy is the advance information for selecting
  65. * algo
  66. */
  67. enum class AlgoSelectionStrategy {
  68. HEURISTIC = 0, //!< heristic to select the algos
  69. FAST_RUN = 1,
  70. FULL_RUN = 2,
  71. };
  72. /**
  73. * \brief separate algo by datatype for Matmul and conv
  74. */
  75. enum class AlgoDataType : uint32_t {
  76. FLOAT32 = 1 << 0,
  77. FLOAT16 = 1 << 1,
  78. QINT8X8X32 = 1 << 2,
  79. QUINT8X8X32 = 1 << 3,
  80. INT8X8X16 = 1 << 4,
  81. INT16X16X32 = 1 << 5,
  82. INT4X4X16 = 1 << 6,
  83. };
  84. /*!
  85. * \brief Abstract representation of an algorithm for implementing
  86. * the operator
  87. */
  88. class Algorithm {
  89. public:
  90. static constexpr uint32_t INVALID_ALGO_TYPE = static_cast<uint32_t>(-1);
  91. /**
  92. * \brief the attribe of the algo, such as REPRODUCIBLE, NAIVE
  93. *
  94. */
  95. enum class Attribute : uint32_t {
  96. /**
  97. * \brief general algo.
  98. */
  99. DEFAULT = 0,
  100. /**
  101. * \brief whether the execution result is
  102. * reproducible across multiple runs.
  103. */
  104. REPRODUCIBLE = 1 << 0,
  105. /**
  106. * \brief whether the algo is naive
  107. * Mark algorithms with simple implementation as NAIVE, so we can filter
  108. * these algorithms to speed up fastrun.
  109. * */
  110. NAIVE = 1 << 1,
  111. /**
  112. * \brief whether the algo is usable once shape changed.
  113. * */
  114. USABLE_DEPEND_ON_SHAPE = 1 << 2,
  115. /**
  116. * \brief whether the accuracy of the algo is dependent with respect
  117. * to batch
  118. * In the case of using algorithm with this attribute, even if the
  119. * content of each batch is the same, the output under multiple batch
  120. * input and single batch input may not equal
  121. * */
  122. ACCURACY_DEPEND_ON_BATCH = 1 << 3,
  123. };
  124. /**
  125. * \brief Algorithm information, we can get real algo from
  126. * AlgorithmInfo::Info::Desc
  127. */
  128. struct Info {
  129. struct Desc {
  130. //! backend of the algo belonging to
  131. Handle::HandleType handle_type;
  132. //! indicate the real algo implementation
  133. uint32_t type = INVALID_ALGO_TYPE;
  134. //! serialized param of the algo type
  135. std::string param;
  136. //! algorithm name
  137. std::string name;
  138. bool valid() const { return type != INVALID_ALGO_TYPE; }
  139. void reset() { type = INVALID_ALGO_TYPE; }
  140. bool operator==(const Desc& rhs) const {
  141. return handle_type == rhs.handle_type && type == rhs.type &&
  142. param == rhs.param && name == rhs.name;
  143. }
  144. } desc;
  145. Attribute attribute;
  146. bool valid() const { return desc.valid(); }
  147. void reset() { desc.reset(); }
  148. //! desc donate the algo
  149. bool operator==(const Info& rhs) const { return desc == rhs.desc; }
  150. };
  151. virtual ~Algorithm() = default;
  152. /**
  153. * \brief get the attribute of the algo
  154. */
  155. virtual Attribute attribute() const = 0;
  156. virtual const char* name() const = 0;
  157. //! serialized param
  158. virtual std::string param() const { return {}; }
  159. virtual uint32_t type() const = 0;
  160. //! if algo contain all of the attribute in attr
  161. bool contain_attribute_all(const Attribute& attr) const;
  162. //! if algo contain any attribute in attr
  163. bool contain_attribute_any(const Attribute& attr) const;
  164. void check_attribute(
  165. const Attribute& positive_attr = Attribute::DEFAULT,
  166. const Attribute& negative_attr = Attribute::DEFAULT) const;
  167. static std::string attribute_str(const Attribute& attr);
  168. Handle::HandleType handle_type() const { return m_handle_type; }
  169. Info::Desc desc() const { return {handle_type(), type(), param(), name()}; }
  170. Info info() const {
  171. return {desc(), attribute()};
  172. }
  173. template <typename T>
  174. static void serialize_write_pod(const T& val, std::string& result) {
  175. static_assert(std::is_trivially_copyable<T>::value,
  176. "type should be trivially copyable");
  177. static_assert(!std::is_pointer<T>::value,
  178. "serialize pointer is unsafe in eager execution mode");
  179. result.append(reinterpret_cast<const char*>(&val), sizeof(T));
  180. }
  181. static void serialize_write_pod(const char* val, std::string& result) {
  182. result.append(val, strlen(val));
  183. }
  184. template <typename T>
  185. static T deserialize_read_pod(const std::string& data, size_t offset = 0) {
  186. static_assert(std::is_trivially_copyable<T>::value, "invalid type");
  187. T ret;
  188. //! A pointer to an object or incomplete type may be converted to a
  189. //! pointer to a different object or incomplete type. If the resulting
  190. //! pointer is not correctly aligned for the pointed-to type, the
  191. //! behavior is undefined.
  192. //!
  193. //! so here we should use memcpy instead of
  194. //! *reinterpret_cast<const T*>(&data[offset]);
  195. memcpy(&ret, data.data() + offset, sizeof(T));
  196. return ret;
  197. }
  198. template <typename T>
  199. static T deserialize_read_pod(const char* data, size_t offset = 0) {
  200. static_assert(std::is_trivially_copyable<T>::value, "invalid type");
  201. T ret;
  202. //! A pointer to an object or incomplete type may be converted to a
  203. //! pointer to a different object or incomplete type. If the resulting
  204. //! pointer is not correctly aligned for the pointed-to type, the
  205. //! behavior is undefined.
  206. //!
  207. //! so here we should use memcpy instead of
  208. //! *reinterpret_cast<const T*>(&data[offset]);
  209. memcpy(&ret, data + offset, sizeof(T));
  210. return ret;
  211. }
  212. enum class OprType : uint32_t {
  213. MATRIX_MUL_FORWARD,
  214. BATCHED_MATRIX_MUL_FORWARD,
  215. CONVOLUTION_FORWARD,
  216. CONVOLUTION_BACKWARD_DATA,
  217. CONVOLUTION_BACKWARD_FILTER,
  218. CONVOLUTION3D_FORWARD,
  219. CONVOLUTION3D_BACKWARD_DATA,
  220. CONVOLUTION3D_BACKWARD_FILTER,
  221. LOCAL_SHARE_FORWARD,
  222. LOCAL_SHARE_BACKWARD_DATA,
  223. LOCAL_SHARE_BACKWARD_FILTER,
  224. DEFORMABLE_CONV_FORWARD,
  225. DEFORMABLE_CONV_BACKWARD_DATA,
  226. DEFORMABLE_CONV_BACKWARD_FILTER,
  227. CONVBIAS_FORWARD,
  228. BATCH_CONV_FORWARD,
  229. };
  230. struct SearchItem {
  231. OprType opr_type;
  232. //! serialized param
  233. std::string param;
  234. TensorLayoutArray layouts;
  235. };
  236. /**
  237. * \brief get subopr list of the algo
  238. *
  239. * \param layouts origin layouts of the parent opr
  240. * \param opr parent opr
  241. */
  242. virtual std::vector<SearchItem> get_subopr_list(const TensorLayoutArray&,
  243. const OperatorBase*) const {
  244. return {};
  245. }
  246. protected:
  247. Handle::HandleType m_handle_type = Handle::HandleType::NAIVE;
  248. };
  249. MEGDNN_DEF_ENUM_CLASS_BIT_OPR(Algorithm::Attribute)
  250. //! policy for executing the operator
  251. struct ExecutionPolicy {
  252. //! INVALID_ALGO_TYPE algo_type means using heuristic
  253. Algorithm::Info::Desc algo;
  254. std::vector<ExecutionPolicy> sub_policy;
  255. };
  256. /*!
  257. * \brief define Algorithm and ExecutionPolicy for oprs that have
  258. * multiple impl algos
  259. *
  260. * \tparam Opr the operator class
  261. * \tparam nargs number of arguments
  262. */
  263. template <class Opr, int nargs>
  264. class MultiAlgoOpr;
  265. //! base def
  266. template <class Opr>
  267. class MultiAlgoOpr<Opr, -1> {
  268. public:
  269. using AlgorithmInfo = detail::Algorithm::Info;
  270. using AlgorithmDesc = detail::Algorithm::Info::Desc;
  271. using Algorithm = detail::Algorithm;
  272. /*!
  273. * \brief get a string representation for current algorithm set;
  274. *
  275. * get_all_algorithms() may return different algorithms only if
  276. * algorithm set name differs. This is used for checking cache
  277. * validity.
  278. */
  279. virtual const char* get_algorithm_set_name() const = 0;
  280. ExecutionPolicy& execution_policy() { return m_execution_policy; }
  281. const ExecutionPolicy& execution_policy() const {
  282. return m_execution_policy;
  283. }
  284. virtual Algorithm* get_algorithm_from_desc(const AlgorithmDesc&) = 0;
  285. protected:
  286. ~MultiAlgoOpr() = default;
  287. private:
  288. ExecutionPolicy m_execution_policy;
  289. };
  290. //! specialize for nargs == 3
  291. template <class Opr>
  292. class MultiAlgoOpr<Opr, 3> : public MultiAlgoOpr<Opr, -1> {
  293. public:
  294. using Algorithm = detail::Algorithm;
  295. using AlgorithmInfo = detail::Algorithm::Info;
  296. using AlgoAttribute = detail::Algorithm::Attribute;
  297. //! get all possible algorithm decriptions for the specified layouts
  298. std::vector<AlgorithmInfo> get_all_algorithms_info(const TensorLayout& p0,
  299. const TensorLayout& p1,
  300. const TensorLayout& p2) {
  301. std::vector<AlgorithmInfo> ret;
  302. for (auto&& algo : get_all_algorithms(p0, p1, p2)) {
  303. ret.emplace_back(algo->info());
  304. }
  305. return ret;
  306. }
  307. /**
  308. * \brief Returns the best algorithm information which indicate the
  309. * algorithm by heuristic.
  310. *
  311. * The selected algorithm should not use workspace more than
  312. * \p workspace_limit_in_bytes.
  313. */
  314. AlgorithmInfo get_algorithm_info_heuristic(
  315. const TensorLayout& p0, const TensorLayout& p1,
  316. const TensorLayout& p2,
  317. size_t workspace_limit_in_bytes =
  318. std::numeric_limits<size_t>::max(),
  319. const AlgoAttribute& positive_attr = AlgoAttribute::DEFAULT,
  320. const AlgoAttribute& negative_attr = AlgoAttribute::DEFAULT) {
  321. return get_algorithm_heuristic(p0, p1, p2, workspace_limit_in_bytes,
  322. positive_attr, negative_attr)
  323. ->info();
  324. }
  325. protected:
  326. ~MultiAlgoOpr() = default;
  327. //! get all possible algorithms for the specified layouts
  328. virtual std::vector<Algorithm*> get_all_algorithms(
  329. const TensorLayout& p0, const TensorLayout& p1,
  330. const TensorLayout& p2) = 0;
  331. /**
  332. * \brief Returns the best algorithm by heuristic.
  333. *
  334. * The selected algorithm should not use workspace more than
  335. * \p workspace_limit_in_bytes.
  336. */
  337. virtual Algorithm* get_algorithm_heuristic(
  338. const TensorLayout& p0, const TensorLayout& p1,
  339. const TensorLayout& p2,
  340. size_t workspace_limit_in_bytes =
  341. std::numeric_limits<size_t>::max(),
  342. const AlgoAttribute& positive_attr = AlgoAttribute::DEFAULT,
  343. const AlgoAttribute& negative_attr = AlgoAttribute::DEFAULT) = 0;
  344. };
  345. //! specializae for nargs == 4
  346. template <class Opr>
  347. class MultiAlgoOpr<Opr, 4> : public MultiAlgoOpr<Opr, -1> {
  348. public:
  349. using Algorithm = detail::Algorithm;
  350. using AlgorithmInfo = detail::Algorithm::Info;
  351. using AlgoAttribute = detail::Algorithm::Attribute;
  352. //! get all possible algorithm decriptions for the specified layouts
  353. std::vector<AlgorithmInfo> get_all_algorithms_info(const TensorLayout& p0,
  354. const TensorLayout& p1,
  355. const TensorLayout& p2,
  356. const TensorLayout& p3) {
  357. std::vector<AlgorithmInfo> ret;
  358. for (auto&& algo : get_all_algorithms(p0, p1, p2, p3)) {
  359. ret.emplace_back(algo->info());
  360. }
  361. return ret;
  362. }
  363. /**
  364. * \brief Returns the best algorithm information which indicate the
  365. * algorithm by heuristic.
  366. *
  367. * The selected algorithm should not use workspace more than
  368. * \p workspace_limit_in_bytes.
  369. */
  370. AlgorithmInfo get_algorithm_info_heuristic(
  371. const TensorLayout& p0, const TensorLayout& p1,
  372. const TensorLayout& p2, const TensorLayout& p3,
  373. size_t workspace_limit_in_bytes =
  374. std::numeric_limits<size_t>::max(),
  375. const AlgoAttribute& positive_attr = AlgoAttribute::DEFAULT,
  376. const AlgoAttribute& negative_attr = AlgoAttribute::DEFAULT) {
  377. return get_algorithm_heuristic(p0, p1, p2, p3, workspace_limit_in_bytes,
  378. positive_attr, negative_attr)
  379. ->info();
  380. }
  381. protected:
  382. ~MultiAlgoOpr() = default;
  383. //! get all possible algorithms for the specified layouts
  384. virtual std::vector<Algorithm*> get_all_algorithms(
  385. const TensorLayout& p0, const TensorLayout& p1,
  386. const TensorLayout& p2, const TensorLayout& p3) = 0;
  387. /**
  388. * \brief Returns the best algorithm by heuristic.
  389. *
  390. * The selected algorithm should not use workspace more than
  391. * \p workspace_limit_in_bytes.
  392. */
  393. virtual Algorithm* get_algorithm_heuristic(
  394. const TensorLayout& p0, const TensorLayout& p1,
  395. const TensorLayout& p2, const TensorLayout& p3,
  396. size_t workspace_limit_in_bytes =
  397. std::numeric_limits<size_t>::max(),
  398. const AlgoAttribute& positive_attr = AlgoAttribute::DEFAULT,
  399. const AlgoAttribute& negative_attr = AlgoAttribute::DEFAULT) = 0;
  400. };
  401. //! specializae for nargs == 5
  402. template <class Opr>
  403. class MultiAlgoOpr<Opr, 5> : public MultiAlgoOpr<Opr, -1> {
  404. public:
  405. using Algorithm = detail::Algorithm;
  406. using AlgorithmInfo = detail::Algorithm::Info;
  407. using AlgoAttribute = detail::Algorithm::Attribute;
  408. //! get all possible algorithm decriptions for the specified layouts
  409. std::vector<AlgorithmInfo> get_all_algorithms_info(const TensorLayout& p0,
  410. const TensorLayout& p1,
  411. const TensorLayout& p2,
  412. const TensorLayout& p3,
  413. const TensorLayout& p4) {
  414. std::vector<AlgorithmInfo> ret;
  415. for (auto&& algo : get_all_algorithms(p0, p1, p2, p3, p4)) {
  416. ret.emplace_back(algo->info());
  417. }
  418. return ret;
  419. }
  420. /**
  421. * \brief Returns the best algorithm information which indicate the
  422. * algorithm by heuristic.
  423. *
  424. * The selected algorithm should not use workspace more than
  425. * \p workspace_limit_in_bytes.
  426. */
  427. AlgorithmInfo get_algorithm_info_heuristic(
  428. const TensorLayout& p0, const TensorLayout& p1,
  429. const TensorLayout& p2, const TensorLayout& p3,
  430. const TensorLayout& p4,
  431. size_t workspace_limit_in_bytes =
  432. std::numeric_limits<size_t>::max(),
  433. const AlgoAttribute& positive_attr = AlgoAttribute::DEFAULT,
  434. const AlgoAttribute& negative_attr = AlgoAttribute::DEFAULT) {
  435. return get_algorithm_heuristic(p0, p1, p2, p3, p4,
  436. workspace_limit_in_bytes, positive_attr,
  437. negative_attr)
  438. ->info();
  439. }
  440. protected:
  441. ~MultiAlgoOpr() = default;
  442. //! get all possible algorithms for the specified layouts
  443. virtual std::vector<Algorithm*> get_all_algorithms(
  444. const TensorLayout& p0, const TensorLayout& p1,
  445. const TensorLayout& p2, const TensorLayout& p3,
  446. const TensorLayout& p4) = 0;
  447. /**
  448. * \brief Returns the best algorithm by heuristic.
  449. *
  450. * The selected algorithm should not use workspace more than
  451. * \p workspace_limit_in_bytes.
  452. */
  453. virtual Algorithm* get_algorithm_heuristic(
  454. const TensorLayout& p0, const TensorLayout& p1,
  455. const TensorLayout& p2, const TensorLayout& p3,
  456. const TensorLayout& p4,
  457. size_t workspace_limit_in_bytes =
  458. std::numeric_limits<size_t>::max(),
  459. const AlgoAttribute& positive_attr = AlgoAttribute::DEFAULT,
  460. const AlgoAttribute& negative_attr = AlgoAttribute::DEFAULT) = 0;
  461. };
  462. //! specializae for nargs == 8
  463. template <class Opr>
  464. class MultiAlgoOpr<Opr, 8> : public MultiAlgoOpr<Opr, -1> {
  465. public:
  466. using Algorithm = detail::Algorithm;
  467. using AlgorithmInfo = detail::Algorithm::Info;
  468. using AlgoAttribute = detail::Algorithm::Attribute;
  469. //! get all possible algorithm decriptions for the specified layouts
  470. std::vector<AlgorithmInfo> get_all_algorithms_info(
  471. const TensorLayout& p0, const TensorLayout& p1,
  472. const TensorLayout& p2, const TensorLayout& p3,
  473. const TensorLayout& p4, const TensorLayout& p5,
  474. const TensorLayout& p6, const TensorLayout& p7) {
  475. std::vector<AlgorithmInfo> ret;
  476. for (auto&& algo : get_all_algorithms(p0, p1, p2, p3, p4, p5, p6, p7)) {
  477. ret.emplace_back(algo->info());
  478. }
  479. return ret;
  480. }
  481. /**
  482. * \brief Returns the best algorithm information which indicate the
  483. * algorithm by heuristic.
  484. *
  485. * The selected algorithm should not use workspace more than
  486. */
  487. AlgorithmInfo get_algorithm_info_heuristic(
  488. const TensorLayout& p0, const TensorLayout& p1,
  489. const TensorLayout& p2, const TensorLayout& p3,
  490. const TensorLayout& p4, const TensorLayout& p5,
  491. const TensorLayout& p6, const TensorLayout& p7,
  492. size_t workspace_limit_in_bytes =
  493. std::numeric_limits<size_t>::max(),
  494. const AlgoAttribute& positive_attr = AlgoAttribute::DEFAULT,
  495. const AlgoAttribute& negative_attr = AlgoAttribute::DEFAULT) {
  496. return get_algorithm_heuristic(p0, p1, p2, p3, p4, p5, p6, p7,
  497. workspace_limit_in_bytes, positive_attr,
  498. negative_attr)
  499. ->info();
  500. }
  501. protected:
  502. ~MultiAlgoOpr() = default;
  503. //! get all possible algorithms for the specified layouts
  504. virtual std::vector<Algorithm*> get_all_algorithms(
  505. const TensorLayout& p0, const TensorLayout& p1,
  506. const TensorLayout& p2, const TensorLayout& p3,
  507. const TensorLayout& p4, const TensorLayout& p5,
  508. const TensorLayout& p6, const TensorLayout& p7) = 0;
  509. /**
  510. * \brief Returns the best algorithm by heuristic.
  511. *
  512. * The selected algorithm should not use workspace more than
  513. * \p workspace_limit_in_bytes.
  514. */
  515. virtual Algorithm* get_algorithm_heuristic(
  516. const TensorLayout& p0, const TensorLayout& p1,
  517. const TensorLayout& p2, const TensorLayout& p3,
  518. const TensorLayout& p4, const TensorLayout& p5,
  519. const TensorLayout& p6, const TensorLayout& p7,
  520. size_t workspace_limit_in_bytes =
  521. std::numeric_limits<size_t>::max(),
  522. const AlgoAttribute& positive_attr = AlgoAttribute::DEFAULT,
  523. const AlgoAttribute& negative_attr = AlgoAttribute::DEFAULT) = 0;
  524. };
  525. } // namespace detail
  526. using Algorithm = detail::Algorithm;
  527. using AlgoAttribute = Algorithm::Attribute;
  528. using ExecutionPolicy = detail::ExecutionPolicy;
  529. } // namespace megdnn
  530. #include "megdnn/internal/visibility_epilogue.h"
  531. // vim: syntax=cpp.doxygen

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