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.6 kB

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

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