pub struct UnboundKernel(/* private fields */);Expand description
An OpenCL kernel, with arguments not yet set
Implementations§
Source§impl UnboundKernel
impl UnboundKernel
Sourcepub fn bind_arguments<T: KernelArgList>(self, arguments: T) -> Result<Kernel<T>>
pub fn bind_arguments<T: KernelArgList>(self, arguments: T) -> Result<Kernel<T>>
Bind arguments to this kernel, performing type checks and calling
clSetKernelArg to set values.
When OpenCL 1.2+ features are available, this call will attempt to check
the type of each argument before each call to clSetKernelArg. If the
types appear to be incompatible, as determined by
KernelArg::is_param_type_compatible, it will panic. If this behavior
isn’t desired, bind_arguments_unchecked can be used instead.
Examples found in repository?
examples/basic.rs (line 75)
18pub fn main() {
19 let version = load_opencl().unwrap();
20 println!("Successfully loaded OpenCL (compat level {:?})", version);
21
22 for platform in Platform::get_platforms().unwrap() {
23 println!("Got platform {:#?}", platform);
24
25 for device in platform.get_devices(DeviceType::ALL).unwrap() {
26 println!("Got device: {:#?}", device);
27
28 let ctx = device.create_context().unwrap();
29
30 println!("Created context: {:#?}", ctx);
31
32 let mut queue = QueueBuilder::new(&ctx, &device).build().unwrap();
33
34 println!("Created command queue: {:#?}", queue);
35
36 let program = ProgramBuilder::with_source(&ctx, &KERNEL).build().unwrap();
37
38 println!(
39 "Compiled program: {:?} {:?}",
40 program,
41 program.kernel_names()
42 );
43
44 let build_info = program.build_info(device).unwrap();
45 println!("Build info: {:#?}", build_info);
46
47 let a = ctx
48 .buffer_builder()
49 .host_access::<HostNoAccess>()
50 .device_access::<DeviceReadOnly>()
51 .build_copying_slice(&[1, 2, 3])
52 .unwrap();
53
54 let b = ctx
55 .buffer_builder()
56 .host_access::<HostNoAccess>()
57 .device_access::<DeviceReadOnly>()
58 .build_copying_slice(&[1, 2, 3])
59 .unwrap();
60
61 let c = ctx
62 .buffer_builder()
63 .host_access::<HostReadOnly>()
64 .device_access::<DeviceWriteOnly>()
65 .build_with_size::<i32>(3)
66 .unwrap();
67
68 let args = (a, b, c);
69
70 println!("Created arguments: {:#?}", args);
71
72 let mut kernel = program
73 .create_kernel(&CString::new("sum").unwrap())
74 .unwrap()
75 .bind_arguments(args)
76 .unwrap();
77
78 println!("Created and bound kernel: {:#?}", kernel);
79
80 queue.kernel_cmd(&mut kernel).exec_ndrange(3).unwrap();
81
82 let mut data = [0i32; 3];
83 queue
84 .buffer_cmd(&mut kernel.arguments().2)
85 .read(&mut data)
86 .unwrap();
87
88 println!("Kernel output: {:?}", data);
89
90 assert_eq!(data, [2, 4, 6]);
91 }
92
93 platform.unload_compiler().unwrap();
94
95 println!(
96 "Unloaded compiler for platform {}",
97 platform.name().unwrap().to_string_lossy()
98 );
99 }
100}Sourcepub fn bind_arguments_unchecked<T: KernelArgList>(
self,
arguments: T,
) -> Result<Kernel<T>>
pub fn bind_arguments_unchecked<T: KernelArgList>( self, arguments: T, ) -> Result<Kernel<T>>
Bind arguments to this kernel, without performing assertions for number or type of arguments.
§Safety
This function is not unsafe in terms of memory safety, but it should still be used with care, as it can lead to unexpected results if the argument types don’t match those of the OpenCL code.
pub fn raw(&self) -> cl_kernel
Trait Implementations§
Source§impl Debug for UnboundKernel
impl Debug for UnboundKernel
Source§impl Drop for UnboundKernel
impl Drop for UnboundKernel
Source§impl Hash for UnboundKernel
impl Hash for UnboundKernel
Source§impl KernelInfo for UnboundKernel
impl KernelInfo for UnboundKernel
Source§fn as_unbound(&self) -> &UnboundKernel
fn as_unbound(&self) -> &UnboundKernel
Get a reference to the unbound form of this kernel
fn function_name(&self) -> Result<CString>
fn num_args(&self) -> Result<cl_uint>
fn reference_count(&self) -> Result<cl_uint>
fn context_raw(&self) -> Result<cl_context>
fn program_raw(&self) -> Result<cl_program>
fn attributes(&self) -> Result<CString>
fn info_fmt(&self, f: &mut Formatter<'_>) -> Result
fn arg_info(&self, idx: cl_uint) -> KernelArgInfo<'_>
Source§impl PartialEq for UnboundKernel
impl PartialEq for UnboundKernel
impl Eq for UnboundKernel
impl Send for UnboundKernel
impl StructuralPartialEq for UnboundKernel
Auto Trait Implementations§
impl Freeze for UnboundKernel
impl RefUnwindSafe for UnboundKernel
impl !Sync for UnboundKernel
impl Unpin for UnboundKernel
impl UnsafeUnpin for UnboundKernel
impl UnwindSafe for UnboundKernel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> OclInfo for Twhere
T: OclInfoInternal,
impl<T> OclInfo for Twhere
T: OclInfoInternal,
Source§fn get_info_raw(&self, param_name: Self::Param) -> Result<Vec<u8>>
fn get_info_raw(&self, param_name: Self::Param) -> Result<Vec<u8>>
Get raw binary info from OpenCL about this object. Read more
Source§fn get_info_raw_sized<L: ArrayLength<u8>>(
&self,
param_name: Self::Param,
) -> Result<GenericArray<u8, L>>
fn get_info_raw_sized<L: ArrayLength<u8>>( &self, param_name: Self::Param, ) -> Result<GenericArray<u8, L>>
Get raw binary info from OpenCL about this object, with a constant size. Read more