Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(candle): Allow enabling accelerate #1009

Merged
merged 8 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend-comparison/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ default = ["std"]
std = []
candle-cpu = ["burn/candle"]
candle-cuda = ["burn/candle-cuda"]
candle-accelerate = ["burn/candle-accelerate"]
ndarray = ["burn/ndarray"]
ndarray-blas-accelerate = ["burn/ndarray-blas-accelerate"]
ndarray-blas-netlib = ["burn/ndarray-blas-netlib"]
Expand Down
1 change: 1 addition & 0 deletions burn-candle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ version = "0.11.0"

[features]
cuda = ["candle-core/cuda"]
accelerate = ["candle-core/accelerate"]

[dependencies]
derive-new = { workspace = true }
Expand Down
9 changes: 8 additions & 1 deletion burn-candle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@ This crate provides a backend for [Burn](https://github.com/burn-rs/burn) based

It is still in alpha stage, not all operations are supported. It is usable for some use cases, like for inference.

It can be used with CPU or CUDA.
It can be used with CPU or CUDA. On macOS computations can be accelerated by using the Accelerate framework.

## Feature Flags

The following features are supported:

- `cuda` - Cuda GPU device (NVIDIA only)
- `accelerate` - Accelerate framework (macOS only)
3 changes: 2 additions & 1 deletion burn-candle/src/ops/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ impl<F: FloatCandleElement, I: IntCandleElement> TensorOps<Self> for Candle<F, I
lhs: FloatTensor<Self, D>,
rhs: FloatTensor<Self, D>,
) -> FloatTensor<Self, D> {
CandleTensor::new(lhs.tensor.broadcast_matmul(&rhs.tensor).unwrap())
let rhs_contiguous = rhs.tensor.contiguous().unwrap();
CandleTensor::new(lhs.tensor.broadcast_matmul(&rhs_contiguous).unwrap())
}

fn swap_dims<const D: usize>(
Expand Down
1 change: 1 addition & 0 deletions burn-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ tch = ["burn-tch"]

candle = ["burn-candle"]
candle-cuda = ["candle", "burn-candle/cuda"]
candle-accelerate = ["candle", "burn-candle/accelerate"]

# Serialization formats
experimental-named-tensor = ["burn-tensor/experimental-named-tensor"]
Expand Down
1 change: 1 addition & 0 deletions burn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ wgpu = ["burn-core/wgpu"]
tch = ["burn-core/tch"]
candle = ["burn-core/candle"]
candle-cuda = ["burn-core/candle-cuda"]
candle-accelerate = ["burn-core/candle-accelerate"]

# Experimental
experimental-named-tensor = ["burn-core/experimental-named-tensor"]
Expand Down
11 changes: 11 additions & 0 deletions xtask/src/runchecks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ fn burn_dataset_features_std() {
cargo_doc(["-p", "burn-dataset", "--all-features"].into());
}

// Test burn-candle with accelerate (macOS only)
// Leverages the macOS Accelerate framework: https://developer.apple.com/documentation/accelerate
#[cfg(target_os = "macos")]
dcvz marked this conversation as resolved.
Show resolved Hide resolved
fn burn_candle_accelerate() {
cargo_test(["-p", "burn-candle", "--features", "accelerate"].into());
}

fn std_checks() {
// Set RUSTDOCFLAGS environment variable to treat warnings as errors
// for the documentation build
Expand Down Expand Up @@ -284,6 +291,10 @@ fn std_checks() {
// Test each workspace
cargo_test(["--workspace"].into());

// Test burn-candle with accelerate (macOS only)
#[cfg(target_os = "macos")]
burn_candle_accelerate();

// Test burn-dataset features
burn_dataset_features_std();

Expand Down