Skip to content

Commit 108e74c

Browse files
Move callback queue lifetime handling to Rust
1 parent d3b67a2 commit 108e74c

4 files changed

Lines changed: 15 additions & 8 deletions

File tree

oneapi-rs-sys/include/event.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ enum class EventCommandStatus : std::uint8_t;
2020

2121
namespace sycl_shims::event {
2222
void wait(std::unique_ptr<Event> &);
23-
void register_callback(Event const &, rust::Box<Waker>);
23+
void register_callback(std::unique_ptr<Queue> &, Event const &, rust::Box<Waker>);
2424
EventCommandStatus get_command_execution_status(Event const &);
2525
std::unique_ptr<Event> clone(Event const &);
2626
} // namespace sycl_shims::event

oneapi-rs-sys/src/event-sys.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ pub mod ffi {
2222
#[namespace = "sycl_shims"]
2323
type Event = crate::types::ffi::Event;
2424

25+
#[namespace = "sycl_shims"]
26+
type Queue = crate::types::ffi::Queue;
27+
2528
fn wait(event: &mut UniquePtr<Event>);
26-
fn register_callback(event: &Event, waker: Box<Waker>);
29+
fn register_callback(queue: &mut UniquePtr<Queue>, event: &Event, waker: Box<Waker>);
2730
fn get_command_execution_status(event: &Event) -> EventCommandStatus;
2831
fn clone(event: &Event) -> UniquePtr<Event>;
2932
}

oneapi-rs-sys/src/event.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
using sycl::info::event_command_status;
1212

13+
namespace syclintel = sycl::ext::intel;
14+
1315
namespace sycl_shims::event {
1416
void wait(std::unique_ptr<Event> & event) {
1517
event->wait();
@@ -30,10 +32,10 @@ EventCommandStatus get_command_execution_status(Event const & event) {
3032
return EventCommandStatus::Unknown;
3133
}
3234
}
33-
void register_callback(Event const & event, rust::Box<Waker> waker) {
34-
sycl::queue().submit([waker = std::move(waker), event](sycl::handler& cgh) {
35+
void register_callback(std::unique_ptr<Queue> & queue, Event const & event, rust::Box<Waker> waker) {
36+
queue->submit([waker = std::move(waker), event](sycl::handler& cgh) {
3537
cgh.depends_on(event);
36-
cgh.host_task([&]() mutable { wake(waker); });
38+
cgh.host_task([&]() { wake(waker); });
3739
});
3840
}
3941
} // namespace sycl_shims::event

oneapi-rs/src/event.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use oneapi_rs_sys::event::ffi;
1212

1313
use pin_project::pin_project;
1414

15-
use crate::info::{EventCommandStatus, event::{CommandExecutionStatus, EventInfo}};
15+
use crate::{info::{EventCommandStatus, event::{CommandExecutionStatus, EventInfo}}, queue::Queue};
1616

1717
pub struct Event(pub(crate) cxx::UniquePtr<ffi::Event>);
1818

@@ -41,7 +41,8 @@ impl Clone for Event {
4141
#[pin_project]
4242
pub struct EventFuture {
4343
event: Event,
44-
set_callback: bool
44+
set_callback: bool,
45+
queue: Queue,
4546
}
4647

4748
impl Future for EventFuture {
@@ -56,7 +57,7 @@ impl Future for EventFuture {
5657
let this = self.project();
5758
*this.set_callback = true;
5859
let waker = Box::new(cx.waker().clone().into());
59-
ffi::register_callback(&this.event.0, waker);
60+
ffi::register_callback(&mut this.queue.0, &this.event.0, waker);
6061
}
6162
Poll::Pending
6263
}
@@ -69,6 +70,7 @@ impl IntoFuture for Event {
6970

7071
fn into_future(self) -> Self::IntoFuture {
7172
EventFuture {
73+
queue: Queue::new_immediate(),
7274
event: self,
7375
set_callback: false
7476
}

0 commit comments

Comments
 (0)