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.

setup.py 3.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # -*- coding: utf-8 -*-
  2. # This file is part of MegBrain.
  3. # Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
  4. import os
  5. import re
  6. import pathlib
  7. from distutils.file_util import copy_file
  8. from setuptools import setup, find_packages, Extension
  9. from setuptools.command.build_ext import build_ext as _build_ext
  10. class PrecompiledExtesion(Extension):
  11. def __init__(self, name):
  12. super().__init__(name, sources=[])
  13. class build_ext(_build_ext):
  14. def build_extension(self, ext):
  15. if not isinstance(ext, PrecompiledExtesion):
  16. return super().build_extension(ext)
  17. if not self.inplace:
  18. fullpath = self.get_ext_fullpath(ext.name)
  19. extdir = pathlib.Path(fullpath)
  20. extdir.parent.mkdir(parents=True, exist_ok=True)
  21. modpath = self.get_ext_fullname(ext.name).split('.')
  22. modpath[-1] += '.so'
  23. modpath = str(pathlib.Path(*modpath).resolve())
  24. copy_file(modpath, fullpath, verbose=self.verbose, dry_run=self.dry_run)
  25. package_name = 'MegEngine'
  26. v = {}
  27. with open("megengine/version.py") as fp:
  28. exec(fp.read(), v)
  29. __version__ = v['__version__']
  30. email = 'megengine@megvii.com'
  31. local_version = os.environ.get('LOCAL_VERSION')
  32. if local_version:
  33. __version__ = '{}+{}'.format(__version__, local_version)
  34. packages = find_packages(exclude=['test'])
  35. package_data = [
  36. str(f.relative_to('megengine'))
  37. for f in pathlib.Path('megengine', '_internal', 'include').glob('**/*')
  38. ]
  39. package_data += [
  40. str(f.relative_to('megengine'))
  41. for f in pathlib.Path('megengine', '_internal', 'lib').glob('**/*')
  42. ]
  43. package_data += [
  44. os.path.join('module', 'pytorch', 'torch_mem_fwd.cpp')
  45. ]
  46. with open('requires.txt') as f:
  47. requires = f.read().splitlines()
  48. with open('requires-style.txt') as f:
  49. requires_style = f.read().splitlines()
  50. with open('requires-test.txt') as f:
  51. requires_test = f.read().splitlines()
  52. setup_kwargs = dict(
  53. name=package_name,
  54. version=__version__,
  55. description='Framework for numerical evaluation with '
  56. 'auto-differentiation',
  57. author='Megvii Engine Team',
  58. author_email=email,
  59. packages=packages,
  60. package_data={
  61. 'megengine': package_data,
  62. },
  63. ext_modules=[PrecompiledExtesion('megengine._internal._mgb')],
  64. install_requires=requires,
  65. extras_require={
  66. 'dev': requires_style + requires_test,
  67. 'ci': requires_test,
  68. },
  69. cmdclass={'build_ext': build_ext},
  70. )
  71. setup_kwargs.update(dict(
  72. classifiers=[
  73. 'Development Status :: 3 - Alpha',
  74. 'Intended Audience :: Developers',
  75. 'Intended Audience :: Education',
  76. 'Intended Audience :: Science/Research',
  77. 'License :: OSI Approved :: Apache Software License',
  78. 'Programming Language :: C++',
  79. 'Programming Language :: Python :: 3',
  80. 'Programming Language :: Python :: 3.5',
  81. 'Programming Language :: Python :: 3.6',
  82. 'Programming Language :: Python :: 3.7',
  83. 'Programming Language :: Python :: 3.8',
  84. 'Topic :: Scientific/Engineering',
  85. 'Topic :: Scientific/Engineering :: Mathematics',
  86. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  87. 'Topic :: Software Development',
  88. 'Topic :: Software Development :: Libraries',
  89. 'Topic :: Software Development :: Libraries :: Python Modules',
  90. ],
  91. license='Apache 2.0',
  92. keywords='megengine deep learning',
  93. data_files = [("megengine", [
  94. "../LICENSE",
  95. "../ACKNOWLEDGMENTS",
  96. ])]
  97. ))
  98. setup(**setup_kwargs)

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