forked from hughperkins/DeepCL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
229 lines (206 loc) · 8.41 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
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
# Copyright Hugh Perkins 2015 hughperkins at gmail
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at http://mozilla.org/MPL/2.0/.
#from distutils.core import setup
import os
import os.path
import sysconfig
import sys
import glob
import platform
from setuptools import setup
#from distutils.extension import Extension
from setuptools import Extension
cython_present = False
try:
from Cython.Build import cythonize
cython_present = True
except ImportError:
pass
pypandoc_present = False
try:
import pypandoc
pypandoc_present = True
except ImportError:
pass
print ( sys.argv )
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
def get_so_suffix():
if sysconfig.get_config_var('SOABI') != None:
return "." + sysconfig.get_config_var('SOABI')
return ""
#def read_md( mdname ):
# if pypandoc_present:
# return pypandoc.convert(mdname, 'rst')
# else:
# print("warning: pypandoc module not found, could not convert Markdown to RST")
# return open(mdname, 'r').read()
if pypandoc_present:
pypandoc.convert('README.md', 'rst', outputfile = 'README.rst' )
def my_cythonize(extensions, **_ignore):
#newextensions = []
for extension in extensions:
print(extension.sources)
should_cythonize = False
sources = []
for sfile in extension.sources:
path, ext = os.path.splitext(sfile)
if ext in ('.pyx', '.py'):
should_cythonize = True
if not cython_present:
if extension.language == 'c++':
ext = '.cpp'
else:
ext = '.c'
sfile = path + ext
sources.append(sfile)
print(should_cythonize)
if should_cythonize and cython_present:
print('cythonizing...')
cythonize(extension)
extension.sources[:] = sources
#newextensions.append( extension )
return extensions
def no_cythonize(extensions, **_ignore):
for extension in extensions:
sources = []
for sfile in extension.sources:
path, ext = os.path.splitext(sfile)
if ext in ('.pyx', '.py'):
if extension.language == 'c++':
ext = '.cpp'
else:
ext = '.c'
sfile = path + ext
sources.append(sfile)
extension.sources[:] = sources
return extensions
# from http://stackoverflow.com/questions/14320220/testing-python-c-libraries-get-build-path
def distutils_dir_name(dname):
"""Returns the name of a distutils build directory"""
f = "{dirname}.{platform}-{version[0]}.{version[1]}"
return f.format(dirname=dname,
platform=sysconfig.get_platform(),
version=sys.version_info)
def lib_build_dir():
return os.path.join('build', distutils_dir_name('lib'))
deepcl_sourcestring = """LayerMaker.cpp NeuralNetMould.cpp
ConvolutionalLayer.cpp NeuralNet.cpp Layer.cpp InputLayer.cpp
Propagate1.cpp Propagate.cpp Propagate2.cpp Propagate3.cpp LayerDimensions.cpp
Propagate4.cpp ActivationFunction.cpp SquareLossLayer.cpp LossLayer.cpp BackpropWeights2.cpp
BackpropWeights2Cpu.cpp BackpropErrorsv2.cpp BackpropErrorsv2Cpu.cpp
BackpropWeights2Naive.cpp BackpropErrorsv2Naive.cpp BackpropWeights2Scratch.cpp
CrossEntropyLoss.cpp SoftMaxLayer.cpp FullyConnectedLayer.cpp EpochMaker.cpp
PoolingPropagate.cpp PoolingPropagateCpu.cpp PoolingLayer.cpp PoolingBackprop.cpp
PoolingBackpropCpu.cpp PoolingPropagateGpuNaive.cpp BackpropWeights2ScratchLarge.cpp
BatchLearner.cpp NetdefToNet.cpp NetLearner.cpp stringhelper.cpp NormalizationLayer.cpp
RandomPatches.cpp RandomTranslations.cpp NorbLoader.cpp MultiNet.cpp
Trainable.cpp InputLayerMaker.cpp ConvolutionalMaker.cpp RandomTranslationsMaker.cpp
RandomPatchesMaker.cpp NormalizationLayerMaker.cpp FullyConnectedMaker.cpp
PoolingMaker.cpp PatchExtractor.cpp Translator.cpp GenericLoader.cpp Kgsv2Loader.cpp
BatchLearnerOnDemand.cpp NetLearnerOnDemand.cpp BatchProcess.cpp WeightsPersister.cpp
PropagateFc.cpp BackpropErrorsv2Cached.cpp PropagateByInputPlane.cpp
PropagateExperimental.cpp PropagateAuto.cpp PropagateCpu.cpp Propagate3_unfactorized.cpp
PoolingBackpropGpuNaive.cpp"""
deepcl_sources_all = deepcl_sourcestring.split()
deepcl_sources = []
for source in deepcl_sources_all:
deepcl_sources.append(source)
openclhelpersources = list(map( lambda name : '../' + name, [ 'OpenCLHelper/OpenCLHelper.cpp',
'OpenCLHelper/deviceinfo_helper.cpp', 'OpenCLHelper/platforminfo_helper.cpp',
'OpenCLHelper/CLKernel.cpp', 'OpenCLHelper/thirdparty/clew/src/clew.c' ] ))
print(openclhelpersources)
print(isinstance( openclhelpersources, list) )
compile_options = []
osfamily = platform.uname()[0]
if osfamily == 'Windows':
compile_options.append('/EHsc')
elif osfamily == 'Linux':
compile_options.append('-std=c++11')
else:
pass
# put other options etc here if necessary
#if osfamily == 'Windows' and sys.version_info[0] == 2:
# print('WARNING: python 2.x not really supported, since it needs visual studio 9; and visual studio 2009 doesnt support any c++11 features, which we would ideally prefer to be able to use')
# print('Probably possible to coerce DeepCL to work with visual studio 9, and by extension with python 2.x, but maybe easier to just use python 3.x instead?')
runtime_library_dirs = []
libraries = []
if osfamily == 'Linux':
runtime_library_dirs= ['.']
if osfamily == 'Windows':
libraries = ['winmm']
if cython_present:
my_cythonize = cythonize
else:
my_cythonize = no_cythonize
#libraries = [
# ("OpenCLHelper", {
# 'sources': openclhelpersources + ['dummy_openclhelper.cpp'],
# 'include_dirs': ['DeepCL/OpenCLHelper'],
# 'extra_compile_args': compile_options,
## define_macros = [('OpenCLHelper_EXPORTS',1)],
## libraries = []
## language='c++'
# }
# )
#]
ext_modules = [
# Extension("_OpenCLHelper",
# sources = openclhelpersources + ['dummy_openclhelper.cpp'],
# include_dirs = ['DeepCL/OpenCLHelper'],
# extra_compile_args=compile_options,
# define_macros = [('OpenCLHelper_EXPORTS',1),('MS_WIN32',1)],
## libraries = []
## language='c++'
# )
# Extension("libDeepCL",
# list(map( lambda name : 'DeepCL/src/' + name, deepcl_sources)), # +
## glob.glob('DeepCL/src/*.h'),
# include_dirs = ['DeepCL/src','DeepCL/OpenCLHelper'],
# extra_compile_args = compile_options,
# library_dirs = [ lib_build_dir() ],
# libraries = [ "OpenCLHelper" + get_so_suffix() ],
# define_macros = [('DeepCL_EXPORTS',1)],
# runtime_library_dirs=runtime_library_dirs
## language='c++'
# ),
Extension("PyDeepCL",
sources=["PyDeepCL.pyx", 'CyWrappers.cpp']
+ openclhelpersources
+ list(map( lambda name : '../src/' + name, deepcl_sources))
+ ['../qlearning/QLearner.cpp','../qlearning/array_helper.cpp'],
# glob.glob('DeepCL/OpenCLHelper/*.h'),
include_dirs = ['../src','../OpenCLHelper','../qlearning'],
libraries= libraries,
extra_compile_args=compile_options,
define_macros = [('DeepCL_EXPORTS',1),('OpenCLHelper_EXPORTS',1)],
# extra_objects=['cDeepCL.pxd'],
# library_dirs = [lib_build_dir()],
runtime_library_dirs=runtime_library_dirs,
language="c++"
)
]
setup(
name = 'DeepCL',
version = "1.0.2",
author = "Hugh Perkins",
author_email = "hughperkins@gmail.com",
description = 'python wrapper for DeepCL deep convolutional neural network library for OpenCL',
license = 'MPL',
url = 'https://github.com/hughperkins/DeepCL',
long_description = read('README.rst'),
classifiers = [
'Development Status :: 4 - Beta',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
],
install_requires = ['Cython>=0.22','cogapp>=2.4','future>=0.14.3'],
tests_require = ['nose>=1.3.4'],
scripts = ['test_deepcl.py','test_lowlevel.py'],
# modules = libraries,
# libraries = libraries,
ext_modules = my_cythonize( ext_modules),
)