forked from explosion/lightnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
142 lines (123 loc) · 4.65 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python
import shutil
import io
import os
import json
import distutils.command.build_ext
import subprocess
import sys
from setuptools import Extension, setup
import platform
import numpy
try:
import cython
use_cython = True
except ImportError:
use_cython = False
class ExtensionBuilder(distutils.command.build_ext.build_ext):
def build_extensions(self):
if use_cython:
subprocess.check_call([sys.executable, 'bin/cythonize.py'],
env=os.environ)
cuda_include_dir = '/usr/local/cuda/include/'
if 'CUDA_INCLUDE_DIR' in os.environ:
cuda_include_dir = os.environ['CUDA_INCLUDE_DIR']
cuda_library_dir = '/usr/local/cuda/lib64/'
if 'CUDA_LIBRARY_DIR' in os.environ:
cuda_library_dir = os.environ['CUDA_LIBRARY_DIR']
use_gpu = False
if 'GPU' in os.environ and os.environ['GPU'] == '1':
use_gpu = True
use_cudnn = False
if 'CUDNN' in os.environ and os.environ['CUDNN'] == '1':
use_gpu = True
use_cudnn = True
make_command = ['make']
if use_gpu:
make_command.append('GPU=1')
if use_cudnn:
make_command.append('CUDNN=1')
darknet_dir = os.path.join(PWD, 'lightnet', '_darknet')
subprocess.check_call(make_command, cwd=darknet_dir)
for e in self.extensions:
e.include_dirs.append(numpy.get_include())
e.undef_macros.append("FORTIFY_SOURCE")
e.extra_compile_args.append("-DCBLAS")
e.extra_compile_args.append('-g')
e.library_dirs.append(darknet_dir)
e.extra_link_args.append('-g')
e.extra_link_args.append('-ldarknet')
if use_gpu:
e.include_dirs.append(cuda_include_dir)
e.library_dirs.append(cuda_library_dir)
e.extra_link_args.append('-lcuda')
e.extra_link_args.append('-lcudart')
e.extra_link_args.append('-lcublas')
e.extra_link_args.append('-lcurand')
e.extra_link_args.append('-lstdc++')
if use_cudnn:
e.extra_link_args.append('-lcudnn')
if sys.platform == 'darwin':
e.extra_compile_args.append('-D__APPLE__')
e.extra_link_args.append('-lblas')
else:
e.extra_link_args.append('-lopenblas')
distutils.command.build_ext.build_ext.build_extensions(self)
def get_c_sources(start_dir):
c_sources = []
excludes = []
for path, subdirs, files in os.walk(start_dir):
for exc in excludes:
if exc in path:
break
else:
for name in files:
if name.endswith('.c'):
c_sources.append(os.path.join(path, name))
return c_sources
PWD = os.path.join(os.path.dirname(__file__))
INCLUDE = os.path.join(PWD, 'lightnet', '_darknet')
c_files = get_c_sources(os.path.join(PWD, 'lightnet', '_darknet'))
with io.open(os.path.join(PWD, 'lightnet', 'about.py'), encoding='utf8') as f:
about = {}
exec(f.read(), about)
with io.open(os.path.join(PWD, 'README.rst'), encoding='utf8') as f:
readme = f.read()
setup(
setup_requires=['numpy'],
install_requires=['numpy', 'plac', 'requests', 'pathlib', 'tqdm',
'msgpack-python'],
ext_modules=[
Extension('lightnet.lightnet', ['lightnet/lightnet.c']),
],
cmdclass={'build_ext': ExtensionBuilder},
package_data={'': ['*.json', '*.pyx', '*.pxd', '_darknet/*.h',
'data/*.cfg', 'data/*.template', 'data/*.names'] + c_files},
name=about['__title__'],
zip_safe=False,
packages=['lightnet'],
version=about['__version__'],
author=about['__author__'],
author_email=about['__email__'],
url=about['__uri__'],
license=about['__license__'],
description=about['__summary__'],
long_description=readme,
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'License :: OSI Approved :: MIT License',
'Operating System :: POSIX :: Linux',
'Operating System :: MacOS :: MacOS X',
'Programming Language :: Cython',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Scientific/Engineering'
],
)