Skip to content

Commit

Permalink
Merge pull request #381 from filecoin-project/cuda-as-default
Browse files Browse the repository at this point in the history
Enable CUDA as default GPU backend if available
  • Loading branch information
jennijuju authored Mar 9, 2023
2 parents ffaa71d + 4fde987 commit 8baa0fa
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ commands:
echo 'export PATH="/usr/local/go/bin:${HOME}/.cargo/bin:${PATH}:${HOME}/go/bin:${HOME}/.bin"' >> $BASH_ENV
echo 'export RUST_LOG=info' >> $BASH_ENV
echo 'export CIRCLE_ARTIFACTS="/tmp"' >> $BASH_ENV
echo 'export FFI_USE_OPENCL=1' >> $BASH_ENV
- when:
condition: << parameters.darwin >>
steps:
Expand Down Expand Up @@ -323,7 +324,7 @@ commands:
no_output_timeout: 90m
- run:
name: Run the Rust tests
command: cd rust && FIL_PROOFS_PARAMETER_CACHE="${HOME}/filecoin-proof-parameters/" RUST_LOG=info cargo test --all --release -- --test-threads 1&& cd ..
command: cd rust && FIL_PROOFS_PARAMETER_CACHE="${HOME}/filecoin-proof-parameters/" RUST_LOG=info cargo test --no-default-features --features multicore-sdr,opencl --all --release -- --test-threads 1&& cd ..
no_output_timeout: 90m
- run:
name: Run the Go tests
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ rm .install-filcrypto \
; FFI_BUILD_FROM_SOURCE=1 FFI_USE_GPU=0 make
```

#### Experimental CUDA build support
#### GPU support

An experimental 'gpu' option using CUDA can be used in the proofs library. This feature is disabled by default (opencl is the default, when `FFI_USE_GPU=1` is set.). To enable building with the 'gpu' CUDA dependency, set `FFI_USE_CUDA=1` when building from source.
CUDA for GPU support is now enabled by default in the proofs library. This feature can optionally be replaced by OpenCL by using `FFI_USE_OPENCL=1` set in the environment when building from source. Alternatively, if the CUDA toolkit (such as `nvcc`) cannot be located in the environment, OpenCL support is used instead. To disable GPU support entirely, set `FFI_USE_GPU=0` in the environment when building from source.

```shell
rm .install-filcrypto \
; make clean \
; FFI_BUILD_FROM_SOURCE=1 FFI_USE_CUDA=1 make
; FFI_BUILD_FROM_SOURCE=1 make
```

By default, a 'multicore-sdr' option is used in the proofs library. This feature is also used in FFI unless explicitly disabled. To disable building with the 'multicore-sdr' dependency, set `FFI_USE_MULTICORE_SDR=0`:
Expand Down
26 changes: 21 additions & 5 deletions install-filcrypto
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,29 @@ build_from_source() {
build="build"
fi

# Default to use gpu flags, unless specified to disable
gpu_flags=",opencl"
if [ "${FFI_USE_CUDA}" == "1" ]; then
gpu_flags=",cuda"
fi
# Check if GPU support is disabled.
if [ "${FFI_USE_GPU}" == "0" ]; then
gpu_flags=""
else
# If not, default to CUDA support where possible.
# First ensure that nvcc (as part of the CUDA toolkit) is
# available -- if it's not warn that we are defaulting GPU to
# OpenCL instead.
gpu_flags=",cuda"

# Unless OpenCL support is specified or we're building on Darwin.
if [ "${FFI_USE_OPENCL}" == "1" ] || [ "$(uname -s)" = "Darwin" ]; then
gpu_flags=",opencl"
else
if [ ! "$(command -v nvcc)" ]; then
echo "WARNING: Cannot find nvcc for CUDA support."
echo "WARNING: For CUDA support, please ensure that the CUDA toolkit is properly installed."
echo "WARNING: After installation, nvcc must be in the system path."
echo ""
echo "WARNING: Defaulting to OpenCL GPU support(!!!)"
gpu_flags=",opencl"
fi
fi
fi

# Default to use multicore_sdr flags, unless specified to disable
Expand Down
4 changes: 2 additions & 2 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ memmap2 = "0.5"
tempfile = "3.0.8"

[features]
default = ["opencl", "multicore-sdr" ]
default = ["cuda", "multicore-sdr" ]
blst-portable = ["bls-signatures/blst-portable", "blstrs/portable"]
opencl = ["filecoin-proofs-api/opencl", "rust-gpu-tools/opencl", "fvm3/opencl", "fvm2/opencl"]
cuda = ["filecoin-proofs-api/cuda", "rust-gpu-tools/cuda", "fvm3/cuda", "fvm2/cuda"]
opencl = ["filecoin-proofs-api/opencl", "rust-gpu-tools/opencl", "fvm3/opencl", "fvm2/opencl"]
multicore-sdr = ["filecoin-proofs-api/multicore-sdr"]
c-headers = ["safer-ffi/headers"]
2 changes: 1 addition & 1 deletion rust/scripts/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ main() {

# generate filcrypto.h
RUSTFLAGS="${__rust_flags}" HEADER_DIR="." \
cargo test --locked build_headers --features c-headers
cargo test --no-default-features --features multicore-sdr,opencl --locked build_headers --features c-headers

# generate pkg-config
#
Expand Down

0 comments on commit 8baa0fa

Please sign in to comment.