Struct ClMem

Source
pub struct ClMem { /* private fields */ }

Implementations§

Source§

impl ClMem

Source

pub unsafe fn new<T: ClNumber>(object: cl_mem) -> Output<ClMem>

Instantiates a new ClMem of type T.

§Safety

This function does not retain its cl_mem, but will release its cl_mem when it is dropped. Mismanagement of a cl_mem’s lifetime. Therefore, this function is unsafe.

Source

pub fn create<T: ClNumber, B: BufferCreator<T>>( context: &ClContext, buffer_creator: B, host_access: HostAccess, kernel_access: KernelAccess, mem_location: MemLocation, ) -> Output<ClMem>

Examples found in repository?
examples/ll_simple_add/main.rs (lines 60-66)
12fn run_procedural() {
13    unsafe {
14        let src = include_str!("simple_add.ocl");
15
16        let mut platforms = list_platforms().unwrap();
17
18        if platforms.len() == 0 {
19            panic!("No platforms found!!!");
20        }
21
22        let platform = platforms.remove(0);
23        let devices = list_devices_by_type(&platform, DeviceType::ALL).unwrap();
24
25        if devices.len() == 0 {
26            panic!("No devices found!!!");
27        }
28        let context = ClContext::create(&devices[..]).unwrap();
29
30        println!("creating program...");
31        let mut program: ClProgram = ClProgram::create_with_source(&context, src).unwrap();
32
33        let names = devices.iter().map(|d| d.name().unwrap());
34        println!("building program on devices {:?}...", names);
35
36        let () = program
37            .build(&devices[..])
38            .unwrap_or_else(|e| panic!("Failed to build program {:?}", e));
39
40        for device in devices[0..1].iter() {
41            let program2 = (&program).clone();
42            let r_count = program2.reference_count().unwrap();
43            let prog_log = program2.get_log(device).unwrap();
44            let prog_src = program2.source().unwrap();
45            println!("Program log {:?} {:?}, {:?}", r_count, prog_log, prog_src);
46            println!("Device {:?}", device);
47
48            let mut command_queue: ClCommandQueue =
49                ClCommandQueue::create(&context, device, None).unwrap();
50
51            let vec_a = vec![1i64, 2, 3];
52            let vec_b = vec![0i64, -1, -2];
53
54            let len = vec_a.len();
55
56            let work: Work = Work::new(len);
57            let name = device.name().unwrap();
58            println!("{}", name);
59
60            let mut mem_a = ClMem::create::<i64, usize>(
61                &context,
62                len,
63                HostAccess::WriteOnly,
64                KernelAccess::ReadOnly,
65                MemLocation::AllocOnDevice,
66            )
67            .unwrap();
68            let mut mem_b = ClMem::create::<i64, usize>(
69                &context,
70                len,
71                HostAccess::WriteOnly,
72                KernelAccess::ReadOnly,
73                MemLocation::AllocOnDevice,
74            )
75            .unwrap();
76            let mut mem_c = ClMem::create::<i64, usize>(
77                &context,
78                len,
79                HostAccess::ReadOnly,
80                KernelAccess::WriteOnly,
81                MemLocation::AllocOnDevice,
82            )
83            .unwrap();
84            println!("Creating kernel simple_add");
85            let mut simple_add = ClKernel::create(&program2, "simple_add").unwrap();
86
87            println!("writing buffer a...");
88            let _write_event_a = command_queue
89                .write_buffer(&mut mem_a, &vec_a[..], None)
90                .unwrap();
91
92            println!("writing buffer b...");
93            let _write_event_b = command_queue
94                .write_buffer(&mut mem_b, &vec_b[..], None)
95                .unwrap();
96
97            println!("mem_a {:?}", mem_a);
98
99            println!("setting simple_add arg 0 as mem_a");
100            simple_add.set_arg(0, &mut mem_a).unwrap();
101
102            println!("setting simple_add arg 1 as mem_b");
103            simple_add.set_arg(1, &mut mem_b).unwrap();
104
105            println!("setting simple_add mut arg 2 as mem_c");
106            simple_add.set_arg(2, &mut mem_c).unwrap();
107
108            println!("calling enqueue_kernel on simple_add");
109            let event = command_queue
110                .enqueue_kernel(&mut simple_add, &work, None)
111                .unwrap();
112            let () = event.wait().unwrap();
113            println!("done putting event into WaitList...");
114            let mut vec_c = vec![0i64; len];
115
116            let _read_event = command_queue
117                .read_buffer(&mem_c, &mut vec_c[..], None)
118                .unwrap();
119
120            println!("  {}", string_from_slice(&vec_a[..]));
121            println!("+ {}", string_from_slice(&vec_b[..]));
122            println!("= {}", string_from_slice(&vec_c[..]));
123        }
124    }
125}
Source

pub unsafe fn create_with_config<T: ClNumber, B: BufferCreator<T>>( context: &ClContext, buffer_creator: B, mem_config: MemConfig, ) -> Output<ClMem>

Created a device memory buffer given the context, the buffer creator and some config. There are some buffer creators that are not valid for some MemConfigs. However, a mismatch of type and configuration between a buffer creator and the MemConfig will, at worst, result in this function call returning an error.

§Safety

Using an invalid context in this function call is undefined behavior.

Trait Implementations§

Source§

impl Debug for ClMem

Source§

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

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

impl KernelArg for ClMem

Source§

fn kernel_arg_size(&self) -> usize

size_of or size_of * len
Source§

unsafe fn kernel_arg_ptr(&self) -> *const c_void

Source§

unsafe fn kernel_arg_mut_ptr(&mut self) -> *mut c_void

Source§

impl MemPtr for ClMem

Source§

unsafe fn mem_ptr(&self) -> cl_mem

Returns a copy to the cl_mem of the implementor. Read more
Source§

unsafe fn mem_ptr_ref(&self) -> &cl_mem

Returns a reference to the cl_mem of the implementor. Read more
Source§

unsafe fn get_info<I: Copy>(&self, flag: MemInfo) -> Output<ClPointer<I>>

Returns the ClPointer of the info type of a given MemInfo flag. Read more
Source§

unsafe fn len(&self) -> Output<usize>

Returns the len of the ClMem. Read more
Source§

unsafe fn is_empty(&self) -> Output<bool>

Determines if ClMem is empty or not. Read more
Source§

unsafe fn context(&self) -> Output<ClContext>

Returns the ClContext of the ClMem. Read more
Source§

unsafe fn reference_count(&self) -> Output<u32>

Returns the reference count info for the ClMem. Read more
Source§

unsafe fn size(&self) -> Output<usize>

Returns the size info for the ClMem. Read more
Source§

unsafe fn offset(&self) -> Output<usize>

Returns the offset info for the ClMem. Read more
Source§

unsafe fn flags(&self) -> Output<MemFlags>

Returns the MemFlag info for the ClMem. Read more
Source§

impl NumberTyped for ClMem

Source§

impl PartialEq for ClMem

Source§

fn eq(&self, other: &ClMem) -> 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 ClMem

Source§

impl Send for ClMem

Source§

impl StructuralPartialEq for ClMem

Auto Trait Implementations§

§

impl Freeze for ClMem

§

impl RefUnwindSafe for ClMem

§

impl !Sync for ClMem

§

impl Unpin for ClMem

§

impl UnwindSafe for ClMem

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