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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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] += '.dll'
  30. elif platform.system() == 'Darwin':
  31. modpath[-1] += '.dylib'
  32. else:
  33. modpath[-1] += '.so'
  34. modpath = str(pathlib.Path(*modpath).resolve())
  35. copy_file(modpath, fullpath, verbose=self.verbose, dry_run=self.dry_run)
  36. v = {}
  37. with open("megenginelite/version.py") as fp:
  38. exec(fp.read(), v)
  39. __version__ = v['__version__']
  40. email = 'megengine@megvii.com'
  41. # https://www.python.org/dev/peps/pep-0440
  42. # Public version identifiers: [N!]N(.N)*[{a|b|rc}N][.postN][.devN]
  43. # Local version identifiers: <public version identifier>[+<local version label>]
  44. # PUBLIC_VERSION_POSTFIX use to handle rc or dev info
  45. public_version_postfix = os.environ.get('PUBLIC_VERSION_POSTFIX')
  46. if public_version_postfix:
  47. __version__ = '{}{}'.format(__version__, public_version_postfix)
  48. local_version = []
  49. strip_sdk_info = os.environ.get('STRIP_SDK_INFO', 'False').lower()
  50. sdk_name = os.environ.get('SDK_NAME', 'cpu')
  51. if 'true' == strip_sdk_info:
  52. print('wheel version strip sdk info')
  53. else:
  54. local_version.append(sdk_name)
  55. local_postfix = os.environ.get('LOCAL_VERSION')
  56. if local_postfix:
  57. local_version.append(local_postfix)
  58. if len(local_version):
  59. __version__ = '{}+{}'.format(__version__, '.'.join(local_version))
  60. packages = find_packages()
  61. megenginelite_data = [
  62. str(f.relative_to('megenginelite'))
  63. for f in pathlib.Path('megenginelite').glob('**/*')
  64. ]
  65. if platform.system() == 'Windows':
  66. megenginelite_data.remove('libs\\liblite_shared.dll')
  67. elif platform.system() == 'Darwin':
  68. megenginelite_data.remove('libs/liblite_shared.dylib')
  69. else:
  70. megenginelite_data.remove('libs/liblite_shared.so')
  71. with open('requires.txt') as f:
  72. requires = f.read().splitlines()
  73. prebuild_modules=[PrecompiledExtesion('megenginelite.libs.liblite_shared')]
  74. setup_kwargs = dict(
  75. name=package_name,
  76. version=__version__,
  77. description='Inference Framework for MegEngine',
  78. author='Megvii Engine Team',
  79. author_email=email,
  80. packages=packages,
  81. package_data={
  82. 'megenginelite': megenginelite_data,
  83. },
  84. ext_modules=prebuild_modules,
  85. install_requires=requires,
  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 平台