Struct Buffer

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

Implementations§

Source§

impl Buffer

Source

pub fn new(ll_mem: ClMem, context: Context) -> Buffer

Source

pub fn create<T: ClNumber, B: BufferCreator<T>>( context: &Context, creator: B, host_access: HostAccess, kernel_access: KernelAccess, mem_location: MemLocation, ) -> Output<Buffer>

Source

pub fn create_with_len<T: ClNumber>( context: &Context, len: usize, ) -> Output<Buffer>

Examples found in repository?
examples/simple_add/main.rs (line 61)
14fn run_procedural() {
15    let src = include_str!("simple_add.ocl");
16
17    let mut platforms = Platform::list_all().unwrap();
18
19    if platforms.len() == 0 {
20        panic!("No platforms found!!!");
21    }
22
23    let platform = platforms.remove(0);
24    let devices = Device::list_all_devices(&platform).unwrap();
25
26    if devices.len() == 0 {
27        panic!("No devices found!!!");
28    }
29    let context = Context::create(&devices[..]).unwrap();
30
31    println!("creating program...");
32    let unbuilt_program: UnbuiltProgram =
33        UnbuiltProgram::create_with_source(&context, src).unwrap();
34
35    let names = devices.iter().map(|d| d.low_level_device().name().unwrap());
36    println!("building program on devices {:?}...", names);
37
38    let program: Program = unbuilt_program
39        .build(&devices[..])
40        .unwrap_or_else(|e| panic!("Failed to build program {:?}", e));
41
42    for device in devices[0..1].iter() {
43        let program2 = (&program).clone();
44        let r_count = program2.low_level_program().reference_count().unwrap();
45        let prog_log = program2.low_level_program().get_log(device).unwrap();
46        let prog_src = program2.low_level_program().source().unwrap();
47        println!("Program log {:?} {:?}, {:?}", r_count, prog_log, prog_src);
48        println!("Device {:?}", device);
49
50        let command_queue: CommandQueue = CommandQueue::create(&context, device, None).unwrap();
51
52        let vec_a = vec![1i64, 2, 3];
53        let vec_b = vec![0i64, -1, -2];
54
55        let len = vec_a.len();
56
57        let work: Work = Work::new(len);
58        let name = device.name().unwrap();
59        println!("{}", name);
60
61        let mem_a = Buffer::create_with_len::<i64>(&context, len).unwrap();
62        let mem_b = Buffer::create_with_len::<i64>(&context, len).unwrap();
63        let mem_c = Buffer::create_with_len::<i64>(&context, len).unwrap();
64    
65        println!("Creating kernel simple_add");
66        let simple_add = Kernel::create(&program2, "simple_add").unwrap();
67
68        println!("writing buffer a...");
69        let _write_event_a = command_queue.write_buffer(&mem_a, &vec_a, None).unwrap();
70
71        println!("writing buffer b...");
72        let _write_event_b = command_queue.write_buffer(&mem_b, &vec_b, None).unwrap();
73
74        println!("mem_a {:?}", mem_a);
75
76        let mut lock_a = mem_a.write_lock();
77        println!("setting simple_add arg 0 as mem_a");
78        unsafe { simple_add.set_arg(0, &mut *lock_a).unwrap() };
79
80        let mut lock_b = mem_b.write_lock();
81        println!("setting simple_add arg 1 as mem_b");
82        unsafe { simple_add.set_arg(1, &mut *lock_b).unwrap() };
83
84        let mut lock_c = mem_c.write_lock();
85        println!("setting simple_add mut arg 2 as mem_c");
86        unsafe { simple_add.set_arg(2, &mut *lock_c).unwrap() };
87
88        println!("calling enqueue_kernel on simple_add");
89        let () = command_queue
90            .enqueue_kernel(simple_add, &work, None)
91            .unwrap();
92
93        println!("Dropping locks...");
94        std::mem::drop(lock_a);
95        std::mem::drop(lock_b);
96        std::mem::drop(lock_c);
97
98        println!("done putting event into WaitList...");
99        let mut vec_c: Vec<i64> = vec![0; len];
100
101        let _read_event = command_queue.read_buffer(&mem_c, &mut vec_c, None).unwrap();
102
103        println!("  {}", string_from_slice(&vec_a[..]));
104        println!("+ {}", string_from_slice(&vec_b[..]));
105        println!("= {}", string_from_slice(&vec_c[..]));
106    }
107}
Source

pub fn create_from_slice<T: ClNumber>( context: &Context, data: &[T], ) -> Output<Buffer>

Source

pub fn create_from<T: ClNumber, B: BufferCreator<T>>( context: &Context, creator: B, ) -> Output<Buffer>

Source

pub fn create_with_config<T: ClNumber, B: BufferCreator<T>>( context: &Context, creator: B, mem_config: MemConfig, ) -> Output<Buffer>

Source

pub fn create_from_low_level_context<T: ClNumber, B: BufferCreator<T>>( ll_context: &ClContext, creator: B, host_access: HostAccess, kernel_access: KernelAccess, mem_location: MemLocation, ) -> Output<Buffer>

Source

pub fn read_lock(&self) -> RwLockReadGuard<'_, ClMem>

Source

pub fn write_lock(&self) -> RwLockWriteGuard<'_, ClMem>

Examples found in repository?
examples/simple_add/main.rs (line 76)
14fn run_procedural() {
15    let src = include_str!("simple_add.ocl");
16
17    let mut platforms = Platform::list_all().unwrap();
18
19    if platforms.len() == 0 {
20        panic!("No platforms found!!!");
21    }
22
23    let platform = platforms.remove(0);
24    let devices = Device::list_all_devices(&platform).unwrap();
25
26    if devices.len() == 0 {
27        panic!("No devices found!!!");
28    }
29    let context = Context::create(&devices[..]).unwrap();
30
31    println!("creating program...");
32    let unbuilt_program: UnbuiltProgram =
33        UnbuiltProgram::create_with_source(&context, src).unwrap();
34
35    let names = devices.iter().map(|d| d.low_level_device().name().unwrap());
36    println!("building program on devices {:?}...", names);
37
38    let program: Program = unbuilt_program
39        .build(&devices[..])
40        .unwrap_or_else(|e| panic!("Failed to build program {:?}", e));
41
42    for device in devices[0..1].iter() {
43        let program2 = (&program).clone();
44        let r_count = program2.low_level_program().reference_count().unwrap();
45        let prog_log = program2.low_level_program().get_log(device).unwrap();
46        let prog_src = program2.low_level_program().source().unwrap();
47        println!("Program log {:?} {:?}, {:?}", r_count, prog_log, prog_src);
48        println!("Device {:?}", device);
49
50        let command_queue: CommandQueue = CommandQueue::create(&context, device, None).unwrap();
51
52        let vec_a = vec![1i64, 2, 3];
53        let vec_b = vec![0i64, -1, -2];
54
55        let len = vec_a.len();
56
57        let work: Work = Work::new(len);
58        let name = device.name().unwrap();
59        println!("{}", name);
60
61        let mem_a = Buffer::create_with_len::<i64>(&context, len).unwrap();
62        let mem_b = Buffer::create_with_len::<i64>(&context, len).unwrap();
63        let mem_c = Buffer::create_with_len::<i64>(&context, len).unwrap();
64    
65        println!("Creating kernel simple_add");
66        let simple_add = Kernel::create(&program2, "simple_add").unwrap();
67
68        println!("writing buffer a...");
69        let _write_event_a = command_queue.write_buffer(&mem_a, &vec_a, None).unwrap();
70
71        println!("writing buffer b...");
72        let _write_event_b = command_queue.write_buffer(&mem_b, &vec_b, None).unwrap();
73
74        println!("mem_a {:?}", mem_a);
75
76        let mut lock_a = mem_a.write_lock();
77        println!("setting simple_add arg 0 as mem_a");
78        unsafe { simple_add.set_arg(0, &mut *lock_a).unwrap() };
79
80        let mut lock_b = mem_b.write_lock();
81        println!("setting simple_add arg 1 as mem_b");
82        unsafe { simple_add.set_arg(1, &mut *lock_b).unwrap() };
83
84        let mut lock_c = mem_c.write_lock();
85        println!("setting simple_add mut arg 2 as mem_c");
86        unsafe { simple_add.set_arg(2, &mut *lock_c).unwrap() };
87
88        println!("calling enqueue_kernel on simple_add");
89        let () = command_queue
90            .enqueue_kernel(simple_add, &work, None)
91            .unwrap();
92
93        println!("Dropping locks...");
94        std::mem::drop(lock_a);
95        std::mem::drop(lock_b);
96        std::mem::drop(lock_c);
97
98        println!("done putting event into WaitList...");
99        let mut vec_c: Vec<i64> = vec![0; len];
100
101        let _read_event = command_queue.read_buffer(&mem_c, &mut vec_c, None).unwrap();
102
103        println!("  {}", string_from_slice(&vec_a[..]));
104        println!("+ {}", string_from_slice(&vec_b[..]));
105        println!("= {}", string_from_slice(&vec_c[..]));
106    }
107}
Source

pub fn context(&self) -> &Context

Source

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

Source

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

Source

pub fn length(&self) -> Output<usize>

A non-panicking version of len.

Source

pub fn len(&self) -> usize

A method for getting the len of the device memory buffer. Panics if the buffer size info returns an error.

Source

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

Source

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

Trait Implementations§

Source§

impl Clone for Buffer

Source§

fn clone(&self) -> Buffer

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Buffer

Source§

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

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

impl NumberTyped for Buffer

Source§

impl PartialEq for Buffer

Source§

fn eq(&self, other: &Self) -> 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<'a, T: ClNumber> ToKernelOpArg<'a, T> for &'a Buffer

Source§

impl Send for Buffer

Source§

impl Sync for Buffer

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.