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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. # -*- coding: utf-8 -*-
  2. # MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  3. #
  4. # Copyright (c) 2014-2021 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. # https://www.python.org/dev/peps/pep-0440
  41. # Public version identifiers: [N!]N(.N)*[{a|b|rc}N][.postN][.devN]
  42. # PUBLIC_VERSION_POSTFIX use to handle rc or dev info
  43. public_version_postfix = os.environ.get('PUBLIC_VERSION_POSTFIX')
  44. if public_version_postfix:
  45. __version__ = '{}{}'.format(__version__, public_version_postfix)
  46. sdk_name = os.environ.get('SDK_NAME', 'cpu')
  47. __version__ = '{}+{}'.format(__version__, sdk_name)
  48. # Local version identifiers: <public version identifier>[+<local version label>]
  49. # reserved for special whl package
  50. local_version = os.environ.get('LOCAL_VERSION')
  51. if local_version:
  52. __version__ = '{}.{}'.format(__version__, local_version)
  53. packages = find_packages(exclude=['test'])
  54. megengine_data = [
  55. str(f.relative_to('megengine'))
  56. for f in pathlib.Path('megengine', 'core', 'include').glob('**/*')
  57. ]
  58. megengine_data += [
  59. str(f.relative_to('megengine'))
  60. for f in pathlib.Path('megengine', 'core', 'lib').glob('**/*')
  61. ]
  62. with open('requires.txt') as f:
  63. requires = f.read().splitlines()
  64. with open('requires-style.txt') as f:
  65. requires_style = f.read().splitlines()
  66. with open('requires-test.txt') as f:
  67. requires_test = f.read().splitlines()
  68. prebuild_modules=[PrecompiledExtesion('megengine.core._imperative_rt')]
  69. setup_kwargs = dict(
  70. name=package_name,
  71. version=__version__,
  72. description='Framework for numerical evaluation with '
  73. 'auto-differentiation',
  74. author='Megvii Engine Team',
  75. author_email=email,
  76. packages=packages,
  77. package_data={
  78. 'megengine': megengine_data,
  79. },
  80. ext_modules=prebuild_modules,
  81. install_requires=requires,
  82. extras_require={
  83. 'dev': requires_style + requires_test,
  84. 'ci': requires_test,
  85. },
  86. cmdclass={'build_ext': build_ext},
  87. )
  88. setup_kwargs.update(dict(
  89. classifiers=[
  90. 'Development Status :: 3 - Alpha',
  91. 'Intended Audience :: Developers',
  92. 'Intended Audience :: Education',
  93. 'Intended Audience :: Science/Research',
  94. 'License :: OSI Approved :: Apache Software License',
  95. 'Programming Language :: C++',
  96. 'Programming Language :: Python :: 3',
  97. 'Programming Language :: Python :: 3.5',
  98. 'Programming Language :: Python :: 3.6',
  99. 'Programming Language :: Python :: 3.7',
  100. 'Programming Language :: Python :: 3.8',
  101. 'Topic :: Scientific/Engineering',
  102. 'Topic :: Scientific/Engineering :: Mathematics',
  103. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  104. 'Topic :: Software Development',
  105. 'Topic :: Software Development :: Libraries',
  106. 'Topic :: Software Development :: Libraries :: Python Modules',
  107. ],
  108. license='Apache 2.0',
  109. keywords='megengine deep learning',
  110. data_files = [("megengine", [
  111. "../LICENSE",
  112. "../ACKNOWLEDGMENTS",
  113. ])]
  114. ))
  115. setup(**setup_kwargs)

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