aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--level_zero/src/ze.rs5
-rw-r--r--zluda/src/impl/mod.rs14
-rw-r--r--zluda/src/impl/stream.rs27
3 files changed, 28 insertions, 18 deletions
diff --git a/level_zero/src/ze.rs b/level_zero/src/ze.rs
index 30146a2..27a61c8 100644
--- a/level_zero/src/ze.rs
+++ b/level_zero/src/ze.rs
@@ -1122,6 +1122,11 @@ impl<'a> Event<'a> {
Ok(unsafe { Self::from_ffi(result) })
}
+ pub fn host_synchronize(&self, timeout_ns: u64) -> Result<()> {
+ check!{ sys::zeEventHostSynchronize(self.as_ffi(), timeout_ns) };
+ Ok(())
+ }
+
pub fn is_ready(&self) -> Result<bool> {
let status = unsafe { sys::zeEventQueryStatus(self.as_ffi()) };
match status {
diff --git a/zluda/src/impl/mod.rs b/zluda/src/impl/mod.rs
index f12e964..fc8fbee 100644
--- a/zluda/src/impl/mod.rs
+++ b/zluda/src/impl/mod.rs
@@ -275,23 +275,25 @@ impl GlobalState {
fn lock_enqueue(
stream: *mut stream::Stream,
- f: impl FnOnce(&l0::CommandList, &l0::Event<'static>, &[&l0::Event<'static>]) -> Result<(), CUresult>,
+ f: impl FnOnce(
+ &l0::CommandList,
+ &l0::Event<'static>,
+ &[&l0::Event<'static>],
+ ) -> Result<(), CUresult>,
) -> Result<(), CUresult> {
Self::lock_stream(stream, |stream_data| {
let l0_dev = unsafe { (*(*stream_data.context).device).base };
let l0_ctx = unsafe { &mut (*(*stream_data.context).device).l0_context };
let event_pool = unsafe { &mut (*(*stream_data.context).device).event_pool };
- let cmd_list = unsafe { mem::transmute(stream_data.command_list()?) };
+ let cmd_list = unsafe { transmute_lifetime(&stream_data.cmd_list) };
stream_data
- .process_finished_events(&mut |(_, marker)| event_pool.mark_as_free(marker))?;
+ .drop_finished_events(&mut |(_, marker)| event_pool.mark_as_free(marker))?;
let prev_event = stream_data.get_last_event();
let prev_event_array = prev_event.map(|e| [e]);
let empty = [];
let prev_event_slice = prev_event_array.as_ref().map_or(&empty[..], |arr| &arr[..]);
let (new_event, new_marker) = event_pool.get(l0_dev, l0_ctx)?;
- f(&cmd_list, &new_event, prev_event_slice)?;
- cmd_list.close()?;
- unsafe { stream_data.queue.execute(&cmd_list, None)? };
+ f(cmd_list, &new_event, prev_event_slice)?;
stream_data.push_event((new_event, new_marker));
Ok(())
})?
diff --git a/zluda/src/impl/stream.rs b/zluda/src/impl/stream.rs
index 11f1869..724eb19 100644
--- a/zluda/src/impl/stream.rs
+++ b/zluda/src/impl/stream.rs
@@ -33,7 +33,8 @@ impl HasLivenessCookie for StreamData {
pub struct StreamData {
pub context: *mut ContextData,
- pub queue: l0::CommandQueue<'static>,
+ // Immediate CommandList
+ pub cmd_list: l0::CommandList<'static>,
pub prev_events: VecDeque<(l0::Event<'static>, u64)>,
}
@@ -44,7 +45,7 @@ impl StreamData {
) -> Result<Self, CUresult> {
Ok(StreamData {
context: ptr::null_mut(),
- queue: l0::CommandQueue::new(ctx, device)?,
+ cmd_list: l0::CommandList::new_immediate(ctx, device)?,
prev_events: VecDeque::new(),
})
}
@@ -53,18 +54,12 @@ impl StreamData {
let device = unsafe { &*ctx.device }.base;
Ok(StreamData {
context: ctx as *mut _,
- queue: l0::CommandQueue::new(l0_ctx, device)?,
+ cmd_list: l0::CommandList::new_immediate(l0_ctx, device)?,
prev_events: VecDeque::new(),
})
}
- pub fn command_list(&self) -> Result<l0::CommandList, l0::sys::_ze_result_t> {
- let ctx = unsafe { &mut *self.context };
- let dev = unsafe { &mut *ctx.device };
- l0::CommandList::new(&mut dev.l0_context, dev.base)
- }
-
- pub fn process_finished_events(
+ pub fn drop_finished_events(
&mut self,
f: &mut impl FnMut((l0::Event<'static>, u64)),
) -> l0::Result<()> {
@@ -82,6 +77,12 @@ impl StreamData {
}
}
+ pub fn drop_all_events(&mut self, f: &mut impl FnMut((l0::Event<'static>, u64))) {
+ for x in self.prev_events.drain(..) {
+ f(x);
+ }
+ }
+
pub fn get_last_event(&self) -> Option<&l0::Event<'static>> {
self.prev_events.iter().next_back().map(|(ev, _)| ev)
}
@@ -91,9 +92,11 @@ impl StreamData {
}
pub fn synchronize(&mut self) -> l0::Result<()> {
- self.queue.synchronize(u64::MAX)?;
+ if let Some((ev, _)) = self.prev_events.back() {
+ ev.host_synchronize(u64::MAX)?;
+ }
let event_pool = unsafe { &mut (*(*self.context).device).event_pool };
- self.process_finished_events(&mut |(_, marker)| event_pool.mark_as_free(marker))?;
+ self.drop_all_events(&mut |(_, marker)| event_pool.mark_as_free(marker));
Ok(())
}
}