From 4807573ba7a9481396fdc183e8856eac2ea0a82d Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Sun, 28 Jan 2024 21:37:12 +0100 Subject: [PATCH] rusticl/icd: move get_arc() and rename it Part-of: --- src/gallium/frontends/rusticl/api/event.rs | 3 +- src/gallium/frontends/rusticl/api/icd.rs | 26 +++-- src/gallium/frontends/rusticl/api/kernel.rs | 19 +-- src/gallium/frontends/rusticl/api/memory.rs | 109 +++++++++--------- src/gallium/frontends/rusticl/api/program.rs | 22 ++-- src/gallium/frontends/rusticl/api/queue.rs | 11 +- src/gallium/frontends/rusticl/core/program.rs | 10 +- 7 files changed, 106 insertions(+), 94 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/event.rs b/src/gallium/frontends/rusticl/api/event.rs index 691992f7ce9..a49a9a4f3df 100644 --- a/src/gallium/frontends/rusticl/api/event.rs +++ b/src/gallium/frontends/rusticl/api/event.rs @@ -1,6 +1,7 @@ use crate::api::icd::*; use crate::api::types::*; use crate::api::util::*; +use crate::core::context::*; use crate::core::event::*; use crate::core::queue::*; @@ -62,7 +63,7 @@ impl CLInfo for cl_event { #[cl_entrypoint] fn create_user_event(context: cl_context) -> CLResult { - let c = context.get_arc()?; + let c = Context::arc_from_raw(context)?; Ok(Event::new_user(c).into_cl()) } diff --git a/src/gallium/frontends/rusticl/api/icd.rs b/src/gallium/frontends/rusticl/api/icd.rs index db7c8b5b318..ce7dae85065 100644 --- a/src/gallium/frontends/rusticl/api/icd.rs +++ b/src/gallium/frontends/rusticl/api/icd.rs @@ -233,20 +233,26 @@ pub trait ReferenceCountedAPIPointer { // I can do the cast in the main trait implementation. So we need to // implement that as part of the macro where we know the real type. fn from_ptr(ptr: *const T) -> Self; - - fn get_arc(&self) -> CLResult> { - unsafe { - let ptr = self.get_ptr()?; - Arc::increment_strong_count(ptr); - Ok(Arc::from_raw(ptr)) - } - } } pub trait CLObject<'a, const ERR: i32, CL: ReferenceCountedAPIPointer + 'a>: Sized { - fn arcs_from_arr(objs: *const CL, count: u32) -> CLResult>> { + /// Note: this operation increases the internal ref count as `ref_from_raw` is the better option + /// when an Arc is not needed. + fn arc_from_raw(ptr: CL) -> CLResult> { + let ptr = ptr.get_ptr()?; + // SAFETY: `get_ptr` already checks if it's one of our pointers. + Ok(unsafe { + Arc::increment_strong_count(ptr); + Arc::from_raw(ptr) + }) + } + + fn arcs_from_arr(objs: *const CL, count: u32) -> CLResult>> + where + CL: Copy, + { // CL spec requires validation for obj arrays, both values have to make sense if objs.is_null() && count > 0 || !objs.is_null() && count == 0 { return Err(CL_INVALID_VALUE); @@ -259,7 +265,7 @@ pub trait CLObject<'a, const ERR: i32, CL: ReferenceCountedAPIPointer for i in 0..count as usize { unsafe { - res.push((*objs.add(i)).get_arc()?); + res.push(Self::arc_from_raw(*objs.add(i))?); } } Ok(res) diff --git a/src/gallium/frontends/rusticl/api/kernel.rs b/src/gallium/frontends/rusticl/api/kernel.rs index 96180a8f218..48aca75b224 100644 --- a/src/gallium/frontends/rusticl/api/kernel.rs +++ b/src/gallium/frontends/rusticl/api/kernel.rs @@ -4,6 +4,9 @@ use crate::api::util::*; use crate::core::device::*; use crate::core::event::*; use crate::core::kernel::*; +use crate::core::memory::*; +use crate::core::program::*; +use crate::core::queue::*; use mesa_rust_util::ptr::*; use mesa_rust_util::string::*; @@ -238,7 +241,7 @@ fn create_kernel( program: cl_program, kernel_name: *const ::std::os::raw::c_char, ) -> CLResult { - let p = program.get_arc()?; + let p = Program::arc_from_raw(program)?; let name = c_string_to_string(kernel_name); // CL_INVALID_VALUE if kernel_name is NULL. @@ -283,7 +286,7 @@ fn create_kernels_in_program( kernels: *mut cl_kernel, num_kernels_ret: *mut cl_uint, ) -> CLResult<()> { - let p = program.get_arc()?; + let p = Program::arc_from_raw(program)?; // CL_INVALID_PROGRAM_EXECUTABLE if there is no successfully built executable for any device in // program. @@ -327,7 +330,7 @@ fn set_kernel_arg( arg_size: usize, arg_value: *const ::std::os::raw::c_void, ) -> CLResult<()> { - let k = kernel.get_arc()?; + let k = Kernel::ref_from_raw(kernel)?; // CL_INVALID_ARG_INDEX if arg_index is not a valid argument index. if let Some(arg) = k.kernel_info.args.get(arg_index as usize) { @@ -390,17 +393,17 @@ fn set_kernel_arg( if ptr.is_null() || (*ptr).is_null() { KernelArgValue::None } else { - KernelArgValue::MemObject((*ptr).get_arc()?) + KernelArgValue::MemObject(Mem::arc_from_raw(*ptr)?) } } KernelArgType::MemLocal => KernelArgValue::LocalMem(arg_size), KernelArgType::Image | KernelArgType::RWImage | KernelArgType::Texture => { let img: *const cl_mem = arg_value.cast(); - KernelArgValue::MemObject((*img).get_arc()?) + KernelArgValue::MemObject(Mem::arc_from_raw(*img)?) } KernelArgType::Sampler => { let ptr: *const cl_sampler = arg_value.cast(); - KernelArgValue::Sampler((*ptr).get_arc()?) + KernelArgValue::Sampler(Sampler::arc_from_raw(*ptr)?) } } } @@ -502,8 +505,8 @@ fn enqueue_ndrange_kernel( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; - let k = kernel.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let k = Kernel::arc_from_raw(kernel)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // CL_INVALID_CONTEXT if context associated with command_queue and kernel are not the same diff --git a/src/gallium/frontends/rusticl/api/memory.rs b/src/gallium/frontends/rusticl/api/memory.rs index 492fd44c564..0c8e10ab224 100644 --- a/src/gallium/frontends/rusticl/api/memory.rs +++ b/src/gallium/frontends/rusticl/api/memory.rs @@ -10,6 +10,7 @@ use crate::core::event::EventSig; use crate::core::format::*; use crate::core::gl::*; use crate::core::memory::*; +use crate::core::queue::*; use mesa_rust_util::properties::Properties; use mesa_rust_util::ptr::*; @@ -254,7 +255,7 @@ fn create_buffer_with_properties( size: usize, host_ptr: *mut ::std::os::raw::c_void, ) -> CLResult { - let c = context.get_arc()?; + let c = Context::arc_from_raw(context)?; // CL_INVALID_VALUE if values specified in flags are not valid as defined in the Memory Flags table. validate_mem_flags(flags, false)?; @@ -300,7 +301,7 @@ fn create_sub_buffer( buffer_create_type: cl_buffer_create_type, buffer_create_info: *const ::std::os::raw::c_void, ) -> CLResult { - let b = buffer.get_arc()?; + let b = Mem::arc_from_raw(buffer)?; // CL_INVALID_MEM_OBJECT if buffer ... is a sub-buffer object. if b.parent.is_some() { @@ -460,7 +461,7 @@ fn validate_image_desc( // TODO: cl_khr_image2d_from_buffer is an optional feature let p = unsafe { &desc.anon_1.mem_object }; let parent = if !p.is_null() { - let p = p.get_arc()?; + let p = Mem::arc_from_raw(*p)?; if !match desc.image_type { CL_MEM_OBJECT_IMAGE1D_BUFFER => p.is_buffer(), CL_MEM_OBJECT_IMAGE2D => { @@ -726,7 +727,7 @@ fn create_image_with_properties( image_desc: *const cl_image_desc, host_ptr: *mut ::std::os::raw::c_void, ) -> CLResult { - let c = context.get_arc()?; + let c = Context::arc_from_raw(context)?; // CL_INVALID_OPERATION if there are no devices in context that support images (i.e. // CL_DEVICE_IMAGE_SUPPORT specified in the Device Queries table is CL_FALSE). @@ -922,7 +923,7 @@ fn create_sampler_impl( filter_mode: cl_filter_mode, props: Option>, ) -> CLResult { - let c = context.get_arc()?; + let c = Context::arc_from_raw(context)?; // CL_INVALID_OPERATION if images are not supported by any device associated with context (i.e. // CL_DEVICE_IMAGE_SUPPORT specified in the Device Queries table is CL_FALSE). @@ -1021,8 +1022,8 @@ fn enqueue_read_buffer( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; - let b = buffer.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let b = Mem::arc_from_raw(buffer)?; let block = check_cl_bool(blocking_read).ok_or(CL_INVALID_VALUE)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; @@ -1074,8 +1075,8 @@ fn enqueue_write_buffer( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; - let b = buffer.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let b = Mem::arc_from_raw(buffer)?; let block = check_cl_bool(blocking_write).ok_or(CL_INVALID_VALUE)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; @@ -1127,9 +1128,9 @@ fn enqueue_copy_buffer( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; - let src = src_buffer.get_arc()?; - let dst = dst_buffer.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let src = Mem::arc_from_raw(src_buffer)?; + let dst = Mem::arc_from_raw(dst_buffer)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // CL_INVALID_CONTEXT if the context associated with command_queue, src_buffer and dst_buffer @@ -1201,8 +1202,8 @@ fn enqueue_read_buffer_rect( event: *mut cl_event, ) -> CLResult<()> { let block = check_cl_bool(blocking_read).ok_or(CL_INVALID_VALUE)?; - let q = command_queue.get_arc()?; - let buf = buffer.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let buf = Mem::arc_from_raw(buffer)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // CL_INVALID_OPERATION if clEnqueueReadBufferRect is called on buffer which has been created @@ -1324,8 +1325,8 @@ fn enqueue_write_buffer_rect( event: *mut cl_event, ) -> CLResult<()> { let block = check_cl_bool(blocking_write).ok_or(CL_INVALID_VALUE)?; - let q = command_queue.get_arc()?; - let buf = buffer.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let buf = Mem::arc_from_raw(buffer)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // CL_INVALID_OPERATION if clEnqueueWriteBufferRect is called on buffer which has been created @@ -1445,9 +1446,9 @@ fn enqueue_copy_buffer_rect( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; - let src = src_buffer.get_arc()?; - let dst = dst_buffer.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let src = Mem::arc_from_raw(src_buffer)?; + let dst = Mem::arc_from_raw(dst_buffer)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // CL_INVALID_VALUE if src_origin, dst_origin, or region is NULL. @@ -1580,8 +1581,8 @@ fn enqueue_fill_buffer( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; - let b = buffer.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let b = Mem::arc_from_raw(buffer)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // CL_INVALID_VALUE if offset or offset + size require accessing elements outside the buffer @@ -1634,8 +1635,8 @@ fn enqueue_map_buffer( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<*mut c_void> { - let q = command_queue.get_arc()?; - let b = buffer.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let b = Mem::arc_from_raw(buffer)?; let block = check_cl_bool(blocking_map).ok_or(CL_INVALID_VALUE)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; @@ -1690,8 +1691,8 @@ fn enqueue_read_image( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; - let i = image.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let i = Mem::arc_from_raw(image)?; let block = check_cl_bool(blocking_read).ok_or(CL_INVALID_VALUE)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; let pixel_size = i.image_format.pixel_size().unwrap() as usize; @@ -1781,8 +1782,8 @@ fn enqueue_write_image( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; - let i = image.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let i = Mem::arc_from_raw(image)?; let block = check_cl_bool(blocking_write).ok_or(CL_INVALID_VALUE)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; let pixel_size = i.image_format.pixel_size().unwrap() as usize; @@ -1870,9 +1871,9 @@ fn enqueue_copy_image( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; - let src_image = src_image.get_arc()?; - let dst_image = dst_image.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let src_image = Mem::arc_from_raw(src_image)?; + let dst_image = Mem::arc_from_raw(dst_image)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // CL_INVALID_CONTEXT if the context associated with command_queue, src_image and dst_image are not the same @@ -1930,8 +1931,8 @@ fn enqueue_fill_image( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; - let i = image.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let i = Mem::arc_from_raw(image)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // CL_INVALID_CONTEXT if the context associated with command_queue and image are not the same @@ -1983,9 +1984,9 @@ fn enqueue_copy_buffer_to_image( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; - let src = src_buffer.get_arc()?; - let dst = dst_image.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let src = Mem::arc_from_raw(src_buffer)?; + let dst = Mem::arc_from_raw(dst_image)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // CL_INVALID_CONTEXT if the context associated with command_queue, src_buffer and dst_image @@ -2039,9 +2040,9 @@ fn enqueue_copy_image_to_buffer( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; - let src = src_image.get_arc()?; - let dst = dst_buffer.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let src = Mem::arc_from_raw(src_image)?; + let dst = Mem::arc_from_raw(dst_buffer)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // CL_INVALID_CONTEXT if the context associated with command_queue, src_image and dst_buffer @@ -2098,8 +2099,8 @@ fn enqueue_map_image( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<*mut ::std::os::raw::c_void> { - let q = command_queue.get_arc()?; - let i = image.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let i = Mem::arc_from_raw(image)?; let block = check_cl_bool(blocking_map).ok_or(CL_INVALID_VALUE)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; @@ -2146,7 +2147,7 @@ fn enqueue_map_image( )?; create_and_queue( - q.clone(), + q, CL_COMMAND_MAP_IMAGE, evs, event, @@ -2183,8 +2184,8 @@ fn enqueue_unmap_mem_object( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; - let m = memobj.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; + let m = Mem::arc_from_raw(memobj)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // CL_INVALID_CONTEXT if context associated with command_queue and memobj are not the same @@ -2218,9 +2219,9 @@ fn enqueue_migrate_mem_objects( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; - let bufs = Mem::arcs_from_arr(mem_objects, num_mem_objects)?; + let bufs = Mem::refs_from_arr(mem_objects, num_mem_objects)?; // CL_INVALID_VALUE if num_mem_objects is zero or if mem_objects is NULL. if bufs.is_empty() { @@ -2350,7 +2351,7 @@ fn enqueue_svm_free_impl( event: *mut cl_event, cmd_type: cl_command_type, ) -> CLResult<()> { - let q = command_queue.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // CL_INVALID_VALUE if num_svm_pointers is 0 and svm_pointers is non-NULL, or if svm_pointers is @@ -2454,7 +2455,7 @@ fn enqueue_svm_memcpy_impl( event: *mut cl_event, cmd_type: cl_command_type, ) -> CLResult<()> { - let q = command_queue.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; let block = check_cl_bool(blocking_copy).ok_or(CL_INVALID_VALUE)?; @@ -2562,7 +2563,7 @@ fn enqueue_svm_mem_fill_impl( event: *mut cl_event, cmd_type: cl_command_type, ) -> CLResult<()> { - let q = command_queue.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // CL_INVALID_OPERATION if the device associated with command queue does not support SVM. @@ -2742,7 +2743,7 @@ fn enqueue_svm_map_impl( event: *mut cl_event, cmd_type: cl_command_type, ) -> CLResult<()> { - let q = command_queue.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; let block = check_cl_bool(blocking_map).ok_or(CL_INVALID_VALUE)?; @@ -2823,7 +2824,7 @@ fn enqueue_svm_unmap_impl( event: *mut cl_event, cmd_type: cl_command_type, ) -> CLResult<()> { - let q = command_queue.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // CL_INVALID_OPERATION if the device associated with command queue does not support SVM. @@ -2886,7 +2887,7 @@ fn enqueue_svm_migrate_mem( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // CL_INVALID_OPERATION if the device associated with command queue does not support SVM. @@ -2982,7 +2983,7 @@ fn create_from_gl( miplevel: cl_GLint, texture: cl_GLuint, ) -> CLResult { - let c = context.get_arc()?; + let c = Context::arc_from_raw(context)?; let gl_ctx_manager = &c.gl_ctx_manager; // CL_INVALID_CONTEXT if context associated with command_queue was not created from an OpenGL context @@ -3111,7 +3112,7 @@ fn enqueue_acquire_gl_objects( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; let objs = Mem::arcs_from_arr(mem_objects, num_objects)?; let gl_ctx_manager = &q.context.gl_ctx_manager; @@ -3145,7 +3146,7 @@ fn enqueue_release_gl_objects( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; let objs = Mem::arcs_from_arr(mem_objects, num_objects)?; let gl_ctx_manager = &q.context.gl_ctx_manager; diff --git a/src/gallium/frontends/rusticl/api/program.rs b/src/gallium/frontends/rusticl/api/program.rs index c6878b19667..c765653982c 100644 --- a/src/gallium/frontends/rusticl/api/program.rs +++ b/src/gallium/frontends/rusticl/api/program.rs @@ -1,6 +1,7 @@ use crate::api::icd::*; use crate::api::types::*; use crate::api::util::*; +use crate::core::context::*; use crate::core::device::*; use crate::core::platform::*; use crate::core::program::*; @@ -63,13 +64,13 @@ impl CLInfo for cl_program { impl CLInfoObj for cl_program { fn query(&self, d: cl_device_id, q: cl_program_build_info) -> CLResult>> { let prog = Program::ref_from_raw(*self)?; - let dev = d.get_arc()?; + let dev = Device::ref_from_raw(d)?; Ok(match q { - CL_PROGRAM_BINARY_TYPE => cl_prop::(prog.bin_type(&dev)), + CL_PROGRAM_BINARY_TYPE => cl_prop::(prog.bin_type(dev)), CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE => cl_prop::(0), - CL_PROGRAM_BUILD_LOG => cl_prop::<&str>(&prog.log(&dev)), - CL_PROGRAM_BUILD_OPTIONS => cl_prop::<&str>(&prog.options(&dev)), - CL_PROGRAM_BUILD_STATUS => cl_prop::(prog.status(&dev)), + CL_PROGRAM_BUILD_LOG => cl_prop::<&str>(&prog.log(dev)), + CL_PROGRAM_BUILD_OPTIONS => cl_prop::<&str>(&prog.options(dev)), + CL_PROGRAM_BUILD_STATUS => cl_prop::(prog.status(dev)), // CL_INVALID_VALUE if param_name is not one of the supported values _ => return Err(CL_INVALID_VALUE), }) @@ -99,7 +100,7 @@ fn create_program_with_source( strings: *mut *const c_char, lengths: *const usize, ) -> CLResult { - let c = context.get_arc()?; + let c = Context::arc_from_raw(context)?; // CL_INVALID_VALUE if count is zero or if strings ... if count == 0 || strings.is_null() { @@ -164,8 +165,7 @@ fn create_program_with_source( } Ok(Program::new( - &c, - &c.devs, + c, // SAFETY: We've constructed `source` such that it contains no nul bytes. unsafe { CString::from_vec_unchecked(source) }, ) @@ -181,7 +181,7 @@ fn create_program_with_binary( binaries: *mut *const ::std::os::raw::c_uchar, binary_status: *mut cl_int, ) -> CLResult { - let c = context.get_arc()?; + let c = Context::arc_from_raw(context)?; let devs = Device::refs_from_arr(device_list, num_devices)?; // CL_INVALID_VALUE if device_list is NULL or num_devices is zero. @@ -239,7 +239,7 @@ fn create_program_with_il( il: *const ::std::os::raw::c_void, length: usize, ) -> CLResult { - let c = context.get_arc()?; + let c = Context::arc_from_raw(context)?; // CL_INVALID_VALUE if il is NULL or if length is zero. if il.is_null() || length == 0 { @@ -407,7 +407,7 @@ pub fn link_program( pfn_notify: Option, user_data: *mut ::std::os::raw::c_void, ) -> CLResult<(cl_program, cl_int)> { - let c = context.get_arc()?; + let c = Context::arc_from_raw(context)?; let devs = validate_devices(device_list, num_devices, &c.devs)?; let progs = Program::arcs_from_arr(input_programs, num_input_programs)?; diff --git a/src/gallium/frontends/rusticl/api/queue.rs b/src/gallium/frontends/rusticl/api/queue.rs index 38499488443..957faffaa55 100644 --- a/src/gallium/frontends/rusticl/api/queue.rs +++ b/src/gallium/frontends/rusticl/api/queue.rs @@ -1,6 +1,7 @@ use crate::api::event::create_and_queue; use crate::api::icd::*; use crate::api::util::*; +use crate::core::context::*; use crate::core::device::*; use crate::core::event::*; use crate::core::queue::*; @@ -73,7 +74,7 @@ pub fn create_command_queue_impl( properties: cl_command_queue_properties, properties_v2: Option>, ) -> CLResult { - let c = context.get_arc()?; + let c = Context::arc_from_raw(context)?; let d = Device::ref_from_raw(device)? .to_static() .ok_or(CL_INVALID_DEVICE)?; @@ -135,7 +136,7 @@ fn create_command_queue_with_properties( #[cl_entrypoint] fn enqueue_marker(command_queue: cl_command_queue, event: *mut cl_event) -> CLResult<()> { - let q = command_queue.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; // TODO marker makes sure previous commands did complete create_and_queue( @@ -155,7 +156,7 @@ fn enqueue_marker_with_wait_list( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // TODO marker makes sure previous commands did complete @@ -171,7 +172,7 @@ fn enqueue_marker_with_wait_list( #[cl_entrypoint] fn enqueue_barrier(command_queue: cl_command_queue) -> CLResult<()> { - let q = command_queue.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; // TODO barriers make sure previous commands did complete and other commands didn't start let e = Event::new(&q, CL_COMMAND_BARRIER, Vec::new(), Box::new(|_, _| Ok(()))); @@ -186,7 +187,7 @@ fn enqueue_barrier_with_wait_list( event_wait_list: *const cl_event, event: *mut cl_event, ) -> CLResult<()> { - let q = command_queue.get_arc()?; + let q = Queue::arc_from_raw(command_queue)?; let evs = event_list_from_cl(&q, num_events_in_wait_list, event_wait_list)?; // TODO barriers make sure previous commands did complete and other commands didn't start diff --git a/src/gallium/frontends/rusticl/core/program.rs b/src/gallium/frontends/rusticl/core/program.rs index 0137ba84af1..2e7c8318c93 100644 --- a/src/gallium/frontends/rusticl/core/program.rs +++ b/src/gallium/frontends/rusticl/core/program.rs @@ -355,18 +355,18 @@ impl Program { .collect() } - pub fn new(context: &Arc, devs: &[&'static Device], src: CString) -> Arc { + pub fn new(context: Arc, src: CString) -> Arc { Arc::new(Self { base: CLObjectBase::new(RusticlTypes::Program), - context: context.clone(), - devs: devs.to_vec(), - src: ProgramSourceType::Src(src), build: Mutex::new(ProgramBuild { - builds: Self::create_default_builds(devs), + builds: Self::create_default_builds(&context.devs), spec_constants: HashMap::new(), kernels: Vec::new(), kernel_info: HashMap::new(), }), + devs: context.devs.to_vec(), + context: context, + src: ProgramSourceType::Src(src), }) }