Skip to content

Commit cccb3fc

Browse files
committedJul 11, 2020
Docker builds for CPU and CUDA
This adds docker support for the project. Docker builds include CPU-only version, as well as different tags for some NVIDIA compute capability versions. Deploy scripts are provided, image name and used versions of both CUDA SDK and CCAP are customizable via env. Added make argument: upper-cased `CAPP` which accepts version in dotted notation (e.g. "5.2"); lower-cased `capp` is derived from it, but should still be directly overridable as any other make's variable. Instructions in README are updated accordingly. Linux section got reformatted and reworked and overall became more comprehensible (IMHO). Adding CI and automatic builds are left as an exercise for curious readers.
1 parent 6fa4ce9 commit cccb3fc

9 files changed

+262
-30
lines changed
 

‎Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ CXX = g++
3434
CUDA = /usr/local/cuda-8.0
3535
CXXCUDA = /usr/bin/g++-4.8
3636
NVCC = $(CUDA)/bin/nvcc
37+
# nvcc requires joint notation w/o dot, i.e. "5.2" -> "52"
38+
ccap = $(shell echo $(CCAP) | tr -d '.')
3739

3840
ifdef gpu
3941
ifdef debug

‎README.md

+94-30
Original file line numberDiff line numberDiff line change
@@ -189,45 +189,109 @@ Note: The current relase has been compiled with CUDA SDK 10.0, if you have a dif
189189

190190
## Linux
191191

192-
Intall CUDA SDK.\
193-
Depenging on the CUDA SDK version and on your Linux distribution you may need to install an older g++ (just for the CUDA SDK).\
194-
Edit the makefile and set up the good CUDA SDK path and appropriate compiler for nvcc.
192+
- Intall CUDA SDK.
193+
- Install older g++ (just for the CUDA SDK). Depenging on the CUDA SDK version and on your Linux distribution you may need to install an older g++.
194+
- Install recent gcc. VanitySearch needs to be compiled and linked with a recent gcc (>=7). The current release has been compiled with gcc 7.3.0.
195+
- Edit the makefile and set up the appropriate CUDA SDK and compiler paths for nvcc. Or pass them as variables to `make` invocation.
196+
197+
```make
198+
CUDA = /usr/local/cuda-8.0
199+
CXXCUDA = /usr/bin/g++-4.8
200+
```
201+
202+
- You can enter a list of architectrures (refer to nvcc documentation) if you have several GPU with different architecture.
203+
204+
- Set CCAP to the desired compute capability according to your hardware. See docker section for more. Compute capability 2.0 (Fermi) is deprecated for recent CUDA SDK.
205+
206+
- Go to the VanitySearch directory.
207+
- To build CPU-only version (without CUDA support):
208+
```sh
209+
$ make all
210+
```
211+
- To build with CUDA:
212+
```sh
213+
$ make gpu=1 CCAP=2.0 all
214+
```
195215

216+
Runnig VanitySearch (Intel(R) Xeon(R) CPU, 8 cores, @ 2.93GHz, Quadro 600 (x2))
217+
```sh
218+
$ export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64
219+
$ ./VanitySearch -t 7 -gpu -gpuId 0,1 1TryMe
220+
# VanitySearch v1.10
221+
# Difficulty: 15318045009
222+
# Search: 1TryMe [Compressed]
223+
# Start Wed Mar 27 10:26:43 2019
224+
# Base Key:C6718D8E50C1A5877DE3E52021C116F7598826873C61496BDB7CAD668CE3DCE5
225+
# Number of CPU thread: 7
226+
# GPU: GPU #1 Quadro 600 (2x48 cores) Grid(16x128)
227+
# GPU: GPU #0 Quadro 600 (2x48 cores) Grid(16x128)
228+
# 40.284 MK/s (GPU 27.520 MK/s) (2^31.84) [P 22.24%][50.00% in 00:02:47][0]
229+
#
230+
# Pub Addr: 1TryMeERTZK7RCTemSJB5SNb2WcKSx45p
231+
# Priv (WIF): Ky9bMLDpb9o5rBwHtLaidREyA6NzLFkWJ19QjPDe2XDYJdmdUsRk
232+
# Priv (HEX): 0x398E7271AF3E5A78821C1ADFDE3EE90760A6B65F72D856CFE455B1264350BCE8
196233
```
197-
CUDA = /usr/local/cuda-8.0
198-
CXXCUDA = /usr/bin/g++-4.8
199-
```
200234

201-
You can enter a list of architectrure (refer to nvcc documentation) if you have several GPU with different architecture. Compute capability 2.0 (Fermi) is deprecated for recent CUDA SDK.
202-
VanitySearch need to be compiled and linked with a recent gcc (>=7). The current release has been compiled with gcc 7.3.0.\
203-
Go to the VanitySearch directory. ccap is the desired compute capability.
235+
## Docker
236+
237+
[![Docker Stars](https://img.shields.io/docker/stars/ratijas/vanitysearch.svg)](https://hub.docker.com/r/ratijas/vanitysearch)
238+
[![Docker Pulls](https://img.shields.io/docker/pulls/ratijas/vanitysearch.svg)](https://hub.docker.com/r/ratijas/vanitysearch)
239+
240+
### Supported tags
241+
242+
* [`latest`, `cuda-ccap-6`, `cuda-ccap-6.0` *(cuda/Dockerfile)*](./docker/cuda/Dockerfile)
243+
* [`cuda-ccap-5`, `cuda-ccap-5.2` *(cuda/Dockerfile)*](./docker/cuda/Dockerfile)
244+
* [`cuda-ccap-2`, `cuda-ccap-2.0` *(cuda/ccap-2.0.Dockerfile)*](./docker/cuda/ccap-2.0.Dockerfile)
245+
* [`cpu` *(cpu/Dockerfile)*](./docker/cpu/Dockerfile)
246+
247+
### Docker build
248+
249+
Docker images are build for CPU-only version and for each supported CUDA Compute capability version (`CCAP`). Generally, users should choose latest `CCAP` supported by their hardware and driver. Compatibility table can be found on [Wikipedia](https://en.wikipedia.org/wiki/CUDA#GPUs_supported) or at the official NVIDIA web page of your product.
250+
251+
Docker uses multi-stage builds to improve final image size. Scripts are provided to facilitate the build process.
252+
253+
When building on your own, full image name (including owner/repo parts) can be customized via `IMAGE_NAME` environment variable. It defaults to just `vanitysearch` withour owner part. Pre-built images are available on Docker hub from [@ratijas](https://hub.docker.com/r/ratijas/vanitysearch).
254+
255+
#### Docker build / CPU-only
204256

257+
Build and tag `vanitysearch:cpu` image:
258+
```sh
259+
$ ./docker/cpu/build.sh
205260
```
206-
$ g++ -v
207-
gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04)
208-
$ make all (for build without CUDA support)
209-
or
210-
$ make gpu=1 ccap=20 all
261+
262+
#### Docker build / GPU
263+
264+
Build with "default" GPU support, which might not be suitable for your system:
265+
```sh
266+
$ ./docker/cuda/build.sh
211267
```
212-
Runnig VanitySearch (Intel(R) Xeon(R) CPU, 8 cores, @ 2.93GHz, Quadro 600 (x2))
268+
269+
Build with customized GPU support:
270+
```sh
271+
$ env CCAP=5.2 CUDA=10.2 ./docker/cuda/build.sh
213272
```
214-
$export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64
215-
pons@linpons:~/VanitySearch$ ./VanitySearch -t 7 -gpu -gpuId 0,1 1TryMe
216-
VanitySearch v1.10
217-
Difficulty: 15318045009
218-
Search: 1TryMe [Compressed]
219-
Start Wed Mar 27 10:26:43 2019
220-
Base Key:C6718D8E50C1A5877DE3E52021C116F7598826873C61496BDB7CAD668CE3DCE5
221-
Number of CPU thread: 7
222-
GPU: GPU #1 Quadro 600 (2x48 cores) Grid(16x128)
223-
GPU: GPU #0 Quadro 600 (2x48 cores) Grid(16x128)
224-
40.284 MK/s (GPU 27.520 MK/s) (2^31.84) [P 22.24%][50.00% in 00:02:47][0]
225-
Pub Addr: 1TryMeERTZK7RCTemSJB5SNb2WcKSx45p
226-
Priv (WIF): Ky9bMLDpb9o5rBwHtLaidREyA6NzLFkWJ19QjPDe2XDYJdmdUsRk
227-
Priv (HEX): 0x398E7271AF3E5A78821C1ADFDE3EE90760A6B65F72D856CFE455B1264350BCE8
273+
274+
As for docker-compose folks, sorry, docker-composed GPUs are not (yet) supported on a 3.x branch. But it (hopefully) will change soon.
275+
276+
### Docker run
277+
278+
Note: VanitySearch image does not (neither should) require network access. To further ensure no data ever leaks from the running container, always pass `--network none` to the docker run command.
279+
280+
```sh
281+
$ docker run -it --rm --gpus all --network none ratijas/vanitysearch:cuda-ccap-5.2 -gpu -c -stop 1docker
282+
# VanitySearch v1.18
283+
# Difficulty: 957377813
284+
# Search: 1docker [Compressed, Case unsensitive] (Lookup size 3)
285+
# Start Sat Jul 11 17:41:32 2020
286+
# Base Key: B506F2C7CA8AA2E826F2947012CFF15D2E6CD3DA5C562E8252C9F755F2A4C5D3
287+
# Number of CPU thread: 1
288+
# GPU: GPU #0 GeForce GTX 970M (10x128 cores) Grid(80x128)
289+
#
290+
# PubAddress: 1DoCKeRXYyydeQy6xxpneqtDovXFarAwrE
291+
# Priv (WIF): p2pkh:KzESATCZFmnH1RfwT5XbCF9dZSnDGTS8z61YjnQbgFiM7tXtcH73
292+
# Priv (HEX): 0x59E27084C6252377A8B7AABB20AFD975060914B3747BD6392930BC5BE7A06565
228293
```
229294

230295
# License
231296

232297
VanitySearch is licensed under GPLv3.
233-

‎docker/build-all-supported.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
# make sure we run from the root of the repository
4+
[ "$(basename "$PWD")" == "docker" ] && cd ..
5+
6+
export IMAGE_NAME="${IMAGE_NAME:-vanitysearch}"
7+
8+
env CCAP=6.0 CUDA=10.2 ./docker/cuda/build.sh
9+
docker tag "${IMAGE_NAME}":cuda-ccap-6.0 "${IMAGE_NAME}":latest
10+
docker tag "${IMAGE_NAME}":cuda-ccap-6.0 "${IMAGE_NAME}":cuda-ccap-6
11+
12+
env CCAP=5.2 CUDA=10.2 ./docker/cuda/build.sh
13+
docker tag "${IMAGE_NAME}":cuda-ccap-5.2 "${IMAGE_NAME}":cuda-ccap-5
14+
15+
env CCAP=2.0 CUDA=8.0 ./docker/cuda/build.sh
16+
docker tag "${IMAGE_NAME}":cuda-ccap-2.0 "${IMAGE_NAME}":cuda-ccap-2
17+
18+
./docker/cpu/build.sh

‎docker/cpu/Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Multistage docker build, requires docker 17.05
2+
3+
# builder stage
4+
FROM gcc:10.1 as builder
5+
6+
COPY . /app
7+
8+
RUN cd /app && make all
9+
10+
# runtime stage
11+
FROM debian:buster-slim
12+
13+
COPY --from=builder /app/VanitySearch /usr/bin/VanitySearch
14+
15+
ENTRYPOINT ["/usr/bin/VanitySearch"]

‎docker/cpu/build.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
# make sure we run from the root of the repository
4+
[ "$(basename "$PWD")" == "cpu" ] && cd ../..
5+
[ "$(basename "$PWD")" == "docker" ] && cd ..
6+
7+
IMAGE_NAME="${IMAGE_NAME:-vanitysearch}"
8+
9+
docker build \
10+
-t "${IMAGE_NAME}:cpu" \
11+
-t "${IMAGE_NAME}:latest" \
12+
-f ./docker/cpu/Dockerfile .

‎docker/cuda/Dockerfile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Multistage docker build, requires docker 17.05
2+
3+
# CUDA SDK version, and also a prefix of images' tag.
4+
# Check out the list of officially supported tags:
5+
# https://gitlab.com/nvidia/container-images/cuda/blob/master/doc/supported-tags.md
6+
# Format: x.y, e.g.: "10.2".
7+
# Required argument.
8+
ARG CUDA
9+
10+
# builder stage
11+
FROM nvidia/cuda:${CUDA}-devel as builder
12+
13+
COPY . /app
14+
15+
# CUDA Computational Capability.
16+
# Format: x.y, e.g.: "5.2".
17+
# Required argument.
18+
ARG CCAP
19+
20+
RUN cd /app && \
21+
make \
22+
CUDA=/usr/local/cuda \
23+
CXXCUDA=/usr/bin/g++ \
24+
gpu=1 \
25+
"CCAP=${CCAP}" \
26+
all
27+
28+
# runtime stage
29+
FROM nvidia/cuda:${CUDA}-runtime
30+
31+
COPY --from=builder /app/VanitySearch /usr/bin/VanitySearch
32+
33+
ENTRYPOINT ["/usr/bin/VanitySearch"]

‎docker/cuda/build.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
# make sure we run from the root of the repository
4+
[ "$(basename "$PWD")" == "cuda" ] && cd ../..
5+
[ "$(basename "$PWD")" == "docker" ] && cd ..
6+
7+
IMAGE_NAME="${IMAGE_NAME:-vanitysearch}"
8+
# default arguments
9+
CCAP="${CCAP:-5.2}"
10+
CUDA="${CUDA:-10.2}"
11+
12+
CAPP_MAJOR="${CCAP%.*}"
13+
14+
if [ "${CAPP_MAJOR}" -lt 5 ]; then
15+
# For 2.x and 3.x branches
16+
DOCKERFILE=./docker/cuda/ccap-2.0.Dockerfile
17+
else
18+
DOCKERFILE=./docker/cuda/Dockerfile
19+
fi
20+
21+
docker build \
22+
--build-arg "CCAP=${CCAP}" \
23+
--build-arg "CUDA=${CUDA}" \
24+
-t "${IMAGE_NAME}:cuda-ccap-${CCAP}" \
25+
-f "${DOCKERFILE}" .

‎docker/cuda/ccap-2.0.Dockerfile

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Multistage docker build, requires docker 17.05
2+
3+
# CUDA SDK version, and also a prefix of images' tag.
4+
# Check out the list of officially supported tags:
5+
# https://gitlab.com/nvidia/container-images/cuda/blob/master/doc/supported-tags.md
6+
# Format: x.y, e.g.: "10.2".
7+
# Required argument.
8+
ARG CUDA
9+
10+
# builder stage
11+
FROM nvidia/cuda:${CUDA}-devel as builder
12+
13+
# Install newer version of g++ than what Ubuntu 16.04 provides.
14+
RUN apt-get update && \
15+
apt-get install -y --no-install-recommends \
16+
software-properties-common \
17+
&& \
18+
add-apt-repository ppa:ubuntu-toolchain-r/test && \
19+
apt-get update && \
20+
apt-get install -y --no-install-recommends \
21+
g++-7 \
22+
&& \
23+
rm -rf /var/lib/apt/lists/*
24+
25+
COPY . /app
26+
27+
# CUDA Computational Capability.
28+
# Format: x.y, e.g.: "5.2".
29+
# Required argument.
30+
ARG CCAP
31+
32+
RUN cd /app && \
33+
make \
34+
CXX=/usr/bin/g++-7 \
35+
CUDA=/usr/local/cuda \
36+
CXXCUDA=/usr/bin/g++ \
37+
gpu=1 \
38+
"CCAP=${CCAP}" \
39+
all
40+
41+
# runtime stage
42+
FROM nvidia/cuda:${CUDA}-runtime
43+
44+
COPY --from=builder /app/VanitySearch /usr/bin/VanitySearch
45+
46+
ENTRYPOINT ["/usr/bin/VanitySearch"]

‎docker/push-all-supported.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
export IMAGE_NAME="${IMAGE_NAME:-vanitysearch}"
4+
5+
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
6+
7+
docker push "${IMAGE_NAME}":latest
8+
docker push "${IMAGE_NAME}":cuda-ccap-6
9+
docker push "${IMAGE_NAME}":cuda-ccap-6.0
10+
11+
docker push "${IMAGE_NAME}":cuda-ccap-5
12+
docker push "${IMAGE_NAME}":cuda-ccap-5.2
13+
14+
docker push "${IMAGE_NAME}":cuda-ccap-2
15+
docker push "${IMAGE_NAME}":cuda-ccap-2.0
16+
17+
docker push "${IMAGE_NAME}":cpu

0 commit comments

Comments
 (0)
Please sign in to comment.