Skip to content

Commit

Permalink
chore: redo CI (#88)
Browse files Browse the repository at this point in the history
Using GPU workers is only needed for running the tests. Use other
(way cheaper) machines for the other steps. This reduces the costs
by about 7.5x (from around 1300 to 170 credits).

Also the total runtime is about half now.
  • Loading branch information
vmx authored Apr 11, 2024
1 parent 6454672 commit d68dd2d
Showing 1 changed file with 27 additions and 116 deletions.
143 changes: 27 additions & 116 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,137 +2,62 @@ version: 2.1

executors:
default:
docker:
- image: cimg/rust:1.70
resource_class: small
gpu:
machine:
image: linux-cuda-12:2023.05.1
working_directory: ~/gpuci
resource_class: gpu.nvidia.medium
resource_class: gpu.nvidia.small

restore-workspace: &restore-workspace
attach_workspace:
at: ~/

restore-cache: &restore-cache
restore_cache:
keys:
- cargo-v0-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
- repo-source-{{ .Branch }}-{{ .Revision }}

commands:
set-env-path:
jobs:
test:
executor: gpu
steps:
- checkout
- run:
name: Set the PATH env variable
name: Install OpenCL
command: |
echo 'export PATH="$HOME:~/.cargo/bin:/usr/local/cuda-11.2/bin:$PATH"' | tee --append $BASH_ENV
source $BASH_ENV
test_target:
parameters:
target:
type: string
steps:
- *restore-workspace
- *restore-cache
sudo apt update
sudo apt install ocl-icd-opencl-dev --no-install-recommends --yes
- run:
name: Test (<< parameters.target >>)
command: TARGET=<< parameters.target >> cargo test
no_output_timeout: 15m

jobs:

cargo_fetch:
executor: default
steps:
- checkout
- run: curl https://sh.rustup.rs -sSf | sh -s -- -y
- set-env-path
- run: echo $BASH_ENV
- run: echo $HOME
- run: cargo --version
- run: rustc --version
name: Install Rust
command: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain $(cat rust-toolchain) --profile minimal -y
- run:
name: Update submodules
command: git submodule update --init --recursive
name: Run tests
command: cargo test
- run:
name: Calculate dependencies
command: cargo generate-lockfile
- restore_cache:
keys:
- cargo-v0-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
- run: cargo update
- run: cargo fetch
- run: rustup install $(cat rust-toolchain)
- run: rustup default $(cat rust-toolchain)
- run: rustc --version
- run: rm -rf .git
- persist_to_workspace:
root: ~/
paths:
- gpuci
- save_cache:
key: cargo-v0-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
paths:
- "~/.cargo"
- "~/.rustup"

test_x86_64-unknown-linux-gnu:
executor: default
steps:
- set-env-path
- run: sudo apt-get update -y
- run: apt-cache search opencl
- run: sudo apt install -y ocl-icd-opencl-dev
- test_target:
target: "x86_64-unknown-linux-gnu"
name: Run `add` example
command: cargo run --example add

rustfmt:
executor: default
steps:
- *restore-workspace
- *restore-cache
- set-env-path
- run: echo 'export PATH="$HOME:~/.cargo/bin:$PATH"' >> $BASH_ENV
- run: source $BASH_ENV
- checkout
- run:
name: Run cargo fmt
command: cargo fmt --all -- --check

clippy:
executor: default
steps:
- *restore-workspace
- *restore-cache
- set-env-path
- checkout
- run:
name: Run cargo clippy
command: cargo clippy --all-features --all-targets -- -D warnings

build:
executor: default
steps:
- *restore-workspace
- *restore-cache
- set-env-path
- checkout
- run:
name: Run cargo release build
command: cargo build --release

example:
executor: default
steps:
- *restore-workspace
- *restore-cache
- set-env-path
- run:
name: Run `add` example
command: cargo run --example add

rustdoc:
executor: default
steps:
- *restore-workspace
- *restore-cache
- set-env-path
- checkout
- run:
name: Run rustdoc
command: cargo rustdoc --all-features -- -D warnings
Expand All @@ -142,22 +67,8 @@ workflows:

test:
jobs:
- cargo_fetch
- rustfmt:
requires:
- cargo_fetch
- clippy:
requires:
- cargo_fetch
- test_x86_64-unknown-linux-gnu:
requires:
- cargo_fetch
- build:
requires:
- cargo_fetch
- example:
requires:
- cargo_fetch
- rustdoc:
requires:
- cargo_fetch
- rustfmt
- clippy
- test
- build
- rustdoc

0 comments on commit d68dd2d

Please sign in to comment.