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 4.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # -*- coding: utf-8 -*-
  2. # MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  3. #
  4. # Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
  5. #
  6. # Unless required by applicable law or agreed to in writing,
  7. # software distributed under the License is distributed on an
  8. # "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. import os
  10. import re
  11. import pathlib
  12. import platform
  13. import subprocess
  14. from distutils.file_util import copy_file
  15. from setuptools import setup, find_packages, Extension
  16. from setuptools.command.build_ext import build_ext as _build_ext
  17. class PrecompiledExtesion(Extension):
  18. def __init__(self, name):
  19. super().__init__(name, sources=[])
  20. class build_ext(_build_ext):
  21. def build_extension(self, ext):
  22. if not isinstance(ext, PrecompiledExtesion):
  23. return super().build_extension(ext)
  24. if not self.inplace:
  25. fullpath = self.get_ext_fullpath(ext.name)
  26. extdir = pathlib.Path(fullpath)
  27. extdir.parent.mkdir(parents=True, exist_ok=True)
  28. modpath = self.get_ext_fullname(ext.name).split('.')
  29. if platform.system() == 'Windows':
  30. modpath[-1] += '.pyd'
  31. else:
  32. modpath[-1] += '.so'
  33. modpath = str(pathlib.Path(*modpath).resolve())
  34. copy_file(modpath, fullpath, verbose=self.verbose, dry_run=self.dry_run)
  35. package_name = 'MegEngine'
  36. v = {}
  37. with open("megengine/version.py") as fp:
  38. exec(fp.read(), v)
  39. __version__ = v['__version__']
  40. email = 'megengine@megvii.com'
  41. commit_id = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip().decode('ascii')
  42. __version__ = '{}+1.git.{}'.format(__version__, commit_id)
  43. local_version = os.environ.get('LOCAL_VERSION')
  44. if local_version:
  45. __version__ = '{}.{}'.format(__version__, local_version)
  46. packages = find_packages(exclude=['test'])
  47. megengine_data = [
  48. str(f.relative_to('megengine'))
  49. for f in pathlib.Path('megengine', 'core', 'include').glob('**/*')
  50. ]
  51. megengine_data += [
  52. str(f.relative_to('megengine'))
  53. for f in pathlib.Path('megengine', 'core', 'lib').glob('**/*')
  54. ]
  55. with open('requires.txt') as f:
  56. requires = f.read().splitlines()
  57. with open('requires-style.txt') as f:
  58. requires_style = f.read().splitlines()
  59. with open('requires-test.txt') as f:
  60. requires_test = f.read().splitlines()
  61. prebuild_modules=[PrecompiledExtesion('megengine.core._imperative_rt')]
  62. setup_kwargs = dict(
  63. name=package_name,
  64. version=__version__,
  65. description='Framework for numerical evaluation with '
  66. 'auto-differentiation',
  67. author='Megvii Engine Team',
  68. author_email=email,
  69. packages=packages,
  70. package_data={
  71. 'megengine': megengine_data,
  72. },
  73. ext_modules=prebuild_modules,
  74. install_requires=requires,
  75. extras_require={
  76. 'dev': requires_style + requires_test,
  77. 'ci': requires_test,
  78. },
  79. cmdclass={'build_ext': build_ext},
  80. )
  81. setup_kwargs.update(dict(
  82. classifiers=[
  83. 'Development Status :: 3 - Alpha',
  84. 'Intended Audience :: Developers',
  85. 'Intended Audience :: Education',
  86. 'Intended Audience :: Science/Research',
  87. 'License :: OSI Approved :: Apache Software License',
  88. 'Programming Language :: C++',
  89. 'Programming Language :: Python :: 3',
  90. 'Programming Language :: Python :: 3.5',
  91. 'Programming Language :: Python :: 3.6',
  92. 'Programming Language :: Python :: 3.7',
  93. 'Programming Language :: Python :: 3.8',
  94. 'Topic :: Scientific/Engineering',
  95. 'Topic :: Scientific/Engineering :: Mathematics',
  96. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  97. 'Topic :: Software Development',
  98. 'Topic :: Software Development :: Libraries',
  99. 'Topic :: Software Development :: Libraries :: Python Modules',
  100. ],
  101. license='Apache 2.0',
  102. keywords='megengine deep learning',
  103. data_files = [("megengine", [
  104. "../LICENSE",
  105. "../ACKNOWLEDGMENTS",
  106. ])]
  107. ))
  108. setup(**setup_kwargs)

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