-
Notifications
You must be signed in to change notification settings - Fork 36
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
Refactor for wgpu v23 compatibility with an example of wgpu device sharing #211
Draft
AsherJingkongChen
wants to merge
18
commits into
tracel-ai:main
Choose a base branch
from
AsherJingkongChen:refactor/wgpu-v23
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a3c4e33
Refactor for wgpu v23 compatibility
AsherJingkongChen 7f689c0
Add example of using existing wgpu device
AsherJingkongChen 13dd59d
Format
AsherJingkongChen bfa5032
Patch changes for SPIR-V compiler
AsherJingkongChen dd04e6c
Make WgpuDevice::Existing unique
AsherJingkongChen e676ccf
Merge commit '1226222ad8be9ac1701d4b40b4c454ffa6d3ee20' into refactor…
AsherJingkongChen 3833348
Adjust namings and comments
AsherJingkongChen 567e9c3
Merge branch 'refactor/cubecl-wgpu/naming' into refactor/wgpu-v23
AsherJingkongChen c1203d7
Adjust example for wgpu runtime updates
AsherJingkongChen ddffbb6
Merge branch 'main' into refactor/wgpu-v23
AsherJingkongChen c8ff1e1
Update wgpu 23.0.0
AsherJingkongChen 038bed6
Fix doc links
AsherJingkongChen 57f21ab
Merge remote-tracking branch 'origin/main' into refactor/wgpu-v23
AsherJingkongChen c6ec950
Merge commit 'd85d503895cadf773bc25a65ce515aee15d17a33' into refactor…
AsherJingkongChen ba78b17
Add wgpu spirv required features
AsherJingkongChen e04d19e
Merge remote-tracking branch 'origin/main' into refactor/wgpu-v23
AsherJingkongChen 1f13590
Merge remote-tracking branch 'origin/main' into refactor/wgpu-v23
AsherJingkongChen 8636b60
Merge branch 'main' of https://github.com/tracel-ai/cubecl into refac…
AsherJingkongChen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = { version = "23.0.0", features = ["fragile-send-sync-non-atomic-wasm"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fn main() { | ||
#[cfg(feature = "wgpu")] | ||
{ | ||
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::<cubecl::wgpu::WgpuRuntime>(&device_cubecl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#[cfg(feature = "wgpu")] | ||
mod device_sharing_wgpu { | ||
use cubecl::wgpu::{WgpuDevice, WgpuSetup}; | ||
|
||
pub fn create_wgpu_setup_from_raw() -> WgpuSetup { | ||
cubecl::future::block_on(create_wgpu_setup_from_raw_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"); | ||
|
||
WgpuSetup { | ||
instance: instance.into(), | ||
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 use device_sharing_wgpu::*; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I am doing the equivalent change here.