Skip to content

Commit 103681e

Browse files
committed
Added info_string
1 parent 456a335 commit 103681e

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

examples/helloworld.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use af::*;
77
fn main() {
88
set_device(0);
99
info();
10+
print!("Info String:\n{}", info_string(true));
1011

1112
let num_rows: u64 = 5;
1213
let num_cols: u64 = 3;

src/device/mod.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ extern crate libc;
22

33
use defines::AfError;
44
use error::HANDLE_ERROR;
5-
use self::libc::{c_int, size_t, c_char};
5+
use self::libc::{c_int, size_t, c_char, c_void};
66
use std::ffi::CString;
77

88
extern {
99
fn af_get_version(major: *mut c_int, minor: *mut c_int, patch: *mut c_int) -> c_int;
1010
fn af_info() -> c_int;
11+
fn af_info_string(str: *mut *mut c_char, verbose: bool) -> c_int;
1112
fn af_init() -> c_int;
1213
fn af_get_device_count(nDevices: *mut c_int) -> c_int;
1314
fn af_get_dbl_support(available: *mut c_int, device: c_int) -> c_int;
@@ -20,6 +21,8 @@ extern {
2021
fn af_get_mem_step_size(step_bytes: *mut size_t) -> c_int;
2122
fn af_device_gc() -> c_int;
2223
fn af_sync(device: c_int) -> c_int;
24+
25+
fn af_free_host (ptr: *mut c_void) -> c_int;
2326
}
2427

2528
/// Get ArrayFire Version Number
@@ -56,6 +59,31 @@ pub fn info() {
5659
}
5760
}
5861

62+
/// Return library meta-info as `String`
63+
///
64+
/// # Examples
65+
///
66+
/// An example output of `af::info_string` call looks like below
67+
///
68+
/// ```text
69+
/// ArrayFire v3.0.0 (CUDA, 64-bit Mac OSX, build d8d4b38)
70+
/// Platform: CUDA Toolkit 7, Driver: CUDA Driver Version: 7000
71+
/// [0] GeForce GT 750M, 2048 MB, CUDA Compute 3.0
72+
/// ```
73+
pub fn info_string(verbose: bool) -> String {
74+
let mut tmp: *mut c_char = 0 as *mut c_char;
75+
unsafe {
76+
let err_val = af_info_string(&mut tmp, verbose);
77+
HANDLE_ERROR(AfError::from(err_val));
78+
79+
let result = CString::from_raw(tmp).into_string().unwrap();
80+
81+
let err_val = af_free_host(tmp as *mut c_void);
82+
HANDLE_ERROR(AfError::from(err_val));
83+
result
84+
}
85+
}
86+
5987
/// Initialize ArrayFire library
6088
///
6189
/// 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, init, device_count, is_double_available, set_device, get_device};
43+
pub use device::{get_version, info, info_string, 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)