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.

comp_graph.i 2.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * $File: comp_graph.i
  3. *
  4. * This file is part of MegBrain, a deep learning framework developed by Megvii.
  5. *
  6. * $Copyright: Copyright (c) 2014-2017 Megvii Inc. All rights reserved.
  7. */
  8. %pythoncode{
  9. from .mgb_helper import copy_output, FuncOutputSaver
  10. import json
  11. } // pythoncode
  12. %feature("autodoc", """a callable object compiled from :class:`CompGraph`.
  13. .. note::
  14. Only the most recently compiled AsyncExec object can be used.
  15. """) AsyncExec;
  16. %feature("autodoc", """explicitly release the underlying staticially allocated
  17. device memory""") AsyncExec::clear_device_memory;
  18. class AsyncExec {
  19. public:
  20. AsyncExec() = delete;
  21. void _execute();
  22. void _wait();
  23. double _get_prev_exec_time();
  24. std::string _to_json_str();
  25. SymbolVarArray _find_mutable_input();
  26. std::vector<std::pair<CompNode, size_t>>
  27. _update_static_alloc_plan_and_get_size();
  28. void clear_device_memory();
  29. %include "comp_graph_impl_AsyncExec.py"
  30. };
  31. %template(_VectorAsyncExec) std::vector<AsyncExec>;
  32. %feature("autodoc", """use device memory manager in another computing graph to
  33. manage memory of this graph, so their memories can be shared. This is safe only
  34. when :class:`AsyncExec` compiled from these graphs do not run concurrently.""")
  35. CompGraph::share_device_memory_with;
  36. %feature("valuewrapper") CompGraph;
  37. class CompGraph {
  38. public:
  39. CompGraph();
  40. AsyncExec _do_compile(bool copy, bool optimize_for_inference);
  41. std::vector<AsyncExec> _do_compile_multi_part();
  42. void _add_output_spec(SymbolVar &var, _CompGraphCallback *callback);
  43. void _add_multi_part_endpoint();
  44. void _clear_output_spec();
  45. size_t _release();
  46. CompGraph& share_device_memory_with(CompGraph &other);
  47. PyObject* _user_data();
  48. void clear_device_memory();
  49. %extend {
  50. size_t _id() const {
  51. return $self->get().id();
  52. }
  53. size_t _get_ptr_addr() const {
  54. return reinterpret_cast<size_t>(&$self->get());
  55. }
  56. std::string get_mem_allocation_info() const {
  57. return self->get().get_mem_allocation_info();
  58. }
  59. std::string __repr__() const {
  60. auto &&graph = $self->get();
  61. return mgb::ssprintf("<CompGraph #%zu at %p>", graph.id(), &graph);
  62. }
  63. }
  64. %include "comp_graph_impl_CompGraph.py"
  65. };
  66. %include "comp_graph_tools.i"
  67. // vim: ft=swig

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