Skip to content

Commit

Permalink
Add new methods for issue #64
Browse files Browse the repository at this point in the history
  • Loading branch information
kenba committed Nov 5, 2023
1 parent 2ccaa9f commit 851f478
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ cl_arm_shared_virtual_memory = ["cl3/cl_arm_shared_virtual_memory"]
cl_intel_accelerator = ["cl3/cl_intel_accelerator"]
cl_intel_unified_shared_memory = ["cl3/cl_intel_unified_shared_memory"]
cl_intel_create_buffer_with_properties = ["cl3/cl_intel_create_buffer_with_properties"]
cl_intel_program_scope_host_pipe = ["cl3/cl_intel_program_scope_host_pipe"]
cl_ext_image_requirements_info = ["cl3/cl_ext_image_requirements_info"]
cl_khr_command_buffer = ["cl3/cl_khr_command_buffer"]
cl_khr_command_buffer_multi_device = ["cl3/cl_khr_command_buffer_multi_device"]
cl_khr_command_buffer_mutable_dispatch = ["cl3/cl_khr_command_buffer_mutable_dispatch"]

cl_khr_gl_sharing = ["cl3/cl_khr_gl_sharing"]
Expand Down
88 changes: 78 additions & 10 deletions src/command_buffer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-2022 Via Technology Ltd.
// Copyright (c) 2021-2023 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 @@ -22,16 +22,17 @@ use super::Result;

#[allow(unused_imports)]
use cl3::ext::{
cl_command_buffer_info_khr, cl_command_buffer_khr, cl_command_buffer_properties_khr,
cl_ndrange_kernel_command_properties_khr, cl_sync_point_khr,
cl_bool, cl_command_buffer_info_khr, cl_command_buffer_khr, cl_command_buffer_properties_khr,
cl_mutable_command_khr, cl_ndrange_kernel_command_properties_khr, cl_sync_point_khr,
command_barrier_with_wait_list_khr, command_copy_buffer_khr, command_copy_buffer_rect_khr,
command_copy_buffer_to_image_khr, command_copy_image_khr, command_copy_image_to_buffer_khr,
command_fill_buffer_khr, command_fill_image_khr, command_nd_range_kernel_khr,
create_command_buffer_khr, enqueue_command_buffer_khr, finalize_command_buffer_khr,
get_command_buffer_data_khr, get_command_buffer_info_khr, release_command_buffer_khr,
CL_COMMAND_BUFFER_NUM_QUEUES_KHR, CL_COMMAND_BUFFER_PROPERTIES_ARRAY_KHR,
CL_COMMAND_BUFFER_QUEUES_KHR, CL_COMMAND_BUFFER_REFERENCE_COUNT_KHR,
CL_COMMAND_BUFFER_STATE_KHR,
command_svm_mem_fill_khr, command_svm_memcpy_khr, create_command_buffer_khr,
enqueue_command_buffer_khr, finalize_command_buffer_khr, get_command_buffer_data_khr,
get_command_buffer_info_khr, get_command_buffer_mutable_dispatch_data,
release_command_buffer_khr, CL_COMMAND_BUFFER_NUM_QUEUES_KHR,
CL_COMMAND_BUFFER_PROPERTIES_ARRAY_KHR, CL_COMMAND_BUFFER_QUEUES_KHR,
CL_COMMAND_BUFFER_REFERENCE_COUNT_KHR, CL_COMMAND_BUFFER_STATE_KHR,
};
#[allow(unused_imports)]
use cl3::types::{cl_command_queue, cl_event, cl_kernel, cl_mem, cl_uint};
Expand Down Expand Up @@ -110,7 +111,7 @@ impl CommandBuffer {
}

/// Records a barrier operation used as a synchronization point.
pub fn command_barrier_with_wait_list(
pub unsafe fn command_barrier_with_wait_list(
&self,
queue: cl_command_queue,
sync_point_wait_list: &[cl_sync_point_khr],
Expand Down Expand Up @@ -287,7 +288,7 @@ impl CommandBuffer {
queue,
buffer.get_mut(),
pattern.as_ptr() as cl_mem,
pattern.len() * mem::size_of::<T>(),
mem::size_of_val(pattern),
offset,
size,
sync_point_wait_list,
Expand Down Expand Up @@ -351,6 +352,54 @@ impl CommandBuffer {
Ok(sync_point)
}

pub unsafe fn svm_memcpy(
&self,
queue: cl_command_queue,
dst_ptr: *mut c_void,
src_ptr: *const c_void,
size: size_t,
sync_point_wait_list: &[cl_sync_point_khr],
mutable_handle: *mut cl_mutable_command_khr,
) -> Result<cl_sync_point_khr> {
let mut sync_point = 0;
command_svm_memcpy_khr(
self.buffer,
queue,
dst_ptr,
src_ptr,
size,
sync_point_wait_list,
&mut sync_point,
mutable_handle,
)?;
Ok(sync_point)
}

pub unsafe fn svm_mem_fill(
&self,
queue: cl_command_queue,
svm_ptr: *mut c_void,
pattern: *const c_void,
pattern_size: size_t,
size: size_t,
sync_point_wait_list: &[cl_sync_point_khr],
mutable_handle: *mut cl_mutable_command_khr,
) -> Result<cl_sync_point_khr> {
let mut sync_point = 0;
command_svm_mem_fill_khr(
self.buffer,
queue,
svm_ptr,
pattern,
pattern_size,
size,
sync_point_wait_list,
&mut sync_point,
mutable_handle,
)?;
Ok(sync_point)
}

pub fn num_queues(&self) -> Result<cl_uint> {
Ok(get_command_buffer_info_khr(self.buffer, CL_COMMAND_BUFFER_NUM_QUEUES_KHR)?.into())
}
Expand Down Expand Up @@ -378,4 +427,23 @@ 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,
)?)
}
}
59 changes: 58 additions & 1 deletion src/command_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ use cl3::egl;
#[allow(unused_imports)]
use cl3::ext;
use cl3::gl;
use libc::{c_void, size_t};
#[allow(unused_imports)]
use cl3::types::cl_program;
#[allow(unused_imports)]
use libc::{c_char, c_void, size_t};
use std::mem;
use std::ptr;

Expand Down Expand Up @@ -1333,6 +1336,60 @@ impl CommandQueue {
Ok(Event::new(event))
}

#[cfg(feature = "cl_intel_program_scope_host_pipe")]
pub unsafe fn enqueue_read_host_pipe_intel(
&self,
program: cl_program,
pipe_symbol: *const c_char,
blocking_read: cl_bool,
ptr: *mut c_void,
size: size_t,
event_wait_list: &[cl_event],
) -> Result<Event> {
let event = ext::enqueue_read_host_pipe_intel(
self.queue,
program,
pipe_symbol,
blocking_read,
ptr,
size,
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_program_scope_host_pipe")]
pub unsafe fn enqueue_write_host_pipe_intel(
&self,
program: cl_program,
pipe_symbol: *const c_char,
blocking_write: cl_bool,
ptr: *const c_void,
size: size_t,
event_wait_list: &[cl_event],
) -> Result<Event> {
let event = ext::enqueue_write_host_pipe_intel(
self.queue,
program,
pipe_symbol,
blocking_write,
ptr,
size,
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))
}

pub fn context(&self) -> Result<cl_context> {
Ok(isize::from(get_command_queue_info(self.queue, CL_QUEUE_CONTEXT)?) as cl_context)
}
Expand Down

0 comments on commit 851f478

Please sign in to comment.