Skip to content

Commit

Permalink
Docker builds for CPU and CUDA
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ratijas committed Jul 11, 2020
1 parent 6fa4ce9 commit cccb3fc
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 30 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ CXX = g++
CUDA = /usr/local/cuda-8.0
CXXCUDA = /usr/bin/g++-4.8
NVCC = $(CUDA)/bin/nvcc
# nvcc requires joint notation w/o dot, i.e. "5.2" -> "52"
ccap = $(shell echo $(CCAP) | tr -d '.')

ifdef gpu
ifdef debug
Expand Down
124 changes: 94 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,45 +189,109 @@ Note: The current relase has been compiled with CUDA SDK 10.0, if you have a dif

## Linux

Intall CUDA SDK.\
Depenging on the CUDA SDK version and on your Linux distribution you may need to install an older g++ (just for the CUDA SDK).\
Edit the makefile and set up the good CUDA SDK path and appropriate compiler for nvcc.
- Intall CUDA SDK.
- 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++.
- 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.
- Edit the makefile and set up the appropriate CUDA SDK and compiler paths for nvcc. Or pass them as variables to `make` invocation.

```make
CUDA = /usr/local/cuda-8.0
CXXCUDA = /usr/bin/g++-4.8
```

- You can enter a list of architectrures (refer to nvcc documentation) if you have several GPU with different architecture.

- 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.

- Go to the VanitySearch directory.
- To build CPU-only version (without CUDA support):
```sh
$ make all
```
- To build with CUDA:
```sh
$ make gpu=1 CCAP=2.0 all
```

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

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.
VanitySearch need to be compiled and linked with a recent gcc (>=7). The current release has been compiled with gcc 7.3.0.\
Go to the VanitySearch directory. ccap is the desired compute capability.
## Docker

[![Docker Stars](https://img.shields.io/docker/stars/ratijas/vanitysearch.svg)](https://hub.docker.com/r/ratijas/vanitysearch)
[![Docker Pulls](https://img.shields.io/docker/pulls/ratijas/vanitysearch.svg)](https://hub.docker.com/r/ratijas/vanitysearch)

### Supported tags

* [`latest`, `cuda-ccap-6`, `cuda-ccap-6.0` *(cuda/Dockerfile)*](./docker/cuda/Dockerfile)
* [`cuda-ccap-5`, `cuda-ccap-5.2` *(cuda/Dockerfile)*](./docker/cuda/Dockerfile)
* [`cuda-ccap-2`, `cuda-ccap-2.0` *(cuda/ccap-2.0.Dockerfile)*](./docker/cuda/ccap-2.0.Dockerfile)
* [`cpu` *(cpu/Dockerfile)*](./docker/cpu/Dockerfile)

### Docker build

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.

Docker uses multi-stage builds to improve final image size. Scripts are provided to facilitate the build process.

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).

#### Docker build / CPU-only

Build and tag `vanitysearch:cpu` image:
```sh
$ ./docker/cpu/build.sh
```
$ g++ -v
gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04)
$ make all (for build without CUDA support)
or
$ make gpu=1 ccap=20 all

#### Docker build / GPU

Build with "default" GPU support, which might not be suitable for your system:
```sh
$ ./docker/cuda/build.sh
```
Runnig VanitySearch (Intel(R) Xeon(R) CPU, 8 cores, @ 2.93GHz, Quadro 600 (x2))

Build with customized GPU support:
```sh
$ env CCAP=5.2 CUDA=10.2 ./docker/cuda/build.sh
```
$export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64
pons@linpons:~/VanitySearch$ ./VanitySearch -t 7 -gpu -gpuId 0,1 1TryMe
VanitySearch v1.10
Difficulty: 15318045009
Search: 1TryMe [Compressed]
Start Wed Mar 27 10:26:43 2019
Base Key:C6718D8E50C1A5877DE3E52021C116F7598826873C61496BDB7CAD668CE3DCE5
Number of CPU thread: 7
GPU: GPU #1 Quadro 600 (2x48 cores) Grid(16x128)
GPU: GPU #0 Quadro 600 (2x48 cores) Grid(16x128)
40.284 MK/s (GPU 27.520 MK/s) (2^31.84) [P 22.24%][50.00% in 00:02:47][0]
Pub Addr: 1TryMeERTZK7RCTemSJB5SNb2WcKSx45p
Priv (WIF): Ky9bMLDpb9o5rBwHtLaidREyA6NzLFkWJ19QjPDe2XDYJdmdUsRk
Priv (HEX): 0x398E7271AF3E5A78821C1ADFDE3EE90760A6B65F72D856CFE455B1264350BCE8

As for docker-compose folks, sorry, docker-composed GPUs are not (yet) supported on a 3.x branch. But it (hopefully) will change soon.

### Docker run

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.

```sh
$ docker run -it --rm --gpus all --network none ratijas/vanitysearch:cuda-ccap-5.2 -gpu -c -stop 1docker
# VanitySearch v1.18
# Difficulty: 957377813
# Search: 1docker [Compressed, Case unsensitive] (Lookup size 3)
# Start Sat Jul 11 17:41:32 2020
# Base Key: B506F2C7CA8AA2E826F2947012CFF15D2E6CD3DA5C562E8252C9F755F2A4C5D3
# Number of CPU thread: 1
# GPU: GPU #0 GeForce GTX 970M (10x128 cores) Grid(80x128)
#
# PubAddress: 1DoCKeRXYyydeQy6xxpneqtDovXFarAwrE
# Priv (WIF): p2pkh:KzESATCZFmnH1RfwT5XbCF9dZSnDGTS8z61YjnQbgFiM7tXtcH73
# Priv (HEX): 0x59E27084C6252377A8B7AABB20AFD975060914B3747BD6392930BC5BE7A06565
```

# License

VanitySearch is licensed under GPLv3.

18 changes: 18 additions & 0 deletions docker/build-all-supported.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

# make sure we run from the root of the repository
[ "$(basename "$PWD")" == "docker" ] && cd ..

export IMAGE_NAME="${IMAGE_NAME:-vanitysearch}"

env CCAP=6.0 CUDA=10.2 ./docker/cuda/build.sh
docker tag "${IMAGE_NAME}":cuda-ccap-6.0 "${IMAGE_NAME}":latest
docker tag "${IMAGE_NAME}":cuda-ccap-6.0 "${IMAGE_NAME}":cuda-ccap-6

env CCAP=5.2 CUDA=10.2 ./docker/cuda/build.sh
docker tag "${IMAGE_NAME}":cuda-ccap-5.2 "${IMAGE_NAME}":cuda-ccap-5

env CCAP=2.0 CUDA=8.0 ./docker/cuda/build.sh
docker tag "${IMAGE_NAME}":cuda-ccap-2.0 "${IMAGE_NAME}":cuda-ccap-2

./docker/cpu/build.sh
15 changes: 15 additions & 0 deletions docker/cpu/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Multistage docker build, requires docker 17.05

# builder stage
FROM gcc:10.1 as builder

COPY . /app

RUN cd /app && make all

# runtime stage
FROM debian:buster-slim

COPY --from=builder /app/VanitySearch /usr/bin/VanitySearch

ENTRYPOINT ["/usr/bin/VanitySearch"]
12 changes: 12 additions & 0 deletions docker/cpu/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

# make sure we run from the root of the repository
[ "$(basename "$PWD")" == "cpu" ] && cd ../..
[ "$(basename "$PWD")" == "docker" ] && cd ..

IMAGE_NAME="${IMAGE_NAME:-vanitysearch}"

docker build \
-t "${IMAGE_NAME}:cpu" \
-t "${IMAGE_NAME}:latest" \
-f ./docker/cpu/Dockerfile .
33 changes: 33 additions & 0 deletions docker/cuda/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Multistage docker build, requires docker 17.05

# CUDA SDK version, and also a prefix of images' tag.
# Check out the list of officially supported tags:
# https://gitlab.com/nvidia/container-images/cuda/blob/master/doc/supported-tags.md
# Format: x.y, e.g.: "10.2".
# Required argument.
ARG CUDA

# builder stage
FROM nvidia/cuda:${CUDA}-devel as builder

COPY . /app

# CUDA Computational Capability.
# Format: x.y, e.g.: "5.2".
# Required argument.
ARG CCAP

RUN cd /app && \
make \
CUDA=/usr/local/cuda \
CXXCUDA=/usr/bin/g++ \
gpu=1 \
"CCAP=${CCAP}" \
all

# runtime stage
FROM nvidia/cuda:${CUDA}-runtime

COPY --from=builder /app/VanitySearch /usr/bin/VanitySearch

ENTRYPOINT ["/usr/bin/VanitySearch"]
25 changes: 25 additions & 0 deletions docker/cuda/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

# make sure we run from the root of the repository
[ "$(basename "$PWD")" == "cuda" ] && cd ../..
[ "$(basename "$PWD")" == "docker" ] && cd ..

IMAGE_NAME="${IMAGE_NAME:-vanitysearch}"
# default arguments
CCAP="${CCAP:-5.2}"
CUDA="${CUDA:-10.2}"

CAPP_MAJOR="${CCAP%.*}"

if [ "${CAPP_MAJOR}" -lt 5 ]; then
# For 2.x and 3.x branches
DOCKERFILE=./docker/cuda/ccap-2.0.Dockerfile
else
DOCKERFILE=./docker/cuda/Dockerfile
fi

docker build \
--build-arg "CCAP=${CCAP}" \
--build-arg "CUDA=${CUDA}" \
-t "${IMAGE_NAME}:cuda-ccap-${CCAP}" \
-f "${DOCKERFILE}" .
46 changes: 46 additions & 0 deletions docker/cuda/ccap-2.0.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Multistage docker build, requires docker 17.05

# CUDA SDK version, and also a prefix of images' tag.
# Check out the list of officially supported tags:
# https://gitlab.com/nvidia/container-images/cuda/blob/master/doc/supported-tags.md
# Format: x.y, e.g.: "10.2".
# Required argument.
ARG CUDA

# builder stage
FROM nvidia/cuda:${CUDA}-devel as builder

# Install newer version of g++ than what Ubuntu 16.04 provides.
RUN apt-get update && \
apt-get install -y --no-install-recommends \
software-properties-common \
&& \
add-apt-repository ppa:ubuntu-toolchain-r/test && \
apt-get update && \
apt-get install -y --no-install-recommends \
g++-7 \
&& \
rm -rf /var/lib/apt/lists/*

COPY . /app

# CUDA Computational Capability.
# Format: x.y, e.g.: "5.2".
# Required argument.
ARG CCAP

RUN cd /app && \
make \
CXX=/usr/bin/g++-7 \
CUDA=/usr/local/cuda \
CXXCUDA=/usr/bin/g++ \
gpu=1 \
"CCAP=${CCAP}" \
all

# runtime stage
FROM nvidia/cuda:${CUDA}-runtime

COPY --from=builder /app/VanitySearch /usr/bin/VanitySearch

ENTRYPOINT ["/usr/bin/VanitySearch"]
17 changes: 17 additions & 0 deletions docker/push-all-supported.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

export IMAGE_NAME="${IMAGE_NAME:-vanitysearch}"

echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

docker push "${IMAGE_NAME}":latest
docker push "${IMAGE_NAME}":cuda-ccap-6
docker push "${IMAGE_NAME}":cuda-ccap-6.0

docker push "${IMAGE_NAME}":cuda-ccap-5
docker push "${IMAGE_NAME}":cuda-ccap-5.2

docker push "${IMAGE_NAME}":cuda-ccap-2
docker push "${IMAGE_NAME}":cuda-ccap-2.0

docker push "${IMAGE_NAME}":cpu

0 comments on commit cccb3fc

Please sign in to comment.