feat: update workspace paths and enhance gitignore
- Updated stablediffusion crate path from "../stable-diffusion-burn" to "./crates/stable-diffusion-burn" for proper workspace resolution - Enhanced .gitignore to include generated model files (.mpk, .pt, .bin, .safetensors, .ckpt) and user_data directory - Added Cargo.lock to gitignore with appropriate comment - Reorganized IDE files section in gitignore for better clarity - Added newline at end of file for proper formatting
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
[package]
|
||||
authors = ["nathanielsimard <nathaniel.simard.42@gmail.com>"]
|
||||
categories = ["science"]
|
||||
description = "WGPU backend for the Burn framework"
|
||||
documentation = "https://docs.rs/burn-wgpu"
|
||||
edition.workspace = true
|
||||
keywords = ["deep-learning", "machine-learning", "gpu", "wgpu", "webgpu"]
|
||||
license.workspace = true
|
||||
name = "burn-wgpu"
|
||||
readme.workspace = true
|
||||
repository = "https://github.com/tracel-ai/burn/tree/main/crates/burn-wgpu"
|
||||
version.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[features]
|
||||
default = ["std", "autotune", "fusion", "burn-cubecl/default", "cubecl/default"]
|
||||
doc = ["burn-cubecl/doc"]
|
||||
std = ["burn-cubecl/std", "cubecl/std"]
|
||||
tracing = [
|
||||
"cubecl/tracing",
|
||||
"burn-backend/tracing",
|
||||
"burn-fusion?/tracing",
|
||||
"burn-cubecl/tracing",
|
||||
]
|
||||
|
||||
autotune = ["burn-cubecl/autotune"]
|
||||
autotune-checks = ["burn-cubecl/autotune-checks"]
|
||||
exclusive-memory-only = ["cubecl/exclusive-memory-only"]
|
||||
fusion = ["burn-fusion", "burn-cubecl/fusion"]
|
||||
template = ["burn-cubecl/template", "cubecl/template"]
|
||||
|
||||
# Backends
|
||||
metal = ["cubecl-msl"]
|
||||
vulkan = ["cubecl-spirv"]
|
||||
webgpu = ["cubecl-wgsl"]
|
||||
|
||||
# Compilers
|
||||
cubecl-msl = ["cubecl/wgpu-msl"]
|
||||
cubecl-spirv = ["cubecl/wgpu-spirv"]
|
||||
cubecl-wgsl = []
|
||||
|
||||
[dependencies]
|
||||
cubecl = { workspace = true, features = ["wgpu"] }
|
||||
|
||||
burn-cubecl = { path = "../burn-cubecl", version = "=0.21.0-pre.2", default-features = false }
|
||||
burn-fusion = { path = "../burn-fusion", version = "=0.21.0-pre.2", optional = true }
|
||||
burn-backend = { path = "../burn-backend", version = "=0.21.0-pre.2", default-features = false, features = [
|
||||
"cubecl-wgpu",
|
||||
] }
|
||||
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = ["default"]
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
@@ -0,0 +1 @@
|
||||
../../LICENSE-APACHE
|
||||
1
crates/stable-diffusion-burn/burn-crates/burn-wgpu/LICENSE-MIT
Symbolic link
1
crates/stable-diffusion-burn/burn-crates/burn-wgpu/LICENSE-MIT
Symbolic link
@@ -0,0 +1 @@
|
||||
../../LICENSE-MIT
|
||||
59
crates/stable-diffusion-burn/burn-crates/burn-wgpu/README.md
Normal file
59
crates/stable-diffusion-burn/burn-crates/burn-wgpu/README.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# Burn WGPU Backend
|
||||
|
||||
[Burn](https://github.com/tracel-ai/burn) WGPU backend
|
||||
|
||||
[](https://crates.io/crates/burn-wgpu)
|
||||
[](https://github.com/tracel-ai/burn-wgpu/blob/master/README.md)
|
||||
|
||||
This crate provides a WGPU backend for [Burn](https://github.com/tracel-ai/burn) using the
|
||||
[wgpu](https://github.com/gfx-rs/wgpu).
|
||||
|
||||
The backend supports Vulkan, Metal, DirectX11/12, OpenGL, WebGPU.
|
||||
|
||||
## Usage Example
|
||||
|
||||
```rust
|
||||
#[cfg(feature = "wgpu")]
|
||||
mod wgpu {
|
||||
use burn_autodiff::Autodiff;
|
||||
use burn_wgpu::{Wgpu, WgpuDevice};
|
||||
use mnist::training;
|
||||
|
||||
pub fn run() {
|
||||
let device = WgpuDevice::default();
|
||||
training::run::<Autodiff<Wgpu<f32, i32>>>(device);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> ⚠️ **Warning**
|
||||
> When using one of the `wgpu` backends, you may encounter compilation errors related to recursive type evaluation. This is due to complex type nesting within the `wgpu` dependency chain.
|
||||
> To resolve this issue, add the following line at the top of your `main.rs` or `lib.rs` file:
|
||||
> ```rust
|
||||
> #![recursion_limit = "256"]
|
||||
> ```
|
||||
> The default recursion limit (128) is often just below the required depth (typically 130-150) due to deeply nested associated types and trait bounds.
|
||||
|
||||
|
||||
## Configuration
|
||||
|
||||
You can set `BURN_WGPU_MAX_TASKS` to a positive integer that determines how many computing tasks are
|
||||
submitted in batches to the graphics API.
|
||||
|
||||
## Alternative SPIR-V backend
|
||||
|
||||
When targeting Vulkan, the `spirv` feature flag can be enabled to enable the SPIR-V compiler
|
||||
backend, which performs significantly better than WGSL. This is especially true for matrix
|
||||
multiplication, where SPIR-V can make use of TensorCores and run at `f16` precision. This isn't
|
||||
currently supported by WGSL. The compiler can also be selected at runtime by setting the
|
||||
corresponding generic parameter to either `SpirV` or `Wgsl`.
|
||||
|
||||
## Platform Support
|
||||
|
||||
| Option | CPU | GPU | Linux | MacOS | Windows | Android | iOS | WASM |
|
||||
| :-------- | :-: | :-: | :---: | :---: | :-----: | :-----: | :-: | :--: |
|
||||
| Metal | No | Yes | No | Yes | No | No | Yes | No |
|
||||
| Vulkan | Yes | Yes | Yes | Yes | Yes | Yes | Yes | No |
|
||||
| OpenGL | No | Yes | Yes | Yes | Yes | Yes | Yes | No |
|
||||
| WebGpu | No | Yes | No | No | No | No | No | Yes |
|
||||
| Dx11/Dx12 | No | Yes | No | No | Yes | No | No | No |
|
||||
189
crates/stable-diffusion-burn/burn-crates/burn-wgpu/src/lib.rs
Normal file
189
crates/stable-diffusion-burn/burn-crates/burn-wgpu/src/lib.rs
Normal file
@@ -0,0 +1,189 @@
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
#[cfg(feature = "template")]
|
||||
pub use burn_cubecl::{
|
||||
kernel::{KernelMetadata, into_contiguous},
|
||||
kernel_source,
|
||||
template::{KernelSource, SourceKernel, SourceTemplate, build_info},
|
||||
};
|
||||
|
||||
pub use burn_cubecl::{BoolElement, FloatElement, IntElement};
|
||||
pub use burn_cubecl::{CubeBackend, tensor::CubeTensor};
|
||||
pub use cubecl::CubeDim;
|
||||
pub use cubecl::flex32;
|
||||
|
||||
pub use cubecl::wgpu::{
|
||||
AutoCompiler, MemoryConfiguration, RuntimeOptions, WgpuDevice, WgpuResource, WgpuRuntime,
|
||||
WgpuSetup, WgpuStorage, init_device, init_setup, init_setup_async,
|
||||
};
|
||||
// Vulkan and WebGpu would have conflicting type names
|
||||
pub mod graphics {
|
||||
pub use cubecl::wgpu::{AutoGraphicsApi, Dx12, GraphicsApi, Metal, OpenGl, Vulkan, WebGpu};
|
||||
}
|
||||
|
||||
#[cfg(feature = "cubecl-wgsl")]
|
||||
pub use cubecl::wgpu::WgslCompiler;
|
||||
#[cfg(feature = "cubecl-spirv")]
|
||||
pub use cubecl::wgpu::vulkan::VkSpirvCompiler;
|
||||
|
||||
#[cfg(feature = "fusion")]
|
||||
/// Tensor backend that uses the wgpu crate for executing GPU compute shaders.
|
||||
///
|
||||
/// This backend can target multiple graphics APIs, including:
|
||||
/// - [Vulkan][crate::graphics::Vulkan] on Linux, Windows, and Android.
|
||||
/// - [OpenGL](crate::graphics::OpenGl) on Linux, Windows, and Android.
|
||||
/// - [DirectX 12](crate::graphics::Dx12) on Windows.
|
||||
/// - [Metal][crate::graphics::Metal] on Apple hardware.
|
||||
/// - [WebGPU](crate::graphics::WebGpu) on supported browsers and `wasm` runtimes.
|
||||
///
|
||||
/// To configure the wgpu backend, eg. to select what graphics API to use or what memory strategy to use,
|
||||
/// you have to manually initialize the runtime. For example:
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// fn custom_init() {
|
||||
/// let device = Default::default();
|
||||
/// burn::backend::wgpu::init_setup::<burn::backend::wgpu::graphics::Vulkan>(
|
||||
/// &device,
|
||||
/// Default::default(),
|
||||
/// );
|
||||
/// }
|
||||
/// ```
|
||||
/// will mean the given device (in this case the default) will be initialized to use Vulkan as the graphics API.
|
||||
/// It's also possible to use an existing wgpu device, by using `init_device`.
|
||||
///
|
||||
/// # Notes
|
||||
///
|
||||
/// This version of the wgpu backend uses [burn_fusion] to compile and optimize streams of tensor
|
||||
/// operations for improved performance.
|
||||
///
|
||||
/// You can disable the `fusion` feature flag to remove that functionality, which might be
|
||||
/// necessary on `wasm` for now.
|
||||
pub type Wgpu<F = f32, I = i32, B = u32> =
|
||||
burn_fusion::Fusion<CubeBackend<cubecl::wgpu::WgpuRuntime, F, I, B>>;
|
||||
|
||||
#[cfg(not(feature = "fusion"))]
|
||||
/// Tensor backend that uses the wgpu crate for executing GPU compute shaders.
|
||||
///
|
||||
/// This backend can target multiple graphics APIs, including:
|
||||
/// - [Vulkan] on Linux, Windows, and Android.
|
||||
/// - [OpenGL](crate::OpenGl) on Linux, Windows, and Android.
|
||||
/// - [DirectX 12](crate::Dx12) on Windows.
|
||||
/// - [Metal] on Apple hardware.
|
||||
/// - [WebGPU](crate::WebGpu) on supported browsers and `wasm` runtimes.
|
||||
///
|
||||
/// To configure the wgpu backend, eg. to select what graphics API to use or what memory strategy to use,
|
||||
/// you have to manually initialize the runtime. For example:
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// fn custom_init() {
|
||||
/// let device = Default::default();
|
||||
/// burn::backend::wgpu::init_setup::<burn::backend::wgpu::graphics::Vulkan>(
|
||||
/// &device,
|
||||
/// Default::default(),
|
||||
/// );
|
||||
/// }
|
||||
/// ```
|
||||
/// will mean the given device (in this case the default) will be initialized to use Vulkan as the graphics API.
|
||||
/// It's also possible to use an existing wgpu device, by using `init_device`.
|
||||
///
|
||||
/// # Notes
|
||||
///
|
||||
/// This version of the wgpu backend doesn't use [burn_fusion] to compile and optimize streams of tensor
|
||||
/// operations.
|
||||
///
|
||||
/// You can enable the `fusion` feature flag to add that functionality, which might improve
|
||||
/// performance.
|
||||
pub type Wgpu<F = f32, I = i32, B = u32> = CubeBackend<cubecl::wgpu::WgpuRuntime, F, I, B>;
|
||||
|
||||
#[cfg(feature = "vulkan")]
|
||||
/// Tensor backend that leverages the Vulkan graphics API to execute GPU compute shaders compiled to SPIR-V.
|
||||
pub type Vulkan<F = f32, I = i32, B = u8> = Wgpu<F, I, B>;
|
||||
|
||||
#[cfg(feature = "webgpu")]
|
||||
/// Tensor backend that uses the wgpu crate to execute GPU compute shaders written in WGSL.
|
||||
pub type WebGpu<F = f32, I = i32, B = u32> = Wgpu<F, I, B>;
|
||||
|
||||
#[cfg(feature = "metal")]
|
||||
/// Tensor backend that leverages the Metal graphics API to execute GPU compute shaders compiled to MSL.
|
||||
pub type Metal<F = f32, I = i32, B = u8> = Wgpu<F, I, B>;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use burn_backend::{Backend, DType, QTensorPrimitive};
|
||||
|
||||
#[test]
|
||||
fn should_support_dtypes() {
|
||||
type B = Wgpu;
|
||||
let device = Default::default();
|
||||
|
||||
assert!(B::supports_dtype(&device, DType::F32));
|
||||
assert!(B::supports_dtype(&device, DType::I64));
|
||||
assert!(B::supports_dtype(&device, DType::I32));
|
||||
assert!(B::supports_dtype(&device, DType::U64));
|
||||
assert!(B::supports_dtype(&device, DType::U32));
|
||||
assert!(B::supports_dtype(
|
||||
&device,
|
||||
DType::QFloat(CubeTensor::<WgpuRuntime>::default_scheme())
|
||||
));
|
||||
// Registered as supported type but we don't actually use it?
|
||||
assert!(B::supports_dtype(&device, DType::Bool));
|
||||
|
||||
#[cfg(feature = "vulkan")]
|
||||
{
|
||||
assert!(B::supports_dtype(&device, DType::F16));
|
||||
assert!(B::supports_dtype(&device, DType::I16));
|
||||
assert!(B::supports_dtype(&device, DType::I8));
|
||||
assert!(B::supports_dtype(&device, DType::U16));
|
||||
assert!(B::supports_dtype(&device, DType::U8));
|
||||
|
||||
assert!(!B::supports_dtype(&device, DType::F64));
|
||||
assert!(!B::supports_dtype(&device, DType::Flex32));
|
||||
// Not supported for any arithmetics, but buffer, conversion and possibly matmul (hw dependent)
|
||||
assert!(!B::supports_dtype(&device, DType::BF16));
|
||||
}
|
||||
|
||||
#[cfg(feature = "metal")]
|
||||
{
|
||||
assert!(B::supports_dtype(&device, DType::F16));
|
||||
assert!(B::supports_dtype(&device, DType::I16));
|
||||
assert!(B::supports_dtype(&device, DType::I8));
|
||||
assert!(B::supports_dtype(&device, DType::U16));
|
||||
assert!(B::supports_dtype(&device, DType::U8));
|
||||
|
||||
assert!(!B::supports_dtype(&device, DType::F64));
|
||||
assert!(!B::supports_dtype(&device, DType::BF16));
|
||||
assert!(!B::supports_dtype(&device, DType::Flex32));
|
||||
}
|
||||
|
||||
// On macOS without the `metal` feature, wgpu still uses Metal at runtime,
|
||||
// which doesn't support F64 or BF16.
|
||||
#[cfg(all(not(any(feature = "vulkan", feature = "metal")), target_os = "macos"))]
|
||||
{
|
||||
assert!(B::supports_dtype(&device, DType::Flex32));
|
||||
assert!(B::supports_dtype(&device, DType::F16));
|
||||
|
||||
assert!(!B::supports_dtype(&device, DType::F64));
|
||||
assert!(!B::supports_dtype(&device, DType::BF16));
|
||||
assert!(!B::supports_dtype(&device, DType::I16));
|
||||
assert!(!B::supports_dtype(&device, DType::I8));
|
||||
assert!(!B::supports_dtype(&device, DType::U16));
|
||||
assert!(!B::supports_dtype(&device, DType::U8));
|
||||
}
|
||||
|
||||
#[cfg(not(any(feature = "vulkan", feature = "metal", target_os = "macos")))]
|
||||
{
|
||||
assert!(B::supports_dtype(&device, DType::F64));
|
||||
assert!(B::supports_dtype(&device, DType::Flex32));
|
||||
assert!(B::supports_dtype(&device, DType::F16));
|
||||
|
||||
assert!(!B::supports_dtype(&device, DType::BF16));
|
||||
assert!(!B::supports_dtype(&device, DType::I16));
|
||||
assert!(!B::supports_dtype(&device, DType::I8));
|
||||
assert!(!B::supports_dtype(&device, DType::U16));
|
||||
assert!(!B::supports_dtype(&device, DType::U8));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user