Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/platform/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ fn main() {
println!(" Type: {}", device.device_type());
println!(" Profile: {}", device.profile());
println!(" Compute Units: {}", device.compute_units());
println!(" Global Mem Cache Size: {} Bytes", device.global_mem_cache_size());
println!(" Global Mem Size: {} Bytes", device.global_mem_size());
println!(" Local Mem Size: {} Bytes", device.local_mem_size());
println!(" Max Constant Buffer Size: {} Bytes", device.max_constant_buffer_size());
println!(" Max Mem Alloc Size: {} Bytes", device.max_mem_alloc_size());
}
}
}
50 changes: 37 additions & 13 deletions src/hl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,44 @@ impl Device {
{
self.profile_info(CL_DEVICE_TYPE)
}

pub fn compute_units(&self) -> usize {
unsafe {
let mut ct: usize = 0;
let status = clGetDeviceInfo(
self.id,
CL_DEVICE_MAX_COMPUTE_UNITS,
8,
(&mut ct as *mut usize) as *mut libc::c_void,
ptr::null_mut());
check(status, "Could not get number of device compute units.");
return ct;
}

fn device_info_helper<T: Default>(&self, query: cl_device_info) -> T {
unsafe{
let mut retvalue: T = Default::default();
let status = clGetDeviceInfo(
self.id,
query,
mem::size_of::<T>() as u64,
(&mut retvalue as *mut T) as *mut libc::c_void,
ptr::null_mut());
check(status, "device_info_ulong_helper: clGetDeviceInfo query failure.");
return retvalue;
}
}

pub fn compute_units(&self) -> u32 {
self.device_info_helper::<u32>(CL_DEVICE_MAX_COMPUTE_UNITS)
}

pub fn global_mem_cache_size(&self) -> u64 {
self.device_info_helper::<u64>(CL_DEVICE_GLOBAL_MEM_CACHE_SIZE)
}

pub fn global_mem_size(&self) -> u64 {
self.device_info_helper::<u64>(CL_DEVICE_GLOBAL_MEM_SIZE)
}

pub fn local_mem_size(&self) -> u64 {
self.device_info_helper::<u64>(CL_DEVICE_LOCAL_MEM_SIZE)
}

pub fn max_constant_buffer_size(&self) -> u64 {
self.device_info_helper::<u64>(CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE)
}

pub fn max_mem_alloc_size(&self) -> u64 {
self.device_info_helper::<u64>(CL_DEVICE_MAX_MEM_ALLOC_SIZE)
}


pub fn create_context(&self) -> Context
Expand Down