Skip to content

Commit

Permalink
feat: diffusion.cpp bindings (#1)
Browse files Browse the repository at this point in the history
* feat: binding crate

* cicd: fix ubuntu pipeline

* ci: fix ubuntu runner v2

* ci: fix ubuntu runner v3

* ci: fix submodules pull

* ci: try cuda on win2022 runner

* ci: vulkan builder

* fix(ci): install vulkan on all platforms

* fix(ci): macos vulkan runner

* feat: sycl support

* fix(ci): sycl runner fix

* ci: rocm runner introduction

* fix(ci): cleanup space rocm runner

* fix(ci): reworked build phase rocm runner

* feat: windows hipblas support

* ci: pipeline refactoring

* doc: updated readme

* fix: fmt
  • Loading branch information
newfla authored Oct 16, 2024
1 parent c59617b commit 1325035
Show file tree
Hide file tree
Showing 12 changed files with 463 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "cargo" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
157 changes: 157 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
name: test

on:
workflow_dispatch:
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
cargo-fmt:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Ubuntu build dependencies
run: sudo apt update && sudo apt install -y clang cmake
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Check Style
run: cargo fmt --check

build-no-features:
needs: cargo-fmt
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Ubuntu build dependencies
if: matrix.platform == 'ubuntu-latest'
run: sudo apt update && sudo apt install -y clang cmake
- uses: dtolnay/rust-toolchain@stable
- name: Build
run: cargo build

build-vulkan:
needs: build-no-features
strategy:
fail-fast: false
matrix:
platform: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-latest'
run: sudo apt update && sudo apt install -y clang cmake
- name: Install vulkan sdk
uses: humbletim/install-vulkan-sdk@c2aa128094d42ba02959a660f03e0a4e012192f9
with:
version: 1.3.250.1
cache: true
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Build
run: cargo build --features vulkan


build-metal:
needs: build-no-features
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- uses: dtolnay/rust-toolchain@stable
- name: Build
run: cargo build --features metal

build-cuda:
needs: build-no-features
strategy:
fail-fast: false
matrix:
platform: [ubuntu-22.04, windows-2022]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Install cuda toolkit
uses: Jimver/[email protected]
- name: Install Windows dependencies
if: matrix.platform == 'windows-2022'
uses: ilammy/msvc-dev-cmd@v1
- name: Ubuntu build dependencies
if: matrix.platform == 'ubuntu-22.04'
run: sudo apt update && sudo apt install -y clang cmake
- uses: dtolnay/rust-toolchain@stable
- name: Build
env:
CUDA_COMPUTE_CAP: "75"
run: cargo build --features cublas

build-rocm:
needs: build-no-features
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Free Disk Space (Ubuntu) for Rocm
uses: jlumbroso/free-disk-space@main
with:
tool-cache: false
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: true
- name: Ubuntu build dependencies
run: sudo apt update && sudo apt install -y clang cmake ninja-build
- name: Install Rocm Toolkit
run: |
wget https://repo.radeon.com/amdgpu-install/6.1.2/ubuntu/jammy/amdgpu-install_6.1.60102-1_all.deb
sudo apt install ./amdgpu-install_6.1.60102-1_all.deb
sudo apt update
sudo apt install -y rocm
- uses: dtolnay/rust-toolchain@stable
- name: Build
env:
AMDGPU_TARGETS: "gfx1100"
run: cargo build --features hipblas

build-sycl:
needs: build-no-features
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Ubuntu build dependencies
run: sudo apt update && sudo apt install -y clang cmake
- name: Install oneAPI Toolkit
run: |
wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
| gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" \
| sudo tee /etc/apt/sources.list.d/oneAPI.list
sudo apt update && sudo apt install -y intel-basekit intel-hpckit
- uses: dtolnay/rust-toolchain@stable
- name: Build
run: |
source /opt/intel/oneapi/setvars.sh
cargo build --features sycl
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ Cargo.lock
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/
bin/act
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "sys/stable-diffusion.cpp"]
path = sys/stable-diffusion.cpp
url = https://github.com/leejet/stable-diffusion.cpp
22 changes: 22 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[workspace]
members = ["sys"]

[package]
name = "diffusion-rs"
version = "0.1.0"
edition = "2021"
description = "Rust bindings for stable-diffusion.cpp"
license = "MIT"
documentation = "https://docs.rs/diffusion-rs"
repository = "https://github.com/newfla/diffusion-rs"

[dependencies]
diffusion-rs-sys = { path = "sys", version = "0.1.0" }

[features]
cublas = ["diffusion-rs-sys/cublas"]
hipblas = ["diffusion-rs-sys/hipblas"]
metal = ["diffusion-rs-sys/metal"]
vulkan = ["diffusion-rs-sys/vulkan"]
sycl = ["diffusion-rs-sys/sycl"]
flashattn = ["diffusion-rs-sys/flashattn"]
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# diffusion-rs
Rust bindings to https://github.com/leejet/stable-diffusion.cpp

## Features Matrix
| | Windows | Mac | Linux |
| --- | :---: | :---: | :---: |
|vulkan| ✅️ | ✅️ | ✅️ |
|metal| ❌️ | ✅️ | ❌️ |
|cuda| ✅️ | ❌️ | ✅️ |
|rocm| ❔️ | ❌️ | ✅️ |
|sycl| ❔️ | ❌️ | ✅️ |

❔️: Not tested, should be supported

## Roadmap
1. ~~Ensure that the underline cpp library compiles on supported platforms~~
2. Build an easy to use library with models download and async interface
3. Automatic library publishing on crates.io by gh actions
4. _Maybe_ prebuilt CLI app binaries
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

48 changes: 48 additions & 0 deletions sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[package]
name = "diffusion-rs-sys"
version = "0.1.0"
edition = "2021"
description = "Rust bindings for stable-diffusion.cpp (FFI bindings)"
license = "MIT"
documentation = "https://docs.rs/diffusion-rs-sys"
repository = "https://github.com/newfla/diffusion-rs"
links = "stable-diffusion"
include = [
"stable-diffusion.cpp/LICENSE",
"stable-diffusion.cpp/CMakeLists.txt",
"stable-diffusion.cpp/stable-diffusion.cpp",
"stable-diffusion.cpp/stable-diffusion.h",
"stable-diffusion.cpp/ggml/src/ggml.c",
"stable-diffusion.cpp/ggml/src/ggml-alloc.c",
"stable-diffusion.cpp/ggml/src/ggml-backend.c",
"stable-diffusion.cpp/ggml/src/ggml-cuda.cu",
"stable-diffusion.cpp/ggml/src/ggml-impl.h",
"stable-diffusion.cpp/ggml/src/ggml-metal.m",
"stable-diffusion.cpp/ggml/src/ggml-metal.metal",
"stable-diffusion.cpp/ggml/src/ggml-quants.h",
"stable-diffusion.cpp/ggml/src/ggml-quants.c",
"stable-diffusion.cpp/ggml/include/ggml.h",
"stable-diffusion.cpp/ggml/include/ggml-alloc.h",
"stable-diffusion.cpp/ggml/include/ggml-backend.h",
"stable-diffusion.cpp/ggml/include/ggml-backend-impl.h",
"stable-diffusion.cpp/ggml/include/ggml-cuda.h",
"stable-diffusion.cpp/ggml/include/ggml-metal.h",
"src/*.rs",
"build.rs",
"wrapper.h",
]

[dependencies]

[features]
cublas = []
hipblas = []
metal = []
vulkan = []
sycl = []
flashattn = []

[build-dependencies]
cmake = "0.1.51"
bindgen = "0.70.1"
fs_extra = "1.3.0"
Loading

0 comments on commit 1325035

Please sign in to comment.