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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # -*- coding: utf-8 -*-
  2. # This file is part of MegEngine, a deep learning framework developed by
  3. # Megvii.
  4. #
  5. # Copyright (c) Copyright (c) 2020-2021 Megvii Inc. All rights reserved.
  6. import os
  7. import re
  8. import pathlib
  9. import platform
  10. from distutils.file_util import copy_file
  11. from setuptools import setup, find_packages, Extension
  12. from setuptools.command.build_ext import build_ext as _build_ext
  13. class PrecompiledExtesion(Extension):
  14. def __init__(self, name):
  15. super().__init__(name, sources=[])
  16. class build_ext(_build_ext):
  17. def build_extension(self, ext):
  18. if not isinstance(ext, PrecompiledExtesion):
  19. return super().build_extension(ext)
  20. if not self.inplace:
  21. fullpath = self.get_ext_fullpath(ext.name)
  22. extdir = pathlib.Path(fullpath)
  23. extdir.parent.mkdir(parents=True, exist_ok=True)
  24. modpath = self.get_ext_fullname(ext.name).split('.')
  25. if platform.system() == 'Windows':
  26. modpath[-1] += '.dll'
  27. elif platform.system() == 'Darwin':
  28. modpath[-1] += '.dylib'
  29. else:
  30. modpath[-1] += '.so'
  31. modpath = str(pathlib.Path(*modpath).resolve())
  32. copy_file(modpath, fullpath, verbose=self.verbose, dry_run=self.dry_run)
  33. v = {}
  34. with open("megenginelite/version.py") as fp:
  35. exec(fp.read(), v)
  36. __version__ = v['__version__']
  37. email = 'megengine@megvii.com'
  38. # https://www.python.org/dev/peps/pep-0440
  39. # Public version identifiers: [N!]N(.N)*[{a|b|rc}N][.postN][.devN]
  40. # Local version identifiers: <public version identifier>[+<local version label>]
  41. # PUBLIC_VERSION_POSTFIX use to handle rc or dev info
  42. public_version_postfix = os.environ.get('PUBLIC_VERSION_POSTFIX')
  43. if public_version_postfix:
  44. __version__ = '{}{}'.format(__version__, public_version_postfix)
  45. local_version = []
  46. strip_sdk_info = os.environ.get('STRIP_SDK_INFO', 'False').lower()
  47. sdk_name = os.environ.get('SDK_NAME', 'cpu')
  48. if 'true' == strip_sdk_info:
  49. print('wheel version strip sdk info')
  50. else:
  51. local_version.append(sdk_name)
  52. local_postfix = os.environ.get('LOCAL_VERSION')
  53. if local_postfix:
  54. local_version.append(local_postfix)
  55. if len(local_version):
  56. __version__ = '{}+{}'.format(__version__, '.'.join(local_version))
  57. packages = find_packages()
  58. megenginelite_data = [
  59. str(f.relative_to('megenginelite'))
  60. for f in pathlib.Path('megenginelite').glob('**/*')
  61. ]
  62. if platform.system() == 'Windows':
  63. megenginelite_data.remove('libs\\liblite_shared.dll')
  64. elif platform.system() == 'Darwin':
  65. megenginelite_data.remove('libs/liblite_shared.dylib')
  66. else:
  67. megenginelite_data.remove('libs/liblite_shared.so')
  68. with open('requires.txt') as f:
  69. requires = f.read().splitlines()
  70. prebuild_modules=[PrecompiledExtesion('megenginelite.libs.liblite_shared')]
  71. setup_kwargs = dict(
  72. name=package_name,
  73. version=__version__,
  74. description='Inference Framework for MegEngine',
  75. author='Megvii Engine Team',
  76. author_email=email,
  77. packages=packages,
  78. package_data={
  79. 'megenginelite': megenginelite_data,
  80. },
  81. ext_modules=prebuild_modules,
  82. install_requires=requires,
  83. cmdclass={'build_ext': build_ext},
  84. )
  85. setup_kwargs.update(dict(
  86. classifiers=[
  87. 'Development Status :: 3 - Alpha',
  88. 'Intended Audience :: Developers',
  89. 'Intended Audience :: Education',
  90. 'Intended Audience :: Science/Research',
  91. 'License :: OSI Approved :: Apache Software License',
  92. 'Programming Language :: C++',
  93. 'Programming Language :: Python :: 3',
  94. 'Programming Language :: Python :: 3.5',
  95. 'Programming Language :: Python :: 3.6',
  96. 'Programming Language :: Python :: 3.7',
  97. 'Programming Language :: Python :: 3.8',
  98. 'Topic :: Scientific/Engineering',
  99. 'Topic :: Scientific/Engineering :: Mathematics',
  100. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  101. 'Topic :: Software Development',
  102. 'Topic :: Software Development :: Libraries',
  103. 'Topic :: Software Development :: Libraries :: Python Modules',
  104. ],
  105. license='Apache 2.0',
  106. keywords='megengine deep learning',
  107. data_files = [("megengine", [
  108. "../LICENSE",
  109. "../ACKNOWLEDGMENTS",
  110. ])]
  111. ))
  112. setup(**setup_kwargs)

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