Skip to content

Commit b088f07

Browse files
committed
API Catchup to 3.3.0 version
More detailed information on the new release can be found at the following URL https://github.com/arrayfire/arrayfire/releases/tag/v3.3.0
1 parent b40c7db commit b088f07

File tree

11 files changed

+423
-34
lines changed

11 files changed

+423
-34
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "arrayfire"
33
description = "ArrayFire is a high performance software library for parallel computing with an easy-to-use API. Its array based function set makes parallel programming simple. ArrayFire's multiple backends (CUDA, OpenCL and native CPU) make it platform independent and highly portable. A few lines of code in ArrayFire can replace dozens of lines of parallel computing code, saving you valuable time and lowering development costs. This crate provides Rust bindings for ArrayFire library."
4-
version = "3.2.0"
4+
version = "3.3.0"
55
documentation = "http://arrayfire.github.io/arrayfire-rust/arrayfire/index.html"
66
homepage = "https://github.com/arrayfire/arrayfire"
77
repository = "https://github.com/arrayfire/arrayfire-rust"

arrayfire

Submodule arrayfire updated 459 files

examples/unified.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@ fn main() {
2424
println!("There are {:?} available backends", get_backend_count().unwrap());
2525
let available = get_available_backends().unwrap();
2626

27-
if available.contains(&Backend::AF_BACKEND_CPU){
27+
if available.contains(&Backend::CPU){
2828
println!("Evaluating CPU Backend...");
29-
let err = set_backend(Backend::AF_BACKEND_CPU);
29+
let err = set_backend(Backend::CPU);
3030
println!("There are {} CPU compute devices", device_count().unwrap());
3131
match err {
3232
Ok(_) => test_backend(),
3333
Err(e) => println!("CPU backend error: {}", e),
3434
};
3535
}
3636

37-
if available.contains(&Backend::AF_BACKEND_CUDA){
37+
if available.contains(&Backend::CUDA){
3838
println!("Evaluating CUDA Backend...");
39-
let err = set_backend(Backend::AF_BACKEND_CUDA);
39+
let err = set_backend(Backend::CUDA);
4040
println!("There are {} CUDA compute devices", device_count().unwrap());
4141
match err {
4242
Ok(_) => test_backend(),
4343
Err(e) => println!("CUDA backend error: {}", e),
4444
};
4545
}
4646

47-
if available.contains(&Backend::AF_BACKEND_OPENCL){
47+
if available.contains(&Backend::OPENCL){
4848
println!("Evaluating OpenCL Backend...");
49-
let err = set_backend(Backend::AF_BACKEND_OPENCL);
49+
let err = set_backend(Backend::OPENCL);
5050
println!("There are {} OpenCL compute devices", device_count().unwrap());
5151
match err {
5252
Ok(_) => test_backend(),

src/array.rs

Lines changed: 102 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ extern {
7272
fn af_cast(out: MutAfArray, arr: AfArray, aftype: uint8_t) -> c_int;
7373

7474
fn af_get_backend_id(backend: *mut c_int, input: AfArray) -> c_int;
75+
76+
fn af_get_device_id(device: *mut c_int, input: AfArray) -> c_int;
77+
78+
fn af_create_strided_array(arr: MutAfArray, data: *const c_void, offset: DimT,
79+
ndims: c_uint, dims: *const DimT, strides: *const DimT,
80+
aftype: uint8_t) -> c_int;
81+
82+
fn af_get_strides(s0: *mut DimT, s1: *mut DimT, s2: *mut DimT, s3: *mut DimT,
83+
arr: AfArray) -> c_int;
84+
85+
fn af_get_offset(offset: *mut DimT, arr: AfArray) -> c_int;
86+
87+
fn af_is_linear(result: *mut c_int, arr: AfArray) -> c_int;
88+
89+
fn af_is_owner(result: *mut c_int, arr: AfArray) -> c_int;
7590
}
7691

7792
/// A multidimensional data container
@@ -122,21 +137,68 @@ impl Array {
122137
}
123138
}
124139

140+
/// Constructs a new Array object from strided data
141+
///
142+
/// This data can possiblly offseted using an additiona `offset` parameter.
143+
///
144+
/// # Examples
145+
///
146+
/// ```
147+
/// let values: &[f32] = &[1.0, 2.0, 3.0];
148+
/// let indices = Array::new(Dim4::new(&[3, 1, 1, 1]), values, Aftype::F32).unwrap();
149+
/// ```
150+
#[allow(unused_mut)]
151+
pub fn new_strided<T>(slice: &[T], offset: i64,
152+
dims: Dim4, strides: Dim4,
153+
aftype: Aftype) -> Result<Array, AfError> {
154+
unsafe {
155+
let mut temp: i64 = 0;
156+
let err_val = af_create_strided_array(&mut temp as MutAfArray,
157+
slice.as_ptr() as *const c_void,
158+
offset as DimT,
159+
dims.ndims() as c_uint,
160+
dims.get().as_ptr() as * const c_longlong,
161+
strides.get().as_ptr() as * const c_longlong,
162+
aftype as uint8_t);
163+
match err_val {
164+
0 => Ok(Array {handle: temp}),
165+
_ => Err(AfError::from(err_val)),
166+
}
167+
}
168+
}
169+
125170
/// Returns the backend of the Array
126171
///
127172
/// # Return Values
128173
///
129174
/// Returns an value of type `Backend` which indicates which backend
130175
/// was active when Array was created.
131-
pub fn get_backend(&self) -> Backend {
176+
pub fn get_backend(&self) -> Result<Backend, AfError> {
132177
unsafe {
133178
let mut ret_val: i32 = 0;
134-
af_get_backend_id(&mut ret_val as *mut c_int, self.handle as AfArray);
135-
match ret_val {
136-
1 => Backend::AF_BACKEND_CPU,
137-
2 => Backend::AF_BACKEND_CUDA,
138-
3 => Backend::AF_BACKEND_OPENCL,
139-
_ => Backend::AF_BACKEND_DEFAULT,
179+
let err_val = af_get_backend_id(&mut ret_val as *mut c_int, self.handle as AfArray);
180+
match (err_val, ret_val) {
181+
(0, 1) => Ok(Backend::CPU),
182+
(0, 2) => Ok(Backend::CUDA),
183+
(0, 3) => Ok(Backend::OPENCL),
184+
_ => Err(AfError::from(err_val)),
185+
}
186+
}
187+
}
188+
189+
/// Returns the device identifier(integer) on which the Array was created
190+
///
191+
/// # Return Values
192+
///
193+
/// Return the device id on which Array was created.
194+
pub fn get_device_id(&self) -> Result<i32, AfError> {
195+
unsafe {
196+
let mut ret_val: i32 = 0;
197+
let err_val = af_get_device_id(&mut ret_val as *mut c_int, self.handle as AfArray);
198+
match err_val {
199+
0 => Ok(ret_val),
200+
_ => Err(AfError::from(err_val)),
201+
140202
}
141203
}
142204
}
@@ -172,8 +234,8 @@ impl Array {
172234
let mut ret1: i64 = 0;
173235
let mut ret2: i64 = 0;
174236
let mut ret3: i64 = 0;
175-
let err_val = af_get_dims(&mut ret0 as *mut c_longlong, &mut ret1 as *mut c_longlong,
176-
&mut ret2 as *mut c_longlong, &mut ret3 as *mut c_longlong,
237+
let err_val = af_get_dims(&mut ret0 as *mut DimT, &mut ret1 as *mut DimT,
238+
&mut ret2 as *mut DimT, &mut ret3 as *mut DimT,
177239
self.handle as AfArray);
178240
match err_val {
179241
0 => Ok(Dim4::new(&[ret0 as u64, ret1 as u64, ret2 as u64, ret3 as u64])),
@@ -182,6 +244,23 @@ impl Array {
182244
}
183245
}
184246

247+
/// Returns the strides of the Array
248+
pub fn strides(&self) -> Result<Dim4, AfError> {
249+
unsafe {
250+
let mut ret0: i64 = 0;
251+
let mut ret1: i64 = 0;
252+
let mut ret2: i64 = 0;
253+
let mut ret3: i64 = 0;
254+
let err_val = af_get_strides(&mut ret0 as *mut DimT, &mut ret1 as *mut DimT,
255+
&mut ret2 as *mut DimT, &mut ret3 as *mut DimT,
256+
self.handle as AfArray);
257+
match err_val {
258+
0 => Ok(Dim4::new(&[ret0 as u64, ret1 as u64, ret2 as u64, ret3 as u64])),
259+
_ => Err(AfError::from(err_val)),
260+
}
261+
}
262+
}
263+
185264
/// Returns the number of dimensions of the Array
186265
pub fn numdims(&self) -> Result<u32, AfError> {
187266
unsafe {
@@ -194,6 +273,18 @@ impl Array {
194273
}
195274
}
196275

276+
/// Returns the offset to the pointer from where data begins
277+
pub fn offset(&self) -> Result<i64, AfError> {
278+
unsafe {
279+
let mut ret_val: i64 = 0;
280+
let err_val = af_get_offset(&mut ret_val as *mut DimT, self.handle as AfArray);
281+
match err_val {
282+
0 => Ok(ret_val),
283+
_ => Err(AfError::from(err_val)),
284+
}
285+
}
286+
}
287+
197288
/// Returns the native FFI handle for Rust object `Array`
198289
pub fn get(&self) -> i64 {
199290
self.handle
@@ -247,6 +338,8 @@ impl Array {
247338
is_func!(is_floating, af_is_floating);
248339
is_func!(is_integer, af_is_integer);
249340
is_func!(is_bool, af_is_bool);
341+
is_func!(is_linear, af_is_linear);
342+
is_func!(is_owner, af_is_owner);
250343

251344
/// Cast the Array data type to `target_type`
252345
pub fn cast(&self, target_type: Aftype) -> Result<Array, AfError> {

src/backend.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern {
77
fn af_set_backend(bknd: uint8_t) -> c_int;
88
fn af_get_backend_count(num_backends: *mut c_uint) -> c_int;
99
fn af_get_available_backends(backends: *mut c_int) -> c_int;
10+
fn af_get_active_backend(backend: *mut c_int) -> c_int;
1011
}
1112

1213
/// Toggle backends between cuda, opencl or cpu
@@ -47,12 +48,28 @@ pub fn get_available_backends() -> Result<Vec<Backend>, AfError> {
4748
match err_val {
4849
0 => {
4950
let mut b = Vec::new();
50-
if temp & 0b0100 == 0b0100 { b.push(Backend::AF_BACKEND_OPENCL); }
51-
if temp & 0b0010 == 0b0010 { b.push(Backend::AF_BACKEND_CUDA); }
52-
if temp & 0b0001 == 0b0001 { b.push(Backend::AF_BACKEND_CPU); }
51+
if temp & 0b0100 == 0b0100 { b.push(Backend::OPENCL); }
52+
if temp & 0b0010 == 0b0010 { b.push(Backend::CUDA); }
53+
if temp & 0b0001 == 0b0001 { b.push(Backend::CPU); }
5354
Ok(b)
5455
},
5556
_ => Err(AfError::from(err_val)),
5657
}
5758
}
5859
}
60+
61+
/// Get current active backend
62+
#[allow(unused_mut)]
63+
pub fn get_active_backend() -> Result<Backend, AfError> {
64+
unsafe {
65+
let mut temp: i32 = 0;
66+
let err_val = af_get_active_backend(&mut temp as *mut c_int);
67+
match (err_val, temp) {
68+
(0, 0) => Ok(Backend::DEFAULT),
69+
(0, 1) => Ok(Backend::CPU),
70+
(0, 2) => Ok(Backend::CUDA),
71+
(0, 4) => Ok(Backend::OPENCL),
72+
_ => Err(AfError::from(err_val)),
73+
}
74+
}
75+
}

src/defines.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub enum AfError {
2828
ERR_DIFF_TYPE = 205,
2929
/// Function does not support GFOR / batch mode
3030
ERR_BATCH = 207,
31+
/// Input does not belong to the current device
32+
ERR_DEVICE = 208,
3133
// 300-399 Errors for missing software features
3234
/// The option is not supported
3335
ERR_NOT_SUPPORTED = 301,
@@ -51,22 +53,22 @@ pub enum AfError {
5153
#[derive(Clone, Copy, Debug, PartialEq)]
5254
pub enum Backend {
5355
/// Default backend order: OpenCL -> CUDA -> CPU
54-
AF_BACKEND_DEFAULT = 0,
56+
DEFAULT = 0,
5557
/// CPU a.k.a sequential algorithms
56-
AF_BACKEND_CPU = 1,
58+
CPU = 1,
5759
/// CUDA Compute Backend
58-
AF_BACKEND_CUDA = 2,
60+
CUDA = 2,
5961
/// OpenCL Compute Backend
60-
AF_BACKEND_OPENCL = 4
62+
OPENCL = 4
6163
}
6264

6365
impl Display for Backend {
6466
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
6567
let text = match *self {
66-
Backend::AF_BACKEND_OPENCL => "OpenCL",
67-
Backend::AF_BACKEND_CUDA => "Cuda",
68-
Backend::AF_BACKEND_CPU => "CPU",
69-
Backend::AF_BACKEND_DEFAULT => "Default",
68+
Backend::OPENCL => "OpenCL",
69+
Backend::CUDA => "Cuda",
70+
Backend::CPU => "CPU",
71+
Backend::DEFAULT => "Default",
7072
};
7173
write!(f, "{}", text)
7274
}
@@ -91,6 +93,7 @@ impl Error for AfError {
9193
AfError::ERR_TYPE => "The type is not supported by this function",
9294
AfError::ERR_DIFF_TYPE => "The type of input arrays are not compatible",
9395
AfError::ERR_BATCH => "Function does not support GFOR / batch mode",
96+
AfError::ERR_DEVICE => "Array does not belong to device",
9497
AfError::ERR_NOT_SUPPORTED => "The option is not supported",
9598
AfError::ERR_NOT_CONFIGURED => "This build of ArrayFire does not support this feature",
9699
AfError::ERR_NO_DBL => "This device does not support double",
@@ -305,3 +308,17 @@ pub enum HomographyType {
305308
/// Least Median of Squares
306309
LMEDS = 1,
307310
}
311+
312+
/// Plotting markers
313+
#[repr(C)]
314+
#[derive(Copy, Clone)]
315+
pub enum MarkerType {
316+
NONE = 0,
317+
POINT = 1,
318+
CIRCLE = 2,
319+
SQUARE = 3,
320+
TRIANGLE = 4,
321+
CROSS = 5,
322+
PLUS = 6,
323+
STAR = 7
324+
}

0 commit comments

Comments
 (0)