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.

symbol_var_array.i 1.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * $File: symbol_var_array.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. /*
  9. * In megbrain, SymbolVarArray is SmallVector<SymbolVar>.
  10. *
  11. * I do no want to convert between std::vector<> and mgb::SmallVector in the
  12. * C++ wrappers; neither do I want to write a SmallVector<> interface file as
  13. * good as swig's std::vector<> implementation.
  14. *
  15. * So the goal becomes making swig generate python wrapper for std::vector<>,
  16. * but call SymbolVarArray in the generated C++ file.
  17. *
  18. * A logical solution is to derive SymbolVarArray from std::vector<> only in
  19. * the .i file so swig can use the correct name; however the generated python
  20. * class becomes uniterable. So our hack here is to specialize std::vector to
  21. * use SymbolVarArray in the generated C++ file.
  22. *
  23. * This file must be included before instantiation of std::vector<SymbolVar>.
  24. */
  25. %{
  26. #include <vector>
  27. #include "megbrain/graph/symbol_var.h"
  28. using SymbolVar = mgb::cg::SymbolVar;
  29. using SymbolVarArray = mgb::cg::SymbolVarArray;
  30. namespace std {
  31. template<typename alloc>
  32. class vector<SymbolVar, alloc> : public SymbolVarArray {
  33. public:
  34. using SymbolVarArray::SymbolVarArray;
  35. using allocator_type = alloc;
  36. allocator_type get_allocator() const {
  37. mgb_throw(mgb::MegBrainError, "get_allocator() should not be called");
  38. return {};
  39. }
  40. };
  41. }
  42. %}
  43. // vim: ft=swig

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