-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsetup.py
More file actions
297 lines (251 loc) · 9.94 KB
/
Copy pathsetup.py
File metadata and controls
297 lines (251 loc) · 9.94 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
try:
from setuptools import setup, Extension, find_packages
from setuptools.command.build_ext import build_ext
except ImportError:
from distutils.core import setup, Extension, find_packages
from distutils.command.build_ext import build_ext
import numpy
import numpy.distutils.misc_util
import pkg_resources
import os
from os.path import join as pjoin
import platform
import sys
os.environ['CC'] = 'g++'
os.environ['CPP'] = 'g++'
os.environ['PTYCHOPY_BASE'] = os.getcwd()
# print("Setting env var PTYCHOPY_BASE to {:s}.".format(os.getcwd()))
# print(os.path.dirname(os.path.dirname(sys.executable)))
# virPythonPath = pjoin(os.path.dirname(os.path.dirname(sys.executable)), 'include')
virPythonPath = os.path.dirname(os.path.dirname(sys.executable))
def customize_compiler(self):
self.src_extensions.append('.cu')
try:
self.compiler_so.remove('-Wstrict-prototypes')
except ValueError:
pass
default_compiler_so = self.compiler_so
super = self._compile
def _compile(obj, src, ext, cc_args, extra_postargs, pp_opts):
if os.path.splitext(src)[1] == '.cu':
self.set_executable('compiler_so', CUDA['nvcc'])
try:
postargs = extra_postargs['nvcc']
except:
postargs = [os.path.abspath('.')]
elif os.path.splitext(src)[1] == '.c':
postargs = extra_postargs['g++']
elif os.path.splitext(src)[1] == '.cpp':
self.compiler_so = default_compiler_so
postargs = extra_postargs['g++']
else:
postargs = extra_postargs['g++']
# else:
# postargs = extra_postargs['gcc']
super(obj, src, ext, cc_args, postargs, pp_opts)
self.compiler_so = default_compiler_so
self._compile = _compile
class custom_build_ext(build_ext):
def build_extensions(self):
customize_compiler(self.compiler)
build_ext.build_extensions(self)
def locate_cuda():
"""
Locate where cuda is installed on the system.
Return a dict with values 'home', 'nvcc', 'sdk', 'include' and 'lib'
and values giving the absolute path to each directory.
Looks for the CUDAHOME environment variable. If not found, searches $PATH
for 'cuda' and 'nvcc'.
Adapted from:
http://stackoverflow.com/questions/10034325/can-python-distutils-compile-cuda-code
"""
home = None
if platform.architecture()[0]=='64bit':
arch = '64'
else:
arch = ''
if 'CUDAHOME' in os.environ:
home = os.environ['CUDAHOME']
nvcc = pjoin(home, 'bin', 'nvcc')
else:
# Otherwise search PATH for cuda and nvcc
for element in os.environ['PATH'].split(os.pathsep):
if element.find('cuda')>-1:
home = element.rstrip('/bin')
nvcc = pjoin(home, 'bin', 'nvcc')
elif element.find('nvcc')>-1:
nvcc = os.path.abspath(element)
home = os.path.dirname(os.path.dirname(element))
if not home:
raise EnvironmentError('The nvcc binary could not be located be '
'located in your $PATH. Either add it to your path, or set '
'the CUDAHOME environment variable.')
cudaconfig = {'home':home, 'nvcc':nvcc,
'sdk':pjoin(home, 'samples'),
'include':pjoin(home, 'include'),
'lib':pjoin(home, 'lib'+arch) }
for key, val in cudaconfig.items():
if not os.path.exists(val):
raise EnvironmentError('The CUDA path {:s} could not be located in {:s}'.format(key, val))
if 'CUDACOMPUTE' in os.environ:
cudaconfig['sm'] = '{:d}'.format(int(10*float(os.environ['CUDACOMPUTE'])))
cudaconfig['compute'] = '{:d}'.format(int(10*float(os.environ['CUDACOMPUTE'])))
else:
raise EnvironmentError("The 'CUDACOMPUTE' environment variable was "
"was not set.")
# print("-gencode=arch=compute_{:s},code=sm_{:s}".format(cudaconfig['compute'],cudaconfig['sm']))
return cudaconfig
def locate_hdf5():
"""
Locate where the HDF5 libraries are located on the system.
Returns a dict with keys 'home', 'lib' and 'include'
and values giving the absolute path to each directory.
Looks for the HDF5HOME environment variable.
"""
home = None
if platform.architecture()[0]=='64bit':
arch = '64'
else:
arch = ''
if 'HDF5_BASE' in os.environ:
home = os.environ['HDF5_BASE']
else:
raise EnvironmentError('Unable to locate the HDF libraries on '
'this system. Set the HDF5_BASE environment variable.')
hdfconfig = {'home':home,
'lib':pjoin(home, 'lib'),
'include':pjoin(home, 'include')}
for key, val in hdfconfig.items():
if not os.path.exists(val):
raise EnvironmentError('Could not locate {:s} in path {:s}'.format(key, val))
return hdfconfig
def locate_diy():
"""
Locate where the DIY libraries are located on the system.
Returns a dict with keys 'home', 'lib' and 'include'
and values giving the absolute path to each directory.
Looks for the DIYHOME environment variable.
"""
home = None
if platform.architecture()[0]=='64bit':
arch = '64'
else:
arch = ''
if 'DIY_BASE' in os.environ:
home = os.environ['DIY_BASE']
else:
raise EnvironmentError('Unable to locate the DIY libraries on '
'this system. Set the DIY_BASE environment variable.')
# diyconfig = {'home':home,
# 'lib':pjoin(home, 'lib'),
# 'include':pjoin(home, 'include')}
diyconfig = {'home':home,
'include':pjoin(home, 'include')}
for key, val in diyconfig.items():
if not os.path.exists(val):
raise EnvironmentError('Could not locate {:s} in path {:s}'.format(key, val))
return diyconfig
CUDA = locate_cuda()
HDF5 = locate_hdf5()
# DIY = locate_diy()
if platform.architecture()[0]=='32bit':
suffix = ''
else:
suffix = '64'
with open('./requirements.txt','r') as f_requirements:
requirements = f_requirements.readlines()
# Create ptychopy.so
extptychopy = Extension(name='ptychopy',
sources=[
'./src/ScanMeshKernels.cu',
'./src/SampleKernels.cu',
'./src/ProbeKernels.cu',
'./src/utilitiesKernels.cu',
'./src/DiffractionsKernels.cu',
'./src/CartesianScanMesh.cpp',
'./src/CudaSmartPtr.cpp',
'./src/Cuda2DArray.cpp',
# './src/GLResourceManager.cpp',
# './src/RenderServer.cpp',
'./src/IPtychoScanMesh.cpp',
'./src/DiffractionLoader.cpp',
'./src/ThreadPool.cpp',
'./src/ListScanMesh.cpp',
'./src/Sample.cpp',
'./src/Probe.cpp',
'./src/Diffractions.cpp',
'./src/CudaFFTPlan.cpp',
'./src/utilities.cpp',
'./src/IPhaser.cpp',
# './src/MPIPhaser.cpp',
'./src/ePIE.cpp',
'./src/MLS.cpp',
'./src/Parameters.cpp',
'./src/FileManager.cpp',
'./src/Timer.cpp',
'./src/SpiralScanMesh.cpp',
'./src/DM.cu',
# './src/WS/easywsclient.cpp',
'./src/ptychopy.c',
],
language='c++',
include_dirs=[
numpy.get_include(),
numpy.distutils.misc_util.get_numpy_include_dirs(),
CUDA['include'],
CUDA['sdk']+'/common/inc',
# '/local/kyue/program/anaconda/envs/py36/include',
virPythonPath + '/include',
'./src',
],
library_dirs=[
CUDA['lib'],
CUDA['sdk']+'/common/lib',
],
runtime_library_dirs=[CUDA['lib']],
extra_link_args = ['-lcudart', '-lcurand', '-lcufft', '-lcublas', '-lhdf5', '-lhdf5_cpp', '-lpthread'],
extra_compile_args={
'nvcc': ['-Xcompiler', '-fpic', '-O3', '-gencode=arch=compute_{:s},code=sm_{:s}'.format(CUDA['compute'],CUDA['sm'])],
'gcc': ['-DEPIE_HDF5', '-fpic', '-DHAVE_HDF5'],
'g++': ['-DEPIE_HDF5', '-fpic', '-DHAVE_HDF5']
})
# extra_link_args = ['-lcudart', '-lcurand', '-lcufft', '-lcublas', '-lSDL2', '-lGLEW', '-lGL', '-lhdf5', '-lhdf5_cpp', '-lz', '-lsz', '-lpthread'],
# extra_compile_args={
# 'nvcc': ['-Xcompiler', '-fpic', '-O3','-gencode=arch=compute_60,code=sm_60', '-gencode=arch=compute_{:s},code=sm_{:s}'.format(CUDA['compute'],CUDA['sm'])],
# 'gcc': ['-DEPIE_HDF5', '-DHAVE_DIY'],
# 'g++': ['-DEPIE_HDF5', '-DHAVE_DIY'],
# 'clang': ['-DEPIE_HDF5', '-DHAVE_DIY'],
# 'clang++': ['-DEPIE_HDF5', '-DHAVE_DIY'],
# }
config = {
'name': 'ptychopy',
'version': open('VERSION').read().strip(),
# 'packages': ['ptychopy'],
'include_package_data': True,
'description': 'Fast ptychography reconstruction library.',
'ext_modules': [extptychopy],
'cmdclass':{'build_ext':custom_build_ext},
'author': 'Ke Yue, Junjing Deng, David J. Vine',
'author_email': 'kyue@anl.gov, junjingdeng@anl.gov, djvine@gmail.com',
# 'url': 'http://aps.anl.gov/ptychopy',
'download_url': 'https://github.com/kyuepublic/ptychopy.git',
'install_requires': requirements,
'license': 'BSD',
'platforms': 'Any',
'classifiers': ['Development Status :: 1 - Pre-alpha',
'Licence :: OSI Approved :: BSD Licence',
'Intended Audience :: Science/Research',
'Intended Audience :: Education',
'Intended Audience :: Developers',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
# 'Programming Language :: Python 2.7',
'Programming Language :: Python 3.4',
'Programming Language :: C',
'Programming Language :: C++',
'Programming Language :: Cuda',
'Topic :: Scientific/Engineering :: Physics',
]
}
setup(**config)