Skip to content

Commit 3818c67

Browse files
Document new Buffer methods
1 parent 5fb435f commit 3818c67

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

oneapi-rs/src/buffer.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ impl<T, A: UsmAlloc> Drop for Buffer<T, A> {
8181
}
8282
}
8383

84-
pub struct BufferInProgress<T, A: UsmAlloc> {
84+
/// A [`Buffer`] whose initialization has been enqueued. You need to wait/await it.
85+
pub struct EnqueuedBuffer<T, A: UsmAlloc> {
8586
buffer: Buffer<T, A>,
8687
event: Event
8788
}
8889

89-
impl<T, A: UsmAlloc> BufferInProgress<T, A> {
90+
impl<T, A: UsmAlloc> EnqueuedBuffer<T, A> {
9091
pub(crate) fn new(buffer: Buffer<T, A>, event: Event) -> Self {
9192
Self {
9293
buffer,
@@ -95,14 +96,16 @@ impl<T, A: UsmAlloc> BufferInProgress<T, A> {
9596
}
9697
}
9798

98-
impl<T, A: UsmAlloc> BufferInProgress<T, A> {
99+
impl<T, A: UsmAlloc> EnqueuedBuffer<T, A> {
100+
/// Waits for [`Buffer`] initialization to finish.
99101
pub fn wait(mut self) -> Buffer<T, A> {
100102
self.event.wait();
101103
self.buffer
102104
}
103105
}
104106

105107
#[pin_project]
108+
/// A [`Future`] which represents a pending [`Buffer`] allocation.
106109
pub struct BufferFuture<T, A: UsmAlloc> {
107110
buffer: Option<Buffer<T, A>>,
108111
#[pin]
@@ -117,7 +120,7 @@ impl<T, A: UsmAlloc> Future for BufferFuture<T, A> {
117120
}
118121
}
119122

120-
impl<T, A: UsmAlloc> IntoFuture for BufferInProgress<T, A> {
123+
impl<T, A: UsmAlloc> IntoFuture for EnqueuedBuffer<T, A> {
121124
type Output = Buffer<T, A>;
122125
type IntoFuture = BufferFuture<T, A>;
123126

oneapi-rs/src/queue.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use bytemuck::Pod;
1010
use oneapi_rs_sys::{queue::ffi, types::ffi::EventPtr};
1111

12-
use crate::{buffer::{Buffer, BufferInProgress}, device::Device, event::Event, usm::{HostAllocator, SharedAllocator, UsmAlloc, UsmAllocator}};
12+
use crate::{buffer::{Buffer, EnqueuedBuffer}, device::Device, event::Event, usm::{HostAllocator, SharedAllocator, UsmAlloc, UsmAllocator}};
1313

1414
/// The `Queue` connects a host program to a single device. Programs submit tasks to a device via the
1515
/// `Queue` and may monitor the `Queue` for completion. A program initiates the task by submitting
@@ -28,20 +28,20 @@ impl Queue {
2828
}
2929

3030
/// Allocates zeroed memory and creates a host-side [`Buffer`] that can store an array of T.
31-
pub fn alloc_host<T: Pod>(&mut self, len: usize) -> BufferInProgress<T, UsmAllocator<HostAllocator>> {
31+
pub fn alloc_host<T: Pod>(&mut self, len: usize) -> EnqueuedBuffer<T, UsmAllocator<HostAllocator>> {
3232
unsafe {
3333
let mut buffer = self.alloc_uninit_host(len);
3434
let event = self.memset(&mut buffer, 0);
35-
BufferInProgress::new(buffer, event)
35+
EnqueuedBuffer::new(buffer, event)
3636
}
3737
}
3838

3939
/// Allocates zeroed memory and creates a shared [`Buffer`] that can store an array of T.
40-
pub fn alloc_shared<T: Pod>(&mut self, len: usize) -> BufferInProgress<T, UsmAllocator<SharedAllocator>> {
40+
pub fn alloc_shared<T: Pod>(&mut self, len: usize) -> EnqueuedBuffer<T, UsmAllocator<SharedAllocator>> {
4141
unsafe {
4242
let mut buffer = self.alloc_uninit_shared(len);
4343
let event = self.memset(&mut buffer, 0);
44-
BufferInProgress::new(buffer, event)
44+
EnqueuedBuffer::new(buffer, event)
4545
}
4646
}
4747

0 commit comments

Comments
 (0)