-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
165 lines (153 loc) · 7.17 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
from distutils.core import setup
from distutils.extension import Extension
from distutils.sysconfig import get_config_vars
from distutils.command.build_clib import build_clib
from distutils.command.build_ext import build_ext
from distutils.command.install_headers import install_headers as install_headers_orig
import json
import pybind11
import pkgconfig
import os
import os.path
import sys
import tmci
class install_headers(install_headers_orig):
"""The install_headers command is redefined to
remove the "python3.Xm" in the installation path"""
def run(self):
a = self.install_dir.split('/')
if 'python' in a[-2]:
del a[-2]
# delete also the last "flamestore" subdir
del a[-1]
self.install_dir = '/'.join(a)
headers = self.distribution.headers or []
for header in headers:
self.mkpath(self.install_dir)
(out, _) = self.copy_file(header, self.install_dir)
if 'swift' in header:
new_out = out.replace('.h','.swift')
os.rename(out, new_out)
out = new_out
self.outfiles.append(out)
src_dir = os.path.dirname(os.path.abspath(__file__)) + '/flamestore/src'
tf_info = {
'libraries' : None,
'library_dirs' : None,
'include_dirs' : None,
'extra_cxxflags' : None
}
try:
with open('tensorflow.json') as f:
tf_info = json.loads(f.read())
except:
pass
if tf_info['libraries'] is None:
tf_info['libraries'] = [ ':libtensorflow_framework.so.2' ]
if tf_info['library_dirs'] is None:
import tensorflow as tf
path = os.path.dirname(tf.__file__)
tf_info['library_dirs'] = [ path + '/../tensorflow_core' ]
if tf_info['include_dirs'] is None:
import tensorflow as tf
path = os.path.dirname(tf.__file__)
tf_info['include_dirs'] = [ path + '/../tensorflow_core/include' ]
cxxflags = tf_info['extra_cxxflags']
def get_pybind11_include():
path = os.path.dirname(pybind11.__file__)
return '/'.join(path.split('/')[0:-4] + ['include'])
(opt,) = get_config_vars('OPT')
os.environ['OPT'] = " ".join(flag for flag in opt.split() if flag != '-Wstrict-prototypes')
thallium = pkgconfig.parse('thallium')
spdlog = pkgconfig.parse('spdlog')
bake_client = pkgconfig.parse('bake-client')
bake_server = pkgconfig.parse('bake-server')
sdskv_client = pkgconfig.parse('sdskv-client')
sdskv_server = pkgconfig.parse('sdskv-server')
jsoncpp = pkgconfig.parse('jsoncpp')
ssg = pkgconfig.parse('ssg')
flamestore_server_module_libraries = thallium['libraries'] \
+ bake_client['libraries'] \
+ bake_server['libraries'] \
+ sdskv_client['libraries'] \
+ ssg['libraries'] \
+ jsoncpp['libraries']
flamestore_server_module_library_dirs = thallium['library_dirs'] \
+ bake_client['library_dirs'] \
+ bake_server['library_dirs'] \
+ sdskv_client['library_dirs'] \
+ ssg['library_dirs'] \
+ jsoncpp['library_dirs']
flamestore_server_module_include_dirs = thallium['include_dirs'] \
+ bake_client['include_dirs'] \
+ bake_server['include_dirs'] \
+ sdskv_client['include_dirs'] \
+ jsoncpp['include_dirs'] \
+ ssg['include_dirs'] \
+ [ src_dir ]
flamestore_server_module = Extension('_flamestore_server',
['flamestore/src/server/backend.cpp',
'flamestore/src/server/memory_backend.cpp',
'flamestore/src/server/mochi_backend.cpp',
'flamestore/src/server/master_server.cpp',
'flamestore/src/server/storage_server.cpp',
# 'flamestore/src/server/mmapfs_backend.cpp',
# 'flamestore/src/server/provider.cpp',
'flamestore/src/server/server_module.cpp'
],
libraries=flamestore_server_module_libraries,
library_dirs=flamestore_server_module_library_dirs,
include_dirs=flamestore_server_module_include_dirs,
extra_compile_args=cxxflags,
depends=[])
flamestore_client_module_libraries = thallium['libraries'] \
+ tf_info['libraries'] \
+ [ ':'+tmci.get_library() ] \
+ jsoncpp['libraries']
flamestore_client_module_library_dirs = thallium['library_dirs'] \
+ tf_info['library_dirs'] \
+ [ tmci.get_library_dir() ] \
+ jsoncpp['library_dirs']
flamestore_client_module_include_dirs = thallium['include_dirs'] \
+ [ src_dir ] \
+ tf_info['include_dirs'] \
+ jsoncpp['include_dirs']
flamestore_client_module = Extension('_flamestore_client',
['flamestore/src/client/client.cpp',
'flamestore/src/client/client_module.cpp',
'flamestore/src/client/tmci_backend.cpp'],
libraries=flamestore_client_module_libraries,
library_dirs=flamestore_client_module_library_dirs,
runtime_library_dirs=flamestore_client_module_library_dirs,
include_dirs=flamestore_client_module_include_dirs,
extra_compile_args=cxxflags,
depends=[])
flamestore_admin_module_libraries = thallium['libraries'] \
+ jsoncpp['libraries']
flamestore_admin_module_library_dirs = thallium['library_dirs'] \
+ jsoncpp['library_dirs']
flamestore_admin_module_include_dirs = thallium['include_dirs'] \
+ [ src_dir ] \
+ jsoncpp['include_dirs']
flamestore_admin_module = Extension('_flamestore_admin',
['flamestore/src/admin/admin.cpp',
'flamestore/src/admin/admin_module.cpp'],
libraries=flamestore_admin_module_libraries,
library_dirs=flamestore_admin_module_library_dirs,
runtime_library_dirs=flamestore_admin_module_library_dirs,
include_dirs=flamestore_admin_module_include_dirs,
extra_compile_args=cxxflags,
depends=[])
setup(name='flamestore',
version='0.3',
author='Matthieu Dorier',
description='''Mochi service to store and load tensorflow models''',
ext_modules=[ flamestore_client_module,
flamestore_server_module,
flamestore_admin_module,
],
packages=['flamestore'],
scripts=['bin/flamestore'],
cmdclass={'install_headers': install_headers},
headers=['swift/flamestore.h'] # swift file considered a header
)