From a3c4e33576208e8ed90b533a96ee66a080b960a4 Mon Sep 17 00:00:00 2001 From: AsherJingkongChen <37398747+AsherJingkongChen@users.noreply.github.com> Date: Wed, 30 Oct 2024 05:25:50 +0800 Subject: [PATCH 01/11] Refactor for wgpu v23 compatibility * Change type of `entry_point` from `&str` to `Option<&str>` * Change enum type of `WgpuDevice::Existing` from `wgpu::Id` to `usize` --- crates/cubecl-wgpu/Cargo.toml | 2 +- crates/cubecl-wgpu/src/compiler/wgsl/compiler.rs | 2 +- crates/cubecl-wgpu/src/device.rs | 6 ++++-- crates/cubecl-wgpu/src/runtime.rs | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/cubecl-wgpu/Cargo.toml b/crates/cubecl-wgpu/Cargo.toml index e4abd3fc..5cb331ca 100644 --- a/crates/cubecl-wgpu/Cargo.toml +++ b/crates/cubecl-wgpu/Cargo.toml @@ -35,7 +35,7 @@ ash = { version = "0.38", optional = true } cubecl-spirv = { path = "../cubecl-spirv", version = "0.4.0", optional = true } bytemuck = { workspace = true } -wgpu = { version = "22.0.0", features = ["fragile-send-sync-non-atomic-wasm"] } +wgpu = { git = "https://github.com/erichdongubler-mozilla/wgpu", branch = "v23", features = ["fragile-send-sync-non-atomic-wasm"] } async-channel = { workspace = true } derive-new = { workspace = true } diff --git a/crates/cubecl-wgpu/src/compiler/wgsl/compiler.rs b/crates/cubecl-wgpu/src/compiler/wgsl/compiler.rs index 976e87d4..d064c741 100644 --- a/crates/cubecl-wgpu/src/compiler/wgsl/compiler.rs +++ b/crates/cubecl-wgpu/src/compiler/wgsl/compiler.rs @@ -94,7 +94,7 @@ impl WgpuCompiler for WgslCompiler { label: None, layout: None, module: &module, - entry_point: "main", + entry_point: Some("main"), compilation_options: wgpu::PipelineCompilationOptions { zero_initialize_workgroup_memory: false, ..Default::default() diff --git a/crates/cubecl-wgpu/src/device.rs b/crates/cubecl-wgpu/src/device.rs index e09645e7..d5b75a20 100644 --- a/crates/cubecl-wgpu/src/device.rs +++ b/crates/cubecl-wgpu/src/device.rs @@ -45,8 +45,10 @@ pub enum WgpuDevice { /// Use an externally created, existing, wgpu setup. This is helpful when using CubeCL in conjunction /// with some existing wgpu setup (eg. egui or bevy), as resources can be transferred in & out of CubeCL. /// - /// The device is indexed by the global wgpu [adapter ID](wgpu::Device::global_id). - Existing(wgpu::Id), + /// # Notes + /// + /// The device is the address of the [wgpu::Device]. + Existing(usize), } impl Default for WgpuDevice { diff --git a/crates/cubecl-wgpu/src/runtime.rs b/crates/cubecl-wgpu/src/runtime.rs index cbafc566..56b01a41 100644 --- a/crates/cubecl-wgpu/src/runtime.rs +++ b/crates/cubecl-wgpu/src/runtime.rs @@ -1,4 +1,4 @@ -use std::marker::PhantomData; +use std::{marker::PhantomData, ptr}; use crate::{ compiler::{base::WgpuCompiler, wgsl::WgslCompiler}, @@ -96,7 +96,7 @@ pub fn init_existing_device( queue: Arc, options: RuntimeOptions, ) -> WgpuDevice { - let device_id = WgpuDevice::Existing(device.as_ref().global_id()); + let device_id = WgpuDevice::Existing(ptr::from_ref(device.as_ref()) as usize); let client = create_client(adapter, device, queue, options); RUNTIME.register(&device_id, client); device_id From 7f689c0c02ac7913a044e3f9b1829790667e47fd Mon Sep 17 00:00:00 2001 From: AsherJingkongChen <37398747+AsherJingkongChen@users.noreply.github.com> Date: Wed, 30 Oct 2024 05:25:50 +0800 Subject: [PATCH 02/11] Add example of using existing wgpu device --- examples/device_sharing/Cargo.toml | 19 +++++++++ .../device_sharing/examples/device_sharing.rs | 13 ++++++ examples/device_sharing/src/lib.rs | 42 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 examples/device_sharing/Cargo.toml create mode 100644 examples/device_sharing/examples/device_sharing.rs create mode 100644 examples/device_sharing/src/lib.rs diff --git a/examples/device_sharing/Cargo.toml b/examples/device_sharing/Cargo.toml new file mode 100644 index 00000000..afc654e8 --- /dev/null +++ b/examples/device_sharing/Cargo.toml @@ -0,0 +1,19 @@ +[package] +authors = [] +edition.workspace = true +license.workspace = true +name = "device_sharing" +publish = false +version.workspace = true + +[features] +default = [] +wgpu = ["cubecl/wgpu"] +cuda = ["cubecl/cuda"] + +[dependencies] +cubecl = { path = "../../crates/cubecl", version = "0.4.0" } +half = { workspace = true } + +sum_things = { path = "../sum_things" } +wgpu = { git = "https://github.com/erichdongubler-mozilla/wgpu", branch = "v23", features = ["fragile-send-sync-non-atomic-wasm"] } diff --git a/examples/device_sharing/examples/device_sharing.rs b/examples/device_sharing/examples/device_sharing.rs new file mode 100644 index 00000000..f0b03df8 --- /dev/null +++ b/examples/device_sharing/examples/device_sharing.rs @@ -0,0 +1,13 @@ +fn main() { + #[cfg(feature = "wgpu")] { + let context_wgpu = device_sharing::create_wgpu_context().expect("No wgpu context found"); + let device_cubecl_wgpu = cubecl::wgpu::init_existing_device( + context_wgpu.adapter, + context_wgpu.device, + context_wgpu.queue, + Default::default(), + ); + device_sharing::assert_device_cubecl_wgpu_is_existing(&device_cubecl_wgpu); + sum_things::launch::(&device_cubecl_wgpu); + } +} diff --git a/examples/device_sharing/src/lib.rs b/examples/device_sharing/src/lib.rs new file mode 100644 index 00000000..9cd58be5 --- /dev/null +++ b/examples/device_sharing/src/lib.rs @@ -0,0 +1,42 @@ +use std::sync::Arc; + +pub struct WgpuContext { + pub adapter: Arc, + pub device: Arc, + pub queue: Arc, +} + +pub fn create_wgpu_context() -> Option { + cubecl::future::block_on(create_wgpu_context_async()) +} + +pub async fn create_wgpu_context_async() -> Option { + let instance = wgpu::Instance::default(); + let adapter = instance.request_adapter(&Default::default()).await?; + let (device, queue) = adapter + .request_device( + &wgpu::DeviceDescriptor { + label: None, + required_features: adapter.features(), + required_limits: adapter.limits(), + memory_hints: wgpu::MemoryHints::MemoryUsage, + }, + None, + ) + .await + .ok()?; + + Some(WgpuContext { + adapter: adapter.into(), + device: device.into(), + queue: queue.into(), + }) +} + +#[cfg(feature = "wgpu")] +pub fn assert_device_cubecl_wgpu_is_existing(device: &cubecl::wgpu::WgpuDevice) { + assert!( + matches!(device, cubecl::wgpu::WgpuDevice::Existing(_)), + "device should be WgpuDevice::Existing" + ); +} From 13dd59d405411ddf9aa03f2c2599ca02c111a91a Mon Sep 17 00:00:00 2001 From: AsherJingkongChen <37398747+AsherJingkongChen@users.noreply.github.com> Date: Wed, 30 Oct 2024 05:25:50 +0800 Subject: [PATCH 03/11] Format --- examples/device_sharing/examples/device_sharing.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/device_sharing/examples/device_sharing.rs b/examples/device_sharing/examples/device_sharing.rs index f0b03df8..fc611bbb 100644 --- a/examples/device_sharing/examples/device_sharing.rs +++ b/examples/device_sharing/examples/device_sharing.rs @@ -1,5 +1,6 @@ fn main() { - #[cfg(feature = "wgpu")] { + #[cfg(feature = "wgpu")] + { let context_wgpu = device_sharing::create_wgpu_context().expect("No wgpu context found"); let device_cubecl_wgpu = cubecl::wgpu::init_existing_device( context_wgpu.adapter, From bfa5032562d222657706a023ce2283df6aba3274 Mon Sep 17 00:00:00 2001 From: AsherJingkongChen <37398747+AsherJingkongChen@users.noreply.github.com> Date: Wed, 30 Oct 2024 05:25:50 +0800 Subject: [PATCH 04/11] Patch changes for SPIR-V compiler --- crates/cubecl-wgpu/src/compiler/spirv.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/cubecl-wgpu/src/compiler/spirv.rs b/crates/cubecl-wgpu/src/compiler/spirv.rs index 339f5bd8..be386a8f 100644 --- a/crates/cubecl-wgpu/src/compiler/spirv.rs +++ b/crates/cubecl-wgpu/src/compiler/spirv.rs @@ -95,7 +95,7 @@ impl WgpuCompiler for SpirvCompiler { label: None, layout: Some(&layout), module: &module, - entry_point: "main", + entry_point: Some("main"), compilation_options: wgpu::PipelineCompilationOptions { zero_initialize_workgroup_memory: false, ..Default::default() @@ -347,13 +347,30 @@ impl Runtime for WgpuRuntime { } } +/// Initializes an existing device and assigns a unique `device_id` for internal tracking. +/// +/// # Note +/// +/// Please **NOT** to initialize the **same** device more than once. +/// +/// This function generates a new, globally unique ID for the device every time it is called, +/// even if called on the same device multiple times. pub fn init_existing_device( adapter: Arc, device: Arc, queue: Arc, options: RuntimeOptions, ) -> WgpuDevice { - let device_id = WgpuDevice::Existing(device.as_ref().global_id()); + use core::sync::atomic::{AtomicU32, Ordering}; + + static COUNTER: AtomicU32 = AtomicU32::new(0); + + let device_id = COUNTER.fetch_add(1, Ordering::Relaxed); + if device_id == u32::MAX { + core::panic!("Memory ID overflowed"); + } + + let device_id = WgpuDevice::Existing(device_id); let client = create_client(adapter, device, queue, options); RUNTIME.register(&device_id, client); device_id From dd04e6c2afe400564b7b852fddb973535945b887 Mon Sep 17 00:00:00 2001 From: AsherJingkongChen <37398747+AsherJingkongChen@users.noreply.github.com> Date: Wed, 30 Oct 2024 05:25:50 +0800 Subject: [PATCH 05/11] Make WgpuDevice::Existing unique * Added auto-increment counter in init_existing_device * Added comments of usage --- crates/cubecl-wgpu/src/compiler/spirv.rs | 2 +- crates/cubecl-wgpu/src/device.rs | 4 ++-- crates/cubecl-wgpu/src/runtime.rs | 21 +++++++++++++++++-- .../device_sharing/examples/device_sharing.rs | 8 +++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/crates/cubecl-wgpu/src/compiler/spirv.rs b/crates/cubecl-wgpu/src/compiler/spirv.rs index be386a8f..49720d70 100644 --- a/crates/cubecl-wgpu/src/compiler/spirv.rs +++ b/crates/cubecl-wgpu/src/compiler/spirv.rs @@ -351,7 +351,7 @@ impl Runtime for WgpuRuntime { /// /// # Note /// -/// Please **NOT** to initialize the **same** device more than once. +/// Please **do not** to initialize the **same** device more than once. /// /// This function generates a new, globally unique ID for the device every time it is called, /// even if called on the same device multiple times. diff --git a/crates/cubecl-wgpu/src/device.rs b/crates/cubecl-wgpu/src/device.rs index d5b75a20..15d29545 100644 --- a/crates/cubecl-wgpu/src/device.rs +++ b/crates/cubecl-wgpu/src/device.rs @@ -47,8 +47,8 @@ pub enum WgpuDevice { /// /// # Notes /// - /// The device is the address of the [wgpu::Device]. - Existing(usize), + /// This can be initialized with [init_existing_device](crate::runtime::init_existing_device). + Existing(u32), } impl Default for WgpuDevice { diff --git a/crates/cubecl-wgpu/src/runtime.rs b/crates/cubecl-wgpu/src/runtime.rs index 56b01a41..f70ffcd6 100644 --- a/crates/cubecl-wgpu/src/runtime.rs +++ b/crates/cubecl-wgpu/src/runtime.rs @@ -1,4 +1,4 @@ -use std::{marker::PhantomData, ptr}; +use std::marker::PhantomData; use crate::{ compiler::{base::WgpuCompiler, wgsl::WgslCompiler}, @@ -90,13 +90,30 @@ impl Default for RuntimeOptions { } } +/// Initializes an existing device and assigns a unique `device_id` for internal tracking. +/// +/// # Note +/// +/// Please **do not** to initialize the **same** device more than once. +/// +/// This function generates a new, globally unique ID for the device every time it is called, +/// even if called on the same device multiple times. pub fn init_existing_device( adapter: Arc, device: Arc, queue: Arc, options: RuntimeOptions, ) -> WgpuDevice { - let device_id = WgpuDevice::Existing(ptr::from_ref(device.as_ref()) as usize); + use core::sync::atomic::{AtomicU32, Ordering}; + + static COUNTER: AtomicU32 = AtomicU32::new(0); + + let device_id = COUNTER.fetch_add(1, Ordering::Relaxed); + if device_id == u32::MAX { + core::panic!("Memory ID overflowed"); + } + + let device_id = WgpuDevice::Existing(device_id); let client = create_client(adapter, device, queue, options); RUNTIME.register(&device_id, client); device_id diff --git a/examples/device_sharing/examples/device_sharing.rs b/examples/device_sharing/examples/device_sharing.rs index fc611bbb..dec87c45 100644 --- a/examples/device_sharing/examples/device_sharing.rs +++ b/examples/device_sharing/examples/device_sharing.rs @@ -10,5 +10,13 @@ fn main() { ); device_sharing::assert_device_cubecl_wgpu_is_existing(&device_cubecl_wgpu); sum_things::launch::(&device_cubecl_wgpu); + + // // Please do not initialize the same device more than once. + // let device_cubecl_wgpu_2 = cubecl::wgpu::init_existing_device( + // context_wgpu.adapter, + // context_wgpu.device, + // context_wgpu.queue, + // Default::default(), + // ); } } From 3833348b4e1f76d751ece47489231e27d6b43f43 Mon Sep 17 00:00:00 2001 From: AsherJingkongChen <37398747+AsherJingkongChen@users.noreply.github.com> Date: Wed, 30 Oct 2024 06:39:54 +0800 Subject: [PATCH 06/11] Adjust namings and comments --- crates/cubecl-wgpu/src/runtime.rs | 34 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/crates/cubecl-wgpu/src/runtime.rs b/crates/cubecl-wgpu/src/runtime.rs index 4088af10..7634e0d1 100644 --- a/crates/cubecl-wgpu/src/runtime.rs +++ b/crates/cubecl-wgpu/src/runtime.rs @@ -82,45 +82,43 @@ impl Default for RuntimeOptions { } } -/// A complete setup used to run wgpu on a GPU. +/// A complete setup used to run wgpu. /// -/// These can either be created with [`ini -#[derive(Clone)] +/// These can either be created with [`init_setup`] or [`init_setup_async`]. +#[derive(Clone, Debug)] pub struct WgpuSetup { /// The underlying wgpu instance. pub instance: Arc, - /// The chose 'adapter'. This corresponds to a physical device. + /// The selected 'adapter'. This corresponds to a physical device. pub adapter: Arc, - /// The wpgu device Burn will use. Nb: There can only be one device per adapter. + /// The wgpu device Burn will use. Nb: There can only be one device per adapter. pub device: Arc, - /// The queue Burn commands will be submittd to. + /// The queue Burn commands will be submitted to. pub queue: Arc, } -/// Create a `WgpuDevice` on an existing `WgpuSetup`. Useful when you want to share -/// a device between CubeCL and other wgpu libraries. -pub fn init_device_on_setup(setup: WgpuSetup, options: RuntimeOptions) -> WgpuDevice { +/// Create a [`WgpuDevice`] on an existing [`WgpuSetup`]. +/// Useful when you want to share a device between CubeCL and other wgpu-dependent libraries. +pub fn init_device(setup: WgpuSetup, options: RuntimeOptions) -> WgpuDevice { let device_id = WgpuDevice::Existing(setup.device.as_ref().global_id()); let client = create_client_on_setup(setup, options); RUNTIME.register(&device_id, client); device_id } -/// Like [`create_setup`], but synchronous. -/// On wasm, it is necessary to use [`init_async`] instead. -pub fn init_device_async( - device: &WgpuDevice, - options: RuntimeOptions, -) -> WgpuSetup { +/// Like [`init_setup_async`], but synchronous. +/// On wasm, it is necessary to use [`init_setup_async`] instead. +pub fn init_setup(device: &WgpuDevice, options: RuntimeOptions) -> WgpuSetup { #[cfg(target_family = "wasm")] panic!("Creating a wgpu setup synchronously is unsupported on wasm. Use init_async instead"); - future::block_on(init_device::(device, options)) + future::block_on(init_setup_async::(device, options)) } -/// Initialize a client on the given device with the given options. This function is useful to configure the runtime options +/// Initialize a client on the given device with the given options. +/// This function is useful to configure the runtime options /// or to pick a different graphics API. -pub async fn init_device( +pub async fn init_setup_async( device: &WgpuDevice, options: RuntimeOptions, ) -> WgpuSetup { From c1203d7945494f652d9ec0a313f9aa3a30a0cc64 Mon Sep 17 00:00:00 2001 From: AsherJingkongChen <37398747+AsherJingkongChen@users.noreply.github.com> Date: Wed, 30 Oct 2024 07:31:05 +0800 Subject: [PATCH 07/11] Adjust example for wgpu runtime updates --- .../device_sharing/examples/device_sharing.rs | 21 +----- examples/device_sharing/src/lib.rs | 73 ++++++++++--------- 2 files changed, 42 insertions(+), 52 deletions(-) diff --git a/examples/device_sharing/examples/device_sharing.rs b/examples/device_sharing/examples/device_sharing.rs index dec87c45..3b76446c 100644 --- a/examples/device_sharing/examples/device_sharing.rs +++ b/examples/device_sharing/examples/device_sharing.rs @@ -1,22 +1,9 @@ fn main() { #[cfg(feature = "wgpu")] { - let context_wgpu = device_sharing::create_wgpu_context().expect("No wgpu context found"); - let device_cubecl_wgpu = cubecl::wgpu::init_existing_device( - context_wgpu.adapter, - context_wgpu.device, - context_wgpu.queue, - Default::default(), - ); - device_sharing::assert_device_cubecl_wgpu_is_existing(&device_cubecl_wgpu); - sum_things::launch::(&device_cubecl_wgpu); - - // // Please do not initialize the same device more than once. - // let device_cubecl_wgpu_2 = cubecl::wgpu::init_existing_device( - // context_wgpu.adapter, - // context_wgpu.device, - // context_wgpu.queue, - // Default::default(), - // ); + let setup_shared = device_sharing::create_wgpu_setup_from_raw(); + let device_cubecl = cubecl::wgpu::init_device(setup_shared.clone(), Default::default()); + device_sharing::assert_wgpu_device_existing(&device_cubecl); + sum_things::launch::(&device_cubecl); } } diff --git a/examples/device_sharing/src/lib.rs b/examples/device_sharing/src/lib.rs index 9cd58be5..f789df7b 100644 --- a/examples/device_sharing/src/lib.rs +++ b/examples/device_sharing/src/lib.rs @@ -1,42 +1,45 @@ -use std::sync::Arc; +#[cfg(feature = "wgpu")] +mod device_sharing_wgpu { + use cubecl::wgpu::{WgpuDevice, WgpuSetup}; -pub struct WgpuContext { - pub adapter: Arc, - pub device: Arc, - pub queue: Arc, -} + pub fn create_wgpu_setup_from_raw() -> WgpuSetup { + cubecl::future::block_on(create_wgpu_setup_from_raw_async()) + } -pub fn create_wgpu_context() -> Option { - cubecl::future::block_on(create_wgpu_context_async()) -} + pub async fn create_wgpu_setup_from_raw_async() -> WgpuSetup { + let instance = wgpu::Instance::default(); + let adapter = instance + .request_adapter(&Default::default()) + .await + .expect("Failed to create wgpu adapter from instance"); + let (device, queue) = adapter + .request_device( + &wgpu::DeviceDescriptor { + label: Some("Raw"), + required_features: adapter.features(), + required_limits: adapter.limits(), + memory_hints: wgpu::MemoryHints::MemoryUsage, + }, + None, + ) + .await + .expect("Failed to create wgpu device from adapter"); -pub async fn create_wgpu_context_async() -> Option { - let instance = wgpu::Instance::default(); - let adapter = instance.request_adapter(&Default::default()).await?; - let (device, queue) = adapter - .request_device( - &wgpu::DeviceDescriptor { - label: None, - required_features: adapter.features(), - required_limits: adapter.limits(), - memory_hints: wgpu::MemoryHints::MemoryUsage, - }, - None, - ) - .await - .ok()?; + WgpuSetup { + instance: instance.into(), + adapter: adapter.into(), + device: device.into(), + queue: queue.into(), + } + } - Some(WgpuContext { - adapter: adapter.into(), - device: device.into(), - queue: queue.into(), - }) + pub fn assert_wgpu_device_existing(device: &WgpuDevice) { + assert!( + matches!(device, cubecl::wgpu::WgpuDevice::Existing(_)), + "device should be WgpuDevice::Existing" + ); + } } #[cfg(feature = "wgpu")] -pub fn assert_device_cubecl_wgpu_is_existing(device: &cubecl::wgpu::WgpuDevice) { - assert!( - matches!(device, cubecl::wgpu::WgpuDevice::Existing(_)), - "device should be WgpuDevice::Existing" - ); -} +pub use device_sharing_wgpu::*; From c8ff1e188687d1db04d0d12eb604241745952f38 Mon Sep 17 00:00:00 2001 From: AsherJingkongChen <37398747+AsherJingkongChen@users.noreply.github.com> Date: Thu, 31 Oct 2024 02:40:13 +0800 Subject: [PATCH 08/11] Update wgpu 23.0.0 --- crates/cubecl-wgpu/Cargo.toml | 2 +- examples/device_sharing/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/cubecl-wgpu/Cargo.toml b/crates/cubecl-wgpu/Cargo.toml index 5cb331ca..8b73bbd9 100644 --- a/crates/cubecl-wgpu/Cargo.toml +++ b/crates/cubecl-wgpu/Cargo.toml @@ -35,7 +35,7 @@ ash = { version = "0.38", optional = true } cubecl-spirv = { path = "../cubecl-spirv", version = "0.4.0", optional = true } bytemuck = { workspace = true } -wgpu = { git = "https://github.com/erichdongubler-mozilla/wgpu", branch = "v23", features = ["fragile-send-sync-non-atomic-wasm"] } +wgpu = { version = "23.0.0", features = ["fragile-send-sync-non-atomic-wasm"] } async-channel = { workspace = true } derive-new = { workspace = true } diff --git a/examples/device_sharing/Cargo.toml b/examples/device_sharing/Cargo.toml index afc654e8..fb8c135c 100644 --- a/examples/device_sharing/Cargo.toml +++ b/examples/device_sharing/Cargo.toml @@ -16,4 +16,4 @@ cubecl = { path = "../../crates/cubecl", version = "0.4.0" } half = { workspace = true } sum_things = { path = "../sum_things" } -wgpu = { git = "https://github.com/erichdongubler-mozilla/wgpu", branch = "v23", features = ["fragile-send-sync-non-atomic-wasm"] } +wgpu = { version = "23.0.0", features = ["fragile-send-sync-non-atomic-wasm"] } From 038bed685479b4530c04bd71f432bad7581ea176 Mon Sep 17 00:00:00 2001 From: AsherJingkongChen <37398747+AsherJingkongChen@users.noreply.github.com> Date: Fri, 1 Nov 2024 06:07:37 +0800 Subject: [PATCH 09/11] Fix doc links --- crates/cubecl-wgpu/src/device.rs | 2 +- crates/cubecl-wgpu/src/runtime.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/cubecl-wgpu/src/device.rs b/crates/cubecl-wgpu/src/device.rs index 0896b952..b268f9a2 100644 --- a/crates/cubecl-wgpu/src/device.rs +++ b/crates/cubecl-wgpu/src/device.rs @@ -43,7 +43,7 @@ pub enum WgpuDevice { /// /// # Notes /// - /// This can be initialized with [init_existing_device](crate::runtime::init_existing_device). + /// This can be initialized with [`init_device`](crate::runtime::init_device). Existing(u32), } diff --git a/crates/cubecl-wgpu/src/runtime.rs b/crates/cubecl-wgpu/src/runtime.rs index 7e5f850e..82f30672 100644 --- a/crates/cubecl-wgpu/src/runtime.rs +++ b/crates/cubecl-wgpu/src/runtime.rs @@ -102,7 +102,7 @@ pub struct WgpuSetup { /// /// # Note /// -/// Please **do not** to initialize the **same** device more than once. +/// Please **do not** to call on the same [`setup`](WgpuSetup) more than once. /// /// This function generates a new, globally unique ID for the device every time it is called, /// even if called on the same device multiple times. From ba78b17f15b97fd8a316b60ed9631f3dd1e3be9e Mon Sep 17 00:00:00 2001 From: AsherJingkongChen <37398747+AsherJingkongChen@users.noreply.github.com> Date: Wed, 13 Nov 2024 02:44:41 +0800 Subject: [PATCH 10/11] Add wgpu spirv required features * Also updated an argument, see https://docs.rs/wgpu-hal/latest/wgpu_hal/vulkan/struct.Adapter.html#method.device_from_raw --- crates/cubecl-wgpu/Cargo.toml | 5 ++++- crates/cubecl-wgpu/src/compiler/spirv.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/cubecl-wgpu/Cargo.toml b/crates/cubecl-wgpu/Cargo.toml index 9f6329d5..1cab24a2 100644 --- a/crates/cubecl-wgpu/Cargo.toml +++ b/crates/cubecl-wgpu/Cargo.toml @@ -15,9 +15,10 @@ default = [ "cubecl-runtime/default", "cubecl-common/default", "cubecl-core/default", + "spirv", ] exclusive-memory-only = ["cubecl-runtime/exclusive-memory-only"] -spirv = ["cubecl-spirv", "ash"] +spirv = ["cubecl-spirv", "ash", "wgpu/spirv", "wgpu-core/vulkan"] std = ["cubecl-runtime/std", "cubecl-common/std", "cubecl-core/std"] spirv-dump = ["sanitize-filename"] @@ -36,6 +37,8 @@ cubecl-spirv = { path = "../cubecl-spirv", version = "0.4.0", optional = true } bytemuck = { workspace = true } wgpu = { version = "23.0.0", features = ["fragile-send-sync-non-atomic-wasm"] } +wgpu-core = { version = "23.0.0" } +wgpu-hal = { version = "23.0.0" } async-channel = { workspace = true } derive-new = { workspace = true } diff --git a/crates/cubecl-wgpu/src/compiler/spirv.rs b/crates/cubecl-wgpu/src/compiler/spirv.rs index 38a648c1..1135978b 100644 --- a/crates/cubecl-wgpu/src/compiler/spirv.rs +++ b/crates/cubecl-wgpu/src/compiler/spirv.rs @@ -284,7 +284,7 @@ fn request_device( adapter .device_from_raw( vk_device, - true, + None, &device_extensions, features, &wgpu::MemoryHints::MemoryUsage, From c091068c8404d2c73897ef0097cb6b4feed2962b Mon Sep 17 00:00:00 2001 From: AsherJingkongChen <37398747+AsherJingkongChen@users.noreply.github.com> Date: Thu, 5 Dec 2024 06:12:03 +0800 Subject: [PATCH 11/11] Adjust: Attempt to remove unused feature flags --- crates/cubecl-wgpu/Cargo.toml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/cubecl-wgpu/Cargo.toml b/crates/cubecl-wgpu/Cargo.toml index 26bff7ba..b32cde01 100644 --- a/crates/cubecl-wgpu/Cargo.toml +++ b/crates/cubecl-wgpu/Cargo.toml @@ -15,10 +15,9 @@ default = [ "cubecl-runtime/default", "cubecl-common/default", "cubecl-core/default", - "spirv", ] exclusive-memory-only = ["cubecl-runtime/exclusive-memory-only"] -spirv = ["cubecl-spirv", "ash", "wgpu/spirv", "wgpu-core/vulkan"] +spirv = ["cubecl-spirv", "ash"] std = ["cubecl-runtime/std", "cubecl-common/std", "cubecl-core/std"] spirv-dump = ["sanitize-filename"] @@ -52,8 +51,6 @@ wgpu = { version = "23.0.0", features = ["fragile-send-sync-non-atomic-wasm"] } # To install MoltenVK, install the VulkanSDK: https://vulkan.lunarg.com/sdk/home#mac [target.'cfg(target_os = "macos")'.dependencies] wgpu = { version = "23.0.0", features = ["vulkan-portability", "fragile-send-sync-non-atomic-wasm"] } -wgpu-core = { version = "23.0.0" } -wgpu-hal = { version = "23.0.0" } [dev-dependencies] cubecl-core = { path = "../cubecl-core", version = "0.4.0", features = [