Skip to content

Commit 4fef41e

Browse files
committed
Added get_revision and device_info
1 parent 80bfb4e commit 4fef41e

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

examples/helloworld.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ fn main() {
88
set_device(0);
99
info();
1010
print!("Info String:\n{}", info_string(true));
11+
println!("Arrayfire version: {:?}", get_version());
12+
let (name, platform, toolkit, compute) = device_info();
13+
print!("Name: {}\nPlatform: {}\nToolkit: {}\nCompute: {}\n", name, platform, toolkit, compute);
14+
println!("Revision: {}", get_revision());
1115

1216
let num_rows: u64 = 5;
1317
let num_cols: u64 = 3;

src/device/mod.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ use defines::{AfError, DType};
44
use error::HANDLE_ERROR;
55
use self::libc::{c_int, size_t, c_char, c_void};
66
use std::ffi::{CStr, CString};
7+
use std::borrow::Cow;
78
use util::free_host;
89

910
extern {
1011
fn af_get_version(major: *mut c_int, minor: *mut c_int, patch: *mut c_int) -> c_int;
12+
fn af_get_revision() -> *const c_char;
1113
fn af_info() -> c_int;
1214
fn af_info_string(str: *mut *mut c_char, verbose: bool) -> c_int;
15+
fn af_device_info(d_name: *mut c_char, d_platform: *mut c_char,
16+
d_toolkit: *mut c_char, d_compute: *mut c_char) -> c_int;
1317
fn af_init() -> c_int;
1418
fn af_get_device_count(nDevices: *mut c_int) -> c_int;
1519
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) {
4044
}
4145
}
4246

47+
/// Get ArrayFire Revision (commit) information of the library.
48+
///
49+
/// # Return Values
50+
/// This returns a `Cow<'static, str>` as the string is constructed at compile time.
51+
pub fn get_revision() -> Cow<'static, str> {
52+
unsafe {
53+
CStr::from_ptr(af_get_revision()).to_string_lossy()
54+
}
55+
}
56+
4357
/// Print library meta-info
4458
///
4559
/// # Examples
@@ -81,6 +95,28 @@ pub fn info_string(verbose: bool) -> String {
8195
result
8296
}
8397

98+
/// Gets the information about device and platform as strings.
99+
///
100+
/// # Return Values
101+
/// A tuple of `String` indicating the name, platform, toolkit and compute.
102+
pub fn device_info() -> (String, String, String, String) {
103+
let mut name = [0 as c_char; 64];
104+
let mut platform = [0 as c_char; 10];
105+
let mut toolkit = [0 as c_char; 64];
106+
let mut compute = [0 as c_char; 10];
107+
unsafe {
108+
let err_val = af_device_info(&mut name[0],
109+
&mut platform[0],
110+
&mut toolkit[0],
111+
&mut compute[0]);
112+
HANDLE_ERROR(AfError::from(err_val));
113+
(CStr::from_ptr(name.as_mut_ptr()).to_string_lossy().into_owned(),
114+
CStr::from_ptr(platform.as_mut_ptr()).to_string_lossy().into_owned(),
115+
CStr::from_ptr(toolkit.as_mut_ptr()).to_string_lossy().into_owned(),
116+
CStr::from_ptr(compute.as_mut_ptr()).to_string_lossy().into_owned())
117+
}
118+
}
119+
84120
/// Initialize ArrayFire library
85121
///
86122
/// 0th device will be the default device unless init call

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub use data::{select, selectl, selectr, replace, replace_scalar};
4040
pub use data::{range_t, iota_t, identity_t, constant_t};
4141
mod data;
4242

43-
pub use device::{get_version, info, info_string, init, device_count, is_double_available, set_device, get_device};
43+
pub use device::{get_version, get_revision, info, info_string, device_info, init, device_count, is_double_available, set_device, get_device};
4444
pub use device::{device_mem_info, print_mem_info, set_mem_step_size, get_mem_step_size, device_gc, sync};
4545
mod device;
4646

0 commit comments

Comments
 (0)