Skip to content

Commit

Permalink
Fix clippy features and change github workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
kenba committed Mar 31, 2024
1 parent 1d7d74d commit f8cb228
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 127 deletions.
28 changes: 25 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ name: Rust

on:
push:
branches: [ main ]
branches: [ main, develop ]
pull_request:
branches: [ develop ]

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
Expand All @@ -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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
21 changes: 1 addition & 20 deletions src/command_buffer.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -427,23 +427,4 @@ impl CommandBuffer {
pub fn get_data(&self, param_name: cl_command_buffer_info_khr) -> Result<Vec<u8>> {
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<cl_command_buffer_khr> {
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,
)?)
}
}
48 changes: 4 additions & 44 deletions src/command_queue.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<Event> {
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<Event> {
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(
Expand Down Expand Up @@ -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],
Expand All @@ -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 {
Expand Down
39 changes: 18 additions & 21 deletions src/context.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -54,7 +56,7 @@ pub fn get_current_device_for_gl_context_khr(
) -> Result<cl_device_id> {
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)
}
Expand All @@ -71,7 +73,7 @@ pub fn get_devices_for_gl_context_khr(
) -> Result<Vec<cl_device_id>> {
let dev_ptrs: Vec<intptr_t> = 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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)?)
}

Expand All @@ -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<cl_event> {
pub fn create_event_from_gl_sync_khr(&self, sync: gl::cl_GLsync) -> Result<cl_event> {
Ok(gl::create_event_from_gl_sync_khr(self.context, sync)?)
}

Expand All @@ -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,
Expand Down Expand Up @@ -361,14 +363,14 @@ impl Context {
image_type: cl_mem_object_type,
plane: cl_uint,
) -> Result<Vec<cl_uint>> {
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")]
Expand All @@ -377,11 +379,9 @@ impl Context {
flags: cl_mem_flags,
image_type: cl_mem_object_type,
) -> Result<Vec<cl_uint>> {
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")]
Expand All @@ -391,12 +391,9 @@ impl Context {
image_type: cl_mem_object_type,
plane: cl_uint,
) -> Result<Vec<cl_uint>> {
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)
}?)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/device.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand Down
13 changes: 6 additions & 7 deletions src/kernel.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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<size_t> {
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::<c_void>(),
)?)
}

Expand All @@ -299,7 +298,7 @@ impl Kernel {
global_work_offset: *const size_t,
global_work_size: *const size_t,
) -> Result<size_t> {
Ok(get_kernel_suggested_local_work_size_khr(
Ok(ext::get_kernel_suggested_local_work_size_khr(
command_queue,
self.kernel,
work_dim,
Expand Down
6 changes: 4 additions & 2 deletions src/platform.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit f8cb228

Please sign in to comment.