pub struct WgpuContext {
pub device: Device,
pub queue: Queue,
pub adapter_info: AdapterInfo,
/* private fields */
}Expand description
Owns the wgpu device/queue and a cache of compiled compute pipelines.
Fields§
§device: Device§queue: Queue§adapter_info: AdapterInfoImplementations§
Source§impl WgpuContext
impl WgpuContext
Sourcepub fn new() -> Result<Arc<Self>>
pub fn new() -> Result<Arc<Self>>
Sync device creation — native only. On wasm use Self::new_async.
Sourcepub async fn new_async() -> Result<Arc<Self>>
pub async fn new_async() -> Result<Arc<Self>>
Async device creation (works on native and wasm32; roadmap v4, pitfall 14: the async form is primary, the sync API is the facade).
pub fn create_storage(&self, size_bytes: usize) -> Buffer
pub fn upload(&self, bytes: &[u8]) -> Buffer
Sourcepub fn readback(
&self,
buf: &Buffer,
offset_bytes: usize,
size_bytes: usize,
) -> Result<Vec<u8>>
pub fn readback( &self, buf: &Buffer, offset_bytes: usize, size_bytes: usize, ) -> Result<Vec<u8>>
Read size_bytes starting at offset_bytes back to the host.
Sync facade — native only (device.poll(Wait) cannot exist on wasm).
Sourcepub async fn readback_async(
&self,
buf: &Buffer,
offset_bytes: usize,
size_bytes: usize,
) -> Result<Vec<u8>>
pub async fn readback_async( &self, buf: &Buffer, offset_bytes: usize, size_bytes: usize, ) -> Result<Vec<u8>>
Async readback — the primary form; on wasm the browser event loop drives the mapping.
Sourcepub async fn readback_many_async(
&self,
regions: &[(&Buffer, usize, usize)],
) -> Result<Vec<Vec<u8>>>
pub async fn readback_many_async( &self, regions: &[(&Buffer, usize, usize)], ) -> Result<Vec<Vec<u8>>>
Read several regions back in one submit and one fence wait.
WgpuContext::readback_async costs a submit and a wait each, which
dominates when a single logical step wants several small tensors: the
attention probe reads n_layer + 1 per generated token, and one at a
time that cost more than the decode itself. Staged into one encoder
they cost one round trip regardless of how many there are.
Regions are returned in the order given.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for WgpuContext
impl !RefUnwindSafe for WgpuContext
impl !UnwindSafe for WgpuContext
impl Send for WgpuContext
impl Sync for WgpuContext
impl Unpin for WgpuContext
impl UnsafeUnpin for WgpuContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more