diff options
author | Andrzej Janik <[email protected]> | 2021-07-04 16:46:07 +0200 |
---|---|---|
committer | Andrzej Janik <[email protected]> | 2021-07-04 16:46:07 +0200 |
commit | ce25035051bbe462bbabec7c446cd62c5f07f88f (patch) | |
tree | bf70a3fd4d4f9f5a040e440aa4a527592be48211 /zluda | |
parent | ecc33f7b105373264807d09f6bdcadb93e59f1f0 (diff) | |
download | ZLUDA-ce25035051bbe462bbabec7c446cd62c5f07f88f.tar.gz ZLUDA-ce25035051bbe462bbabec7c446cd62c5f07f88f.zip |
Use immediate command lists
Diffstat (limited to 'zluda')
-rw-r--r-- | zluda/src/impl/mod.rs | 14 | ||||
-rw-r--r-- | zluda/src/impl/stream.rs | 27 |
2 files changed, 23 insertions, 18 deletions
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(()) } } |