-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile.gpu
343 lines (276 loc) · 10.4 KB
/
Dockerfile.gpu
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
FROM nvidia/cuda:9.0-cudnn7-devel-ubuntu16.04
ENV DEBIAN_FRONTEND=noninteractive
COPY requirements.txt requirements.txt
RUN APT_INSTALL="apt-get install -y --no-install-recommends" && \
PIP_INSTALL="python -m pip --no-cache-dir install --upgrade" && \
GIT_CLONE="git clone --depth 10" && \
rm -rf /var/lib/apt/lists/* \
/etc/apt/sources.list.d/cuda.list \
/etc/apt/sources.list.d/nvidia-ml.list && \
apt-get update && \
# ==================================================================
# tools
# ------------------------------------------------------------------
$APT_INSTALL \
build-essential \
ca-certificates \
cmake \
wget \
git \
vim \
&& \
# ==================================================================
# python
# ------------------------------------------------------------------
$APT_INSTALL \
software-properties-common \
&& \
add-apt-repository ppa:deadsnakes/ppa && \
apt-get update && \
$APT_INSTALL \
python3.6 \
python3.6-dev \
&& \
wget -O ~/get-pip.py \
https://bootstrap.pypa.io/get-pip.py && \
python3.6 ~/get-pip.py && \
ln -s /usr/bin/python3.6 /usr/local/bin/python3 && \
ln -s /usr/bin/python3.6 /usr/local/bin/python && \
$PIP_INSTALL \
setuptools \
&& \
# ==================================================================
# torch
# ------------------------------------------------------------------
export TORCH_NVCC_FLAGS="-D__CUDA_NO_HALF_OPERATORS__" && \
$GIT_CLONE https://github.com/torch/distro.git ~/torch --recursive && \
cd ~/torch/exe/luajit-rocks && \
mkdir build && cd build && \
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_LUAJIT21=ON \
.. && \
make -j"$(nproc)" install && \
$APT_INSTALL \
libjpeg-dev \
libpng-dev \
libreadline-dev \
&& \
$GIT_CLONE https://github.com/Yonaba/Moses ~/moses && \
cd ~/moses && \
luarocks install rockspec/moses-1.6.1-1.rockspec && \
cd ~/torch && \
sed -i 's/extra\/cudnn/extra\/cudnn \&\& git checkout R7/' install.sh && \
sed -i 's/$PREFIX\/bin\/luarocks/luarocks/' install.sh && \
sed -i '/qt/d' install.sh && \
sed -i '/Installing Lua/,/^cd \.\.$/d' install.sh && \
sed -i '/path_to_nvidiasmi/,/^fi$/d' install.sh && \
sed -i '/Restore anaconda/,/^Not updating$/d' install.sh && \
sed -i '/You might want to/,/^fi$/d' install.sh && \
yes no | ./install.sh && \
# ==================================================================
# boost
# ------------------------------------------------------------------
wget -O ~/boost.tar.gz https://dl.bintray.com/boostorg/release/1.65.1/source/boost_1_65_1.tar.gz && \
tar -zxf ~/boost.tar.gz -C ~ && \
cd ~/boost_* && \
./bootstrap.sh --with-python=python3.6 && \
./b2 install --prefix=/usr/local && \
# ==================================================================
# chainer
# ------------------------------------------------------------------
$PIP_INSTALL \
cupy \
chainer \
&& \
# ==================================================================
# cntk
# ------------------------------------------------------------------
$APT_INSTALL \
openmpi-bin \
libpng-dev \
libtiff-dev \
libjasper-dev \
&& \
$PIP_INSTALL \
cntk-gpu \
&& \
# ==================================================================
# jupyter
# ------------------------------------------------------------------
$PIP_INSTALL \
jupyter \
jupyterlab \
&& \
# ==================================================================
# xgboost
# ------------------------------------------------------------------
pip uninstall xgboost -y \
&& git clone --recursive https://github.com/dmlc/xgboost \
&& git submodule init \
&& git submodule update \
&& cd xgboost \
&& mkdir build \
&& cd build \
&& cmake .. -DUSE_CUDA=ON \
&& make -j4 \
&& \
# ==================================================================
# mxnet
# ------------------------------------------------------------------
$APT_INSTALL \
libatlas-base-dev \
graphviz \
&& \
$PIP_INSTALL \
mxnet-cu90 \
graphviz \
&& \
# ==================================================================
# pytorch
# ------------------------------------------------------------------
$PIP_INSTALL \
http://download.pytorch.org/whl/cu90/torch-0.4.0-cp36-cp36m-linux_x86_64.whl \
torchvision \
&& \
# ==================================================================
# tensorflow
# ------------------------------------------------------------------
$PIP_INSTALL \
tensorflow-gpu \
&& \
# ==================================================================
# theano
# ------------------------------------------------------------------
$APT_INSTALL \
libblas-dev \
&& \
wget -qO- https://github.com/Theano/Theano/archive/rel-1.0.1.tar.gz | tar xz -C ~ && \
cd ~/Theano* && \
$PIP_INSTALL \
. && \
$GIT_CLONE https://github.com/Theano/libgpuarray ~/gpuarray && \
mkdir -p ~/gpuarray/build && cd ~/gpuarray/build && \
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
.. && \
make -j"$(nproc)" install && \
cd ~/gpuarray && \
python setup.py build && \
python setup.py install && \
printf '[global]\nfloatX = float32\ndevice = cuda0\n\n[dnn]\ninclude_path = /usr/local/cuda/targets/x86_64-linux/include\n' > ~/.theanorc && \
# ==================================================================
# keras
# ------------------------------------------------------------------
$PIP_INSTALL \
h5py \
keras \
&& \
# ==================================================================
# lasagne
# ------------------------------------------------------------------
$GIT_CLONE https://github.com/Lasagne/Lasagne ~/lasagne && \
cd ~/lasagne && \
$PIP_INSTALL \
. && \
# ==================================================================
# opencv
# ------------------------------------------------------------------
$APT_INSTALL \
libatlas-base-dev \
libgflags-dev \
libgoogle-glog-dev \
libhdf5-serial-dev \
libleveldb-dev \
liblmdb-dev \
libprotobuf-dev \
libsnappy-dev \
protobuf-compiler \
&& \
$GIT_CLONE --branch 3.4.1 https://github.com/opencv/opencv ~/opencv && \
mkdir -p ~/opencv/build && cd ~/opencv/build && \
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_IPP=OFF \
-D WITH_CUDA=OFF \
-D WITH_OPENCL=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
.. && \
make -j"$(nproc)" install && \
# ==================================================================
# sonnet
# ------------------------------------------------------------------
$PIP_INSTALL \
dm-sonnet \
&& \
# ==================================================================
# caffe
# ------------------------------------------------------------------
$GIT_CLONE https://github.com/NVIDIA/nccl ~/nccl && \
cd ~/nccl && \
make -j"$(nproc)" install && \
$GIT_CLONE https://github.com/BVLC/caffe ~/caffe && \
cp ~/caffe/Makefile.config.example ~/caffe/Makefile.config && \
sed -i 's/# USE_CUDNN/USE_CUDNN/g' ~/caffe/Makefile.config && \
sed -i 's/# PYTHON_LIBRARIES/PYTHON_LIBRARIES/g' ~/caffe/Makefile.config && \
sed -i 's/# WITH_PYTHON_LAYER/WITH_PYTHON_LAYER/g' ~/caffe/Makefile.config && \
sed -i 's/# OPENCV_VERSION/OPENCV_VERSION/g' ~/caffe/Makefile.config && \
sed -i 's/# USE_NCCL/USE_NCCL/g' ~/caffe/Makefile.config && \
sed -i 's/-gencode arch=compute_20,code=sm_20//g' ~/caffe/Makefile.config && \
sed -i 's/-gencode arch=compute_20,code=sm_21//g' ~/caffe/Makefile.config && \
sed -i 's/2\.7/3\.6/g' ~/caffe/Makefile.config && \
sed -i 's/3\.5/3\.6/g' ~/caffe/Makefile.config && \
sed -i 's/\/usr\/lib\/python/\/usr\/local\/lib\/python/g' ~/caffe/Makefile.config && \
sed -i 's/\/usr\/local\/include/\/usr\/local\/include \/usr\/include\/hdf5\/serial/g' ~/caffe/Makefile.config && \
sed -i 's/hdf5/hdf5_serial/g' ~/caffe/Makefile && \
cd ~/caffe && \
make -j"$(nproc)" -Wno-deprecated-gpu-targets distribute && \
# fix ValueError caused by python-dateutil 1.x
sed -i 's/,<2//g' ~/caffe/python/requirements.txt && \
$PIP_INSTALL \
-r ~/caffe/python/requirements.txt && \
cd ~/caffe/distribute/bin && \
for file in *.bin; do mv "$file" "${file%%.bin}"; done && \
cd ~/caffe/distribute && \
cp -r bin include lib proto /usr/local/ && \
cp -r python/caffe /usr/local/lib/python3.6/dist-packages/ && \
# ==================================================================
# caffe2
# ------------------------------------------------------------------
$APT_INSTALL \
libprotobuf-dev \
protobuf-compiler \
&& \
$PIP_INSTALL \
future \
numpy \
protobuf \
&& \
$GIT_CLONE https://github.com/pytorch/pytorch.git \
~/caffe2 --recursive && \
git submodule update --init && \
cd ~/caffe2 && \
sed -i "s/prefix=''/prefix='', standard_lib=True) \
+ '\/dist-packages'/g" CMakeLists.txt && \
mkdir build && cd build && \
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D USE_CUDA=ON \
-D USE_MPI=OFF \
.. && \
make -j"$(nproc)" install && \
mv /usr/local/lib/python3/dist-packages/caffe2 \
/usr/local/lib/python3.6/dist-packages && \
# ==================================================================
# config & cleanup
# ------------------------------------------------------------------
ldconfig && \
apt-get clean && \
apt-get autoremove && \
rm -rf /var/lib/apt/lists/* /tmp/* ~/*
# ==================================================================
# Python requirements packages
# ------------------------------------------------------------------
RUN pip install --upgrade -r requirements.txt
EXPOSE 8888 6006