pub struct Device { /* private fields */ }
Implementations§
Source§impl Device
impl Device
Sourcepub fn low_level_device(&self) -> &ClDeviceID
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}
pub fn list_devices_by_type( platform: &Platform, device_type: DeviceType, ) -> Output<Vec<Device>>
pub fn list_default_devices(platform: &Platform) -> Output<Vec<Device>>
Sourcepub fn list_all_devices(platform: &Platform) -> Output<Vec<Device>>
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}
pub fn list_cpu_devices(platform: &Platform) -> Output<Vec<Device>>
pub fn list_gpu_devices(platform: &Platform) -> Output<Vec<Device>>
pub fn list_accelerator_devices(platform: &Platform) -> Output<Vec<Device>>
pub fn list_custom_devices(platform: &Platform) -> Output<Vec<Device>>
Trait Implementations§
Source§impl DevicePtr for Device
impl DevicePtr for Device
unsafe fn device_ptr(&self) -> cl_device_id
fn is_usable(&self) -> bool
fn usability_check(&self) -> Result<(), Error>
fn global_mem_cacheline_size(&self) -> Result<u32, Error>
fn native_vector_width_double(&self) -> Result<u32, Error>
fn native_vector_width_half(&self) -> Result<u32, Error>
fn address_bits(&self) -> Result<u32, Error>
fn max_clock_frequency(&self) -> Result<u32, Error>
fn max_compute_units(&self) -> Result<u32, Error>
fn max_constant_args(&self) -> Result<u32, Error>
fn max_read_image_args(&self) -> Result<u32, Error>
fn max_samplers(&self) -> Result<u32, Error>
fn max_work_item_dimensions(&self) -> Result<u32, Error>
fn max_write_image_args(&self) -> Result<u32, Error>
fn mem_base_addr_align(&self) -> Result<u32, Error>
fn min_data_type_align_size(&self) -> Result<u32, Error>
fn native_vector_width_char(&self) -> Result<u32, Error>
fn native_vector_width_short(&self) -> Result<u32, Error>
fn native_vector_width_int(&self) -> Result<u32, Error>
fn native_vector_width_long(&self) -> Result<u32, Error>
fn native_vector_width_float(&self) -> Result<u32, Error>
fn partition_max_sub_devices(&self) -> Result<u32, Error>
fn preferred_vector_width_char(&self) -> Result<u32, Error>
fn preferred_vector_width_short(&self) -> Result<u32, Error>
fn preferred_vector_width_int(&self) -> Result<u32, Error>
fn preferred_vector_width_long(&self) -> Result<u32, Error>
fn preferred_vector_width_float(&self) -> Result<u32, Error>
fn preferred_vector_width_double(&self) -> Result<u32, Error>
fn preferred_vector_width_half(&self) -> Result<u32, Error>
fn vendor_id(&self) -> Result<u32, Error>
fn available(&self) -> Result<bool, Error>
fn compiler_available(&self) -> Result<bool, Error>
fn endian_little(&self) -> Result<bool, Error>
fn error_correction_support(&self) -> Result<bool, Error>
fn host_unified_memory(&self) -> Result<bool, Error>
fn image_support(&self) -> Result<bool, Error>
fn linker_available(&self) -> Result<bool, Error>
fn preferred_interop_user_sync(&self) -> Result<bool, Error>
fn name(&self) -> Result<String, Error>
fn opencl_c_version(&self) -> Result<String, Error>
fn profile(&self) -> Result<String, Error>
fn vendor(&self) -> Result<String, Error>
fn version(&self) -> Result<String, Error>
fn driver_version(&self) -> Result<String, Error>
fn global_mem_cache_size(&self) -> Result<u64, Error>
fn global_mem_size(&self) -> Result<u64, Error>
fn local_mem_size(&self) -> Result<u64, Error>
fn max_constant_buffer_size(&self) -> Result<u64, Error>
fn max_mem_alloc_size(&self) -> Result<u64, Error>
fn image2d_max_width(&self) -> Result<usize, Error>
fn image2d_max_height(&self) -> Result<usize, Error>
fn image3d_max_width(&self) -> Result<usize, Error>
fn image3d_max_height(&self) -> Result<usize, Error>
fn image3d_max_depth(&self) -> Result<usize, Error>
fn image_max_buffer_size(&self) -> Result<usize, Error>
fn image_max_array_size(&self) -> Result<usize, Error>
fn max_parameter_size(&self) -> Result<usize, Error>
fn max_work_group_size(&self) -> Result<usize, Error>
fn printf_buffer_size(&self) -> Result<usize, Error>
fn profiling_timer_resolution(&self) -> Result<usize, Error>
fn max_work_item_sizes(&self) -> Result<Vec<usize>, Error>
fn local_mem_type(&self) -> Result<DeviceLocalMemType, Error>
fn execution_capabilities(&self) -> Result<DeviceExecCapabilities, Error>
fn global_mem_cache_type(&self) -> Result<DeviceMemCacheType, Error>
fn partition_affinity_domain(&self) -> Result<DeviceAffinityDomain, Error>
fn device_type(&self) -> Result<DeviceType, Error>
impl Eq for Device
impl Send for Device
impl Sync for Device
Auto Trait Implementations§
impl Freeze for Device
impl RefUnwindSafe for Device
impl Unpin for Device
impl UnwindSafe for Device
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