Skip to main content

Program

Struct Program 

Source
pub struct Program(/* private fields */);
Expand description

An OpenCL program

Implementations§

Source§

impl Program

Source

pub fn create_kernel(&self, name: &CStr) -> Result<UnboundKernel>

Create a kernel with a given name.

Examples found in repository?
examples/basic.rs (line 73)
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}
Source§

impl Program

Source

pub fn try_clone(&self) -> Result<Self>

Attempt to clone this program, using clRetainProgram to ensure the program is not released while a wrapper still exists.

Source

pub fn raw(&self) -> cl_program

Get the raw handle for this program. Note that this handle is only a raw pointer and does not use RAII to ensure validity, so you must manually make sure that it’s not released while still in use.

Source

pub fn reference_count(&self) -> Result<cl_uint>

Source

pub fn context_raw(&self) -> Result<cl_context>

Source

pub fn num_devices(&self) -> Result<cl_uint>

Source

pub fn source(&self) -> Result<CString>

Source

pub fn il(&self) -> Result<Vec<u8>>

Source

pub fn binary_sizes(&self) -> Result<Vec<size_t>>

Source

pub fn num_kernels(&self) -> Result<size_t>

Source

pub fn kernel_names(&self) -> Result<CString>

Examples found in repository?
examples/basic.rs (line 41)
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}
Source

pub fn scope_global_ctors_present(&self) -> Result<bool>

Source

pub fn scope_global_dtors_present(&self) -> Result<bool>

Source

pub fn build_info(&self, Device: Device) -> Result<ProgramBuildInfo<'_>>

Get program build info for a given device

Examples found in repository?
examples/basic.rs (line 44)
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}

Trait Implementations§

Source§

impl Debug for Program

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Program

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Hash for Program

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Program

Source§

fn eq(&self, other: &Program) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Program

Source§

impl Send for Program

Source§

impl StructuralPartialEq for Program

Source§

impl Sync for Program

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OclInfo for T
where T: OclInfoInternal,

Source§

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>>

Get raw binary info from OpenCL about this object, with a constant size. Read more
Source§

fn get_info<T: FromOclInfo>(&self, param_name: Self::Param) -> Result<T>
where Self: Sized,

Get information about this object from OpenCL. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.