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.

module.cpp 1.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <pybind11/eval.h>
  2. #define DO_IMPORT_ARRAY
  3. #include "./numpy_dtypes.h"
  4. #include "./helper.h"
  5. #include "./common.h"
  6. #include "./utils.h"
  7. #include "./imperative_rt.h"
  8. #include "./graph_rt.h"
  9. #include "./ops.h"
  10. namespace py = pybind11;
  11. #ifndef MODULE_NAME
  12. #define MODULE_NAME imperative_rt
  13. #endif
  14. PYBIND11_MODULE(MODULE_NAME, m) {
  15. // initialize numpy
  16. if ([]() {import_array1(1); return 0;}()) {
  17. throw py::error_already_set();
  18. }
  19. py::module::import("sys").attr("modules")[m.attr("__name__")] = m;
  20. m.attr("__package__") = m.attr("__name__");
  21. m.attr("__builtins__") = py::module::import("builtins");
  22. auto atexit = py::module::import("atexit");
  23. atexit.attr("register")(py::cpp_function([]() {
  24. py::gil_scoped_release _;
  25. py_task_q.wait_all_task_finish();
  26. }));
  27. auto common = submodule(m, "common");
  28. auto utils = submodule(m, "utils");
  29. auto imperative = submodule(m, "imperative");
  30. auto graph = submodule(m, "graph");
  31. auto ops = submodule(m, "ops");
  32. init_common(common);
  33. init_utils(utils);
  34. init_imperative_rt(imperative);
  35. init_graph_rt(graph);
  36. init_ops(ops);
  37. py::exec(R"(
  38. from .common import *
  39. from .utils import *
  40. from .imperative import *
  41. from .graph import *
  42. )",
  43. py::getattr(m, "__dict__"));
  44. }

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