From f8cb2289b04699ae07b15877c22f31ae3198bb62 Mon Sep 17 00:00:00 2001 From: Ken Barker Date: Sun, 31 Mar 2024 10:35:19 +0100 Subject: [PATCH] Fix clippy features and change github workflow. --- .github/workflows/rust.yml | 28 +++++++++++++++++++--- Cargo.toml | 2 +- src/command_buffer.rs | 21 +---------------- src/command_queue.rs | 48 ++++---------------------------------- src/context.rs | 39 ++++++++++++++----------------- src/device.rs | 4 +++- src/kernel.rs | 13 +++++------ src/platform.rs | 6 +++-- src/program.rs | 34 +++++---------------------- 9 files changed, 68 insertions(+), 127 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 64403c8..286c4eb 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -2,7 +2,7 @@ name: Rust on: push: - branches: [ main ] + branches: [ main, develop ] pull_request: branches: [ develop ] @@ -10,9 +10,19 @@ env: CARGO_TERM_COLOR: always jobs: - build: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust + run: rustup update stable + - name: Unit test + run: cargo check - runs-on: ubuntu-20.04 + build: + name: Build + runs-on: ubuntu-latest steps: - name: Load OpenCL @@ -33,3 +43,15 @@ jobs: run: cargo build --verbose # - name: Run tests # run: cargo test --verbose + + clippy: + name: Clippy + runs-on: ubuntu-latest + env: + RUSTFLAGS: "-Dwarnings" + steps: + - uses: actions/checkout@v4 + - name: Install Rust + run: rustup update stable + - name: Run Clippy + run: cargo clippy --all-features diff --git a/Cargo.toml b/Cargo.toml index a0535e9..cd87193 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,7 +69,7 @@ default = ["CL_VERSION_1_1", "CL_VERSION_1_2", "CL_VERSION_2_0"] [dependencies] libc = "0.2" -cl3 = "0.9" +cl3 = "0.10" serde = { version = "1.0", optional = true } [dev-dependencies] diff --git a/src/command_buffer.rs b/src/command_buffer.rs index 2e80b16..a545606 100644 --- a/src/command_buffer.rs +++ b/src/command_buffer.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2021-2023 Via Technology Ltd. +// Copyright (c) 2021-2024 Via Technology Ltd. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -427,23 +427,4 @@ impl CommandBuffer { pub fn get_data(&self, param_name: cl_command_buffer_info_khr) -> Result> { Ok(get_command_buffer_data_khr(self.buffer, param_name)?) } - - #[cfg(feature = "cl_khr_command_buffer_multi_device")] - pub unsafe fn get_mutable_dispatch_data( - &self, - automatic: cl_bool, - queues: &[cl_command_queue], - handles: &[cl_mutable_command_khr], - handles_ret: *mut cl_mutable_command_khr, - ) -> Result { - Ok(get_command_buffer_mutable_dispatch_data( - self.buffer, - automatic, - queues.len() as cl_uint, - queues.as_ptr(), - handles.len() as cl_uint, - handles.as_ptr(), - handles_ret, - )?) - } } diff --git a/src/command_queue.rs b/src/command_queue.rs index d6cd2d7..125685d 100644 --- a/src/command_queue.rs +++ b/src/command_queue.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2023 Via Technology Ltd. +// Copyright (c) 2020-2024 Via Technology Ltd. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -1225,48 +1225,6 @@ impl CommandQueue { Ok(Event::new(event)) } - #[cfg(feature = "cl_khr_dx9_media_sharing")] - #[inline] - pub unsafe fn enqueue_acquire_dx9_media_surfaces_khr( - &self, - mem_objects: &[*const c_void], - event_wait_list: &[cl_event], - ) -> Result { - let event = dx9_media_sharing::enqueue_acquire_dx9_media_surfaces_khr( - self.queue, - mem_objects.len() as cl_uint, - mem_objects.as_ptr() as *const *mut c_void, - event_wait_list.len() as cl_uint, - if !event_wait_list.is_empty() { - event_wait_list.as_ptr() - } else { - ptr::null() - }, - )?; - Ok(Event::new(event)) - } - - #[cfg(feature = "cl_khr_dx9_media_sharing")] - #[inline] - pub unsafe fn enqueue_release_dx9_media_surfaces_khr( - &self, - mem_objects: &[*const c_void], - event_wait_list: &[cl_event], - ) -> Result { - let event = dx9_media_sharing::enqueue_release_dx9_media_surfaces_khr( - self.queue, - mem_objects.len() as cl_uint, - mem_objects.as_ptr() as *const *mut c_void, - event_wait_list.len() as cl_uint, - if !event_wait_list.is_empty() { - event_wait_list.as_ptr() - } else { - ptr::null() - }, - )?; - Ok(Event::new(event)) - } - #[cfg(feature = "cl_intel_dx9_media_sharing")] #[inline] pub unsafe fn enqueue_acquire_dx9_objects_intel( @@ -1310,12 +1268,13 @@ impl CommandQueue { } #[cfg(feature = "cl_img_generate_mipmap")] + #[allow(clippy::cast_possible_truncation)] #[inline] pub unsafe fn enqueue_generate_mipmap_img( &self, src_image: cl_mem, dst_image: cl_mem, - mipmap_filter_mode: cl_mipmap_filter_mode_img, + mipmap_filter_mode: ext::cl_mipmap_filter_mode_img, array_region: *const size_t, mip_region: *const size_t, event_wait_list: &[cl_event], @@ -1327,6 +1286,7 @@ impl CommandQueue { mipmap_filter_mode, array_region, mip_region, + event_wait_list.len() as cl_uint, if !event_wait_list.is_empty() { event_wait_list.as_ptr() } else { diff --git a/src/context.rs b/src/context.rs index 79eb570..bbd656e 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 Via Technology Ltd. +// Copyright (c) 2020-2024 Via Technology Ltd. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![allow(clippy::missing_safety_doc)] + pub use cl3::context; use super::device::Device; @@ -54,7 +56,7 @@ pub fn get_current_device_for_gl_context_khr( ) -> Result { let device = intptr_t::from(gl::get_gl_context_info_khr( properties.as_ptr() as *mut cl_context_properties, - gl::GlCL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, + gl::CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, )?) as cl_device_id; Ok(device) } @@ -71,7 +73,7 @@ pub fn get_devices_for_gl_context_khr( ) -> Result> { let dev_ptrs: Vec = gl::get_gl_context_info_khr( properties.as_ptr() as *mut cl_context_properties, - gl::GlCL_DEVICES_FOR_GL_CONTEXT_KHR, + gl::CL_DEVICES_FOR_GL_CONTEXT_KHR, )? .into(); let devices = dev_ptrs @@ -249,7 +251,7 @@ impl Context { } #[cfg(feature = "cl_arm_import_memory")] - pub fn import_memory_arm( + pub unsafe fn import_memory_arm( &self, flags: cl_mem_flags, properties: *const ext::cl_import_properties_arm, @@ -303,7 +305,7 @@ impl Context { } #[cfg(feature = "cl_khr_terminate_context")] - pub fn terminate(&self) -> Result<()> { + pub unsafe fn terminate(&self) -> Result<()> { Ok(ext::terminate_context_khr(self.context)?) } @@ -315,7 +317,7 @@ impl Context { /// returns a Result containing the new OpenCL event /// or the error code from the OpenCL C API function. #[cfg(feature = "cl_khr_gl_sharing")] - pub fn create_event_from_gl_sync_khr(&self, sync: gl::gl_sync) -> Result { + pub fn create_event_from_gl_sync_khr(&self, sync: gl::cl_GLsync) -> Result { Ok(gl::create_event_from_gl_sync_khr(self.context, sync)?) } @@ -328,7 +330,7 @@ impl Context { /// returns a Result containing the new OpenCL event /// or the error code from the OpenCL C API function. #[cfg(feature = "cl_khr_egl_event")] - pub fn create_event_from_egl_sync_khr( + pub unsafe fn create_event_from_egl_sync_khr( &self, sync: egl::CLeglSyncKHR, display: egl::CLeglDisplayKHR, @@ -361,14 +363,14 @@ impl Context { image_type: cl_mem_object_type, plane: cl_uint, ) -> Result> { - Ok( + Ok(unsafe { dx9_media_sharing::get_supported_dx9_media_surface_formats_intel( self.context, flags, image_type, plane, - )?, - ) + ) + }?) } #[cfg(feature = "cl_khr_d3d10_sharing")] @@ -377,11 +379,9 @@ impl Context { flags: cl_mem_flags, image_type: cl_mem_object_type, ) -> Result> { - Ok(d3d10::get_supported_d3d10_texture_formats_intel( - self.context, - flags, - image_type, - )?) + Ok(unsafe { + d3d10::get_supported_d3d10_texture_formats_intel(self.context, flags, image_type) + }?) } #[cfg(feature = "cl_khr_d3d11_sharing")] @@ -391,12 +391,9 @@ impl Context { image_type: cl_mem_object_type, plane: cl_uint, ) -> Result> { - Ok(d3d11::get_supported_d3d11_texture_formats_intel( - self.context, - flags, - image_type, - plane, - )?) + Ok(unsafe { + d3d11::get_supported_d3d11_texture_formats_intel(self.context, flags, image_type, plane) + }?) } } diff --git a/src/device.rs b/src/device.rs index ae45d8f..b20252e 100644 --- a/src/device.rs +++ b/src/device.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2023 Via Technology Ltd. +// Copyright (c) 2020-2024 Via Technology Ltd. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ pub use cl3::ext::cl_device_feature_capabilities_intel; use super::platform::get_platforms; use super::Result; #[allow(unused_imports)] +use cl3::ext; +#[allow(unused_imports)] use libc::{intptr_t, size_t}; /// Get the ids of all available devices of the given type. diff --git a/src/kernel.rs b/src/kernel.rs index 11e9021..ffa8682 100644 --- a/src/kernel.rs +++ b/src/kernel.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2023 Via Technology Ltd. All Rights Reserved. +// Copyright (c) 2020-2024 Via Technology Ltd. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ use super::Result; #[allow(unused_imports)] use cl3::ext; #[allow(unused_imports)] -use cl3::types::{cl_context, cl_event}; +use cl3::types::{cl_command_queue, cl_context, cl_event}; use libc::{c_void, size_t}; use std::ffi::CString; use std::mem; @@ -278,16 +278,15 @@ impl Kernel { pub fn get_kernel_sub_group_info_khr( &self, device: cl_device_id, - device: cl_device_id, - param_name: ext::KernelSubGroupInfoKhr, + param_name: cl_kernel_sub_group_info, input_values: &[size_t], ) -> Result { - Ok(get_kernel_sub_group_info_khr( + Ok(ext::get_kernel_sub_group_info_khr( self.kernel, device, param_name, input_values.len(), - input_values.as_ptr(), + input_values.as_ptr().cast::(), )?) } @@ -299,7 +298,7 @@ impl Kernel { global_work_offset: *const size_t, global_work_size: *const size_t, ) -> Result { - Ok(get_kernel_suggested_local_work_size_khr( + Ok(ext::get_kernel_suggested_local_work_size_khr( command_queue, self.kernel, work_dim, diff --git a/src/platform.rs b/src/platform.rs index 8fa478a..2fd098f 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2023 Via Technology Ltd. +// Copyright (c) 2020-2024 Via Technology Ltd. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![allow(clippy::missing_safety_doc)] + pub use cl3::platform; use super::Result; @@ -85,7 +87,7 @@ impl Platform { } #[cfg(feature = "cl_khr_dx9_media_sharing")] - pub fn get_device_ids_from_dx9_intel( + pub unsafe fn get_device_ids_from_dx9_intel( &self, dx9_device_source: dx9_media_sharing::cl_dx9_device_source_intel, dx9_object: *mut c_void, diff --git a/src/program.rs b/src/program.rs index a304dfc..f603b6b 100644 --- a/src/program.rs +++ b/src/program.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2023 Via Technology Ltd. All Rights Reserved. +// Copyright (c) 2020-2024 Via Technology Ltd. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![allow(clippy::missing_safety_doc)] + pub use cl3::program::*; use super::context::Context; @@ -210,16 +212,13 @@ impl Program { /// or the error code from the OpenCL C API function. #[cfg(feature = "CL_VERSION_2_1")] pub fn create_from_il(context: &Context, il: &[u8]) -> Result { - Ok(Program::new( - create_program_with_il(context.get(), &il)?, - "", - )) + Ok(Program::new(create_program_with_il(context.get(), il)?, "")) } #[cfg(feature = "cl_khr_il_program")] pub fn create_from_il_khr(context: &Context, il: &[u8]) -> Result { Ok(Program::new( - ext::create_program_with_il_khr(context.get(), &il)?, + ext::create_program_with_il_khr(context.get(), il)?, "", )) } @@ -323,7 +322,7 @@ impl Program { il: &[u8], options: &str, ) -> Result { - let mut program = Program::create_from_il(&context, il)?; + let mut program = Program::create_from_il(context, il)?; program.build(context.devices(), options)?; Ok(program) } @@ -393,27 +392,6 @@ impl Program { Ok(()) } - /// Register a callback function with a program object that is called when the - /// program object is destroyed. - /// CL_VERSION_2_2 - /// - /// * `pfn_notify` - function pointer to the notification routine. - /// * `user_data` - passed as an argument when pfn_notify is called, or ptr::null_mut(). - /// - /// returns an empty Result or the error code from the OpenCL C API function. - #[cfg(feature = "CL_VERSION_2_2")] - pub unsafe fn set_release_callback( - &self, - pfn_notify: Option, - user_data: *mut c_void, - ) -> Result<()> { - Ok(set_program_release_callback( - self.program, - pfn_notify, - user_data, - )?) - } - /// Set the value of a specialization constant. /// CL_VERSION_2_2 ///