Struct Device

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

Implementations§

Source§

impl Device

Source

pub fn new(device_id: ClDeviceID) -> Device

Source§

impl Device

Source

pub fn low_level_device(&self) -> &ClDeviceID

Examples found in repository?
examples/simple_add/main.rs (line 35)
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 list_devices_by_type( platform: &Platform, device_type: DeviceType, ) -> Output<Vec<Device>>

Source

pub fn list_default_devices(platform: &Platform) -> Output<Vec<Device>>

Source

pub fn list_all_devices(platform: &Platform) -> Output<Vec<Device>>

Examples found in repository?
examples/simple_add/main.rs (line 24)
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 list_cpu_devices(platform: &Platform) -> Output<Vec<Device>>

Source

pub fn list_gpu_devices(platform: &Platform) -> Output<Vec<Device>>

Source

pub fn list_accelerator_devices(platform: &Platform) -> Output<Vec<Device>>

Source

pub fn list_custom_devices(platform: &Platform) -> Output<Vec<Device>>

Trait Implementations§

Source§

impl Clone for Device

Source§

fn clone(&self) -> Device

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 Device

Source§

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

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

impl DevicePtr for Device

Source§

unsafe fn device_ptr(&self) -> cl_device_id

Source§

fn is_usable(&self) -> bool

Source§

fn usability_check(&self) -> Result<(), Error>

Source§

fn global_mem_cacheline_size(&self) -> Result<u32, Error>

Source§

fn native_vector_width_double(&self) -> Result<u32, Error>

Source§

fn native_vector_width_half(&self) -> Result<u32, Error>

Source§

fn address_bits(&self) -> Result<u32, Error>

Source§

fn max_clock_frequency(&self) -> Result<u32, Error>

Source§

fn max_compute_units(&self) -> Result<u32, Error>

Source§

fn max_constant_args(&self) -> Result<u32, Error>

Source§

fn max_read_image_args(&self) -> Result<u32, Error>

Source§

fn max_samplers(&self) -> Result<u32, Error>

Source§

fn max_work_item_dimensions(&self) -> Result<u32, Error>

Source§

fn max_write_image_args(&self) -> Result<u32, Error>

Source§

fn mem_base_addr_align(&self) -> Result<u32, Error>

Source§

fn min_data_type_align_size(&self) -> Result<u32, Error>

Source§

fn native_vector_width_char(&self) -> Result<u32, Error>

Source§

fn native_vector_width_short(&self) -> Result<u32, Error>

Source§

fn native_vector_width_int(&self) -> Result<u32, Error>

Source§

fn native_vector_width_long(&self) -> Result<u32, Error>

Source§

fn native_vector_width_float(&self) -> Result<u32, Error>

Source§

fn partition_max_sub_devices(&self) -> Result<u32, Error>

Source§

fn preferred_vector_width_char(&self) -> Result<u32, Error>

Source§

fn preferred_vector_width_short(&self) -> Result<u32, Error>

Source§

fn preferred_vector_width_int(&self) -> Result<u32, Error>

Source§

fn preferred_vector_width_long(&self) -> Result<u32, Error>

Source§

fn preferred_vector_width_float(&self) -> Result<u32, Error>

Source§

fn preferred_vector_width_double(&self) -> Result<u32, Error>

Source§

fn preferred_vector_width_half(&self) -> Result<u32, Error>

Source§

fn vendor_id(&self) -> Result<u32, Error>

Source§

fn available(&self) -> Result<bool, Error>

Source§

fn compiler_available(&self) -> Result<bool, Error>

Source§

fn endian_little(&self) -> Result<bool, Error>

Source§

fn error_correction_support(&self) -> Result<bool, Error>

Source§

fn host_unified_memory(&self) -> Result<bool, Error>

Source§

fn image_support(&self) -> Result<bool, Error>

Source§

fn linker_available(&self) -> Result<bool, Error>

Source§

fn preferred_interop_user_sync(&self) -> Result<bool, Error>

Source§

fn name(&self) -> Result<String, Error>

Source§

fn opencl_c_version(&self) -> Result<String, Error>

Source§

fn profile(&self) -> Result<String, Error>

Source§

fn vendor(&self) -> Result<String, Error>

Source§

fn version(&self) -> Result<String, Error>

Source§

fn driver_version(&self) -> Result<String, Error>

Source§

fn global_mem_cache_size(&self) -> Result<u64, Error>

Source§

fn global_mem_size(&self) -> Result<u64, Error>

Source§

fn local_mem_size(&self) -> Result<u64, Error>

Source§

fn max_constant_buffer_size(&self) -> Result<u64, Error>

Source§

fn max_mem_alloc_size(&self) -> Result<u64, Error>

Source§

fn image2d_max_width(&self) -> Result<usize, Error>

Source§

fn image2d_max_height(&self) -> Result<usize, Error>

Source§

fn image3d_max_width(&self) -> Result<usize, Error>

Source§

fn image3d_max_height(&self) -> Result<usize, Error>

Source§

fn image3d_max_depth(&self) -> Result<usize, Error>

Source§

fn image_max_buffer_size(&self) -> Result<usize, Error>

Source§

fn image_max_array_size(&self) -> Result<usize, Error>

Source§

fn max_parameter_size(&self) -> Result<usize, Error>

Source§

fn max_work_group_size(&self) -> Result<usize, Error>

Source§

fn printf_buffer_size(&self) -> Result<usize, Error>

Source§

fn profiling_timer_resolution(&self) -> Result<usize, Error>

Source§

fn max_work_item_sizes(&self) -> Result<Vec<usize>, Error>

Source§

fn local_mem_type(&self) -> Result<DeviceLocalMemType, Error>

Source§

fn execution_capabilities(&self) -> Result<DeviceExecCapabilities, Error>

Source§

fn global_mem_cache_type(&self) -> Result<DeviceMemCacheType, Error>

Source§

fn partition_affinity_domain(&self) -> Result<DeviceAffinityDomain, Error>

Source§

fn device_type(&self) -> Result<DeviceType, Error>

Source§

impl Drop for Device

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PartialEq for Device

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 Eq for Device

Source§

impl Send for Device

Source§

impl Sync for Device

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.