diff --git a/examples/helloworld.rs b/examples/helloworld.rs index cae62575b..53cf75eb1 100644 --- a/examples/helloworld.rs +++ b/examples/helloworld.rs @@ -8,6 +8,10 @@ fn main() { set_device(0); info(); print!("Info String:\n{}", info_string(true)); + println!("Arrayfire version: {:?}", get_version()); + let (name, platform, toolkit, compute) = device_info(); + print!("Name: {}\nPlatform: {}\nToolkit: {}\nCompute: {}\n", name, platform, toolkit, compute); + println!("Revision: {}", get_revision()); let num_rows: u64 = 5; let num_cols: u64 = 3; diff --git a/src/device/mod.rs b/src/device/mod.rs index ff0e8ac65..8f83f2a10 100644 --- a/src/device/mod.rs +++ b/src/device/mod.rs @@ -4,12 +4,16 @@ use defines::{AfError, DType}; use error::HANDLE_ERROR; use self::libc::{c_int, size_t, c_char, c_void}; use std::ffi::{CStr, CString}; +use std::borrow::Cow; use util::free_host; extern { fn af_get_version(major: *mut c_int, minor: *mut c_int, patch: *mut c_int) -> c_int; + fn af_get_revision() -> *const c_char; fn af_info() -> c_int; fn af_info_string(str: *mut *mut c_char, verbose: bool) -> c_int; + fn af_device_info(d_name: *mut c_char, d_platform: *mut c_char, + d_toolkit: *mut c_char, d_compute: *mut c_char) -> c_int; fn af_init() -> c_int; fn af_get_device_count(nDevices: *mut c_int) -> c_int; fn af_get_dbl_support(available: *mut c_int, device: c_int) -> c_int; @@ -40,6 +44,16 @@ pub fn get_version() -> (i32, i32, i32) { } } +/// Get ArrayFire Revision (commit) information of the library. +/// +/// # Return Values +/// This returns a `Cow<'static, str>` as the string is constructed at compile time. +pub fn get_revision() -> Cow<'static, str> { + unsafe { + CStr::from_ptr(af_get_revision()).to_string_lossy() + } +} + /// Print library meta-info /// /// # Examples @@ -81,6 +95,28 @@ pub fn info_string(verbose: bool) -> String { result } +/// Gets the information about device and platform as strings. +/// +/// # Return Values +/// A tuple of `String` indicating the name, platform, toolkit and compute. +pub fn device_info() -> (String, String, String, String) { + let mut name = [0 as c_char; 64]; + let mut platform = [0 as c_char; 10]; + let mut toolkit = [0 as c_char; 64]; + let mut compute = [0 as c_char; 10]; + unsafe { + let err_val = af_device_info(&mut name[0], + &mut platform[0], + &mut toolkit[0], + &mut compute[0]); + HANDLE_ERROR(AfError::from(err_val)); + (CStr::from_ptr(name.as_mut_ptr()).to_string_lossy().into_owned(), + CStr::from_ptr(platform.as_mut_ptr()).to_string_lossy().into_owned(), + CStr::from_ptr(toolkit.as_mut_ptr()).to_string_lossy().into_owned(), + CStr::from_ptr(compute.as_mut_ptr()).to_string_lossy().into_owned()) + } +} + /// Initialize ArrayFire library /// /// 0th device will be the default device unless init call diff --git a/src/lib.rs b/src/lib.rs index a1c5b6fe3..2ead5233d 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,7 +40,7 @@ pub use data::{select, selectl, selectr, replace, replace_scalar}; pub use data::{range_t, iota_t, identity_t, constant_t}; mod data; -pub use device::{get_version, info, info_string, init, device_count, is_double_available, set_device, get_device}; +pub use device::{get_version, get_revision, info, info_string, device_info, init, device_count, is_double_available, set_device, get_device}; pub use device::{device_mem_info, print_mem_info, set_mem_step_size, get_mem_step_size, device_gc, sync}; mod device;