Skip to content

Added get_revision and device_info #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2017
Merged
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
4 changes: 4 additions & 0 deletions examples/helloworld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 36 additions & 0 deletions src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down