From ebfffa1daec0a5a5ad0ca83dae1873cd01407bd1 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Sat, 12 Mar 2022 22:23:23 +0100 Subject: [PATCH] rusticl/event: wrong but non crashing impl of clWaitForEvents Signed-off-by: Karol Herbst Acked-by: Alyssa Rosenzweig Part-of: --- src/gallium/frontends/rusticl/api/event.rs | 34 ++++++++++++++++++++++ src/gallium/frontends/rusticl/api/icd.rs | 5 ++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/event.rs b/src/gallium/frontends/rusticl/api/event.rs index 6532682b1d1..fe6c72eef7e 100644 --- a/src/gallium/frontends/rusticl/api/event.rs +++ b/src/gallium/frontends/rusticl/api/event.rs @@ -7,6 +7,7 @@ use crate::core::queue::*; use self::rusticl_opencl_gen::*; +use std::collections::HashSet; use std::ptr; use std::sync::Arc; @@ -40,6 +41,39 @@ pub fn create_user_event(context: cl_context) -> CLResult { Ok(cl_event::from_arc(Event::new_user(c))) } +pub fn wait_for_events(num_events: cl_uint, event_list: *const cl_event) -> CLResult<()> { + let evs = cl_event::get_arc_vec_from_arr(event_list, num_events)?; + + // CL_INVALID_VALUE if num_events is zero or event_list is NULL. + if evs.is_empty() { + return Err(CL_INVALID_VALUE); + } + + // CL_INVALID_CONTEXT if events specified in event_list do not belong to the same context. + let contexts: HashSet<_> = evs.iter().map(|e| &e.context).collect(); + if contexts.len() != 1 { + return Err(CL_INVALID_CONTEXT); + } + + // TODO better impl + let mut err = false; + for e in evs { + if let Some(q) = &e.queue { + q.flush(true)?; + } + + err |= e.status() < 0; + } + + // CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST if the execution status of any of the events + // in event_list is a negative integer value. + if err { + return Err(CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST); + } + + Ok(()) +} + pub fn create_and_queue( q: Arc, cmd_type: cl_command_type, diff --git a/src/gallium/frontends/rusticl/api/icd.rs b/src/gallium/frontends/rusticl/api/icd.rs index aff678e57b2..ea3f7e40c60 100644 --- a/src/gallium/frontends/rusticl/api/icd.rs +++ b/src/gallium/frontends/rusticl/api/icd.rs @@ -824,9 +824,8 @@ extern "C" fn cl_get_kernel_work_group_info( )) } -extern "C" fn cl_wait_for_events(_num_events: cl_uint, _event_list: *const cl_event) -> cl_int { - println!("cl_wait_for_events not implemented"); - CL_OUT_OF_HOST_MEMORY +extern "C" fn cl_wait_for_events(num_events: cl_uint, event_list: *const cl_event) -> cl_int { + match_err!(wait_for_events(num_events, event_list)) } extern "C" fn cl_get_event_info(