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

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

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