Skip to content

Commit e1ce525

Browse files
authored
Merge pull request #112 from arrayfire/devel
v3.4.2 devel to master
2 parents f75a858 + b4e26e3 commit e1ce525

File tree

22 files changed

+193
-150
lines changed

22 files changed

+193
-150
lines changed

Cargo.toml

+1-1
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.4.1"
4+
version = "3.4.2"
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"

README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
|:-------:|:-------:|:---:|
44
| [![Build Status](http://ci.arrayfire.org/buildStatus/icon?job=arrayfire-wrappers/rust-linux)](http://ci.arrayfire.org/view/All/job/arrayfire-wrappers/job/rust-linux/) | [![Build Status](http://ci.arrayfire.org/buildStatus/icon?job=arrayfire-wrappers/rust-windows)](http://ci.arrayfire.org/view/All/job/arrayfire-wrappers/job/rust-windows/) | [![Build Status](http://ci.arrayfire.org/buildStatus/icon?job=arrayfire-wrappers/rust-osx)](http://ci.arrayfire.org/view/All/job/arrayfire-wrappers/job/rust-osx/) |
55

6-
[ArrayFire](https://github.com/arrayfire/arrayfire) is a high performance library for parallel computing with an easy-to-use API. It enables users to write scientific computing code that is portable across CUDA, OpenCL and CPU devices. This project provides Rust bindings for the ArrayFire library. The wrapper is currently compliant with ArrayFire 3.4.x API. If you find any bugs, please report them [here](https://github.com/arrayfire/arrayfire-rust/issues).
6+
[ArrayFire](https://github.com/arrayfire/arrayfire) is a high performance library for parallel computing with an easy-to-use API. It enables users to write scientific computing code that is portable across CUDA, OpenCL and CPU devices. This project provides Rust bindings for the ArrayFire library. Given below table shows the rust bindings compatability with ArrayFire. If you find any bugs, please report them [here](https://github.com/arrayfire/arrayfire-rust/issues).
7+
8+
| ArrayFire Upstream | Rust Crate |
9+
|:------------------:|:---------------:|
10+
| 3.3.x | 3.3.x |
11+
| 3.4.x | 3.4.x |
12+
13+
Only, Major & Minor version numbers need to match.
714

815
## Documentation
916

@@ -30,7 +37,8 @@ first.
3037
3. Make sure you add the path to library files to your path environment variables.
3138
- On Linux & OSX: do `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$AF_PATH/lib`
3239
- On Windows: Add `%AF_PATH%\lib` to your PATH environment variable.
33-
4. Add `arrayfire = "3.4.1"` to the dependencies section of your project's Cargo.toml file.
40+
4. Add `arrayfire = "3.4.2"` to the dependencies section of your project's Cargo.toml file - 3.4.2
41+
is the lastest version of crate.
3442

3543
Once step (4) is over, you should be able to use ArrayFire in your Rust project. If you find any bugs, please report them [here](https://github.com/arrayfire/arrayfire-rust/issues).
3644

@@ -68,10 +76,6 @@ af_print!("Create a 5-by-3 matrix of random floats on the GPU", a);
6876
~/p/arrayfire_rust> cargo run --example helloworld
6977
...
7078
running 1 test
71-
ArrayFire v3.4.0 (CUDA, 64-bit Linux, build 10d9716)
72-
Platform: CUDA Toolkit 7.5, Driver: 361.42
73-
[0] GeForce GT 650M, 2048 MB, CUDA Compute 3.0
74-
7579
Create a 5-by-3 matrix of random floats on the GPU
7680
[5 3 1 1]
7781
0.7402 0.4464 0.7762

examples/helloworld.rs

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ use af::*;
77
fn main() {
88
set_device(0);
99
info();
10+
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());
1015

1116
let num_rows: u64 = 5;
1217
let num_cols: u64 = 3;

src/algorithm/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ use array::Array;
44
use defines::{AfError, BinaryOp};
55
use error::HANDLE_ERROR;
66
use self::libc::{c_int, uint8_t, c_uint, c_double};
7-
8-
type MutAfArray = *mut self::libc::c_longlong;
9-
type MutDouble = *mut self::libc::c_double;
10-
type MutUint = *mut self::libc::c_uint;
11-
type AfArray = self::libc::c_longlong;
7+
use util::{AfArray, MutAfArray, MutDouble, MutUint};
128

139
#[allow(dead_code)]
1410
extern {

src/arith/mod.rs

+54-53
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,8 @@ use error::HANDLE_ERROR;
88
use self::libc::{c_int};
99
use data::{constant, constant_t, tile};
1010
use self::num::Complex;
11-
11+
use util::{AfArray, Complex32, Complex64, MutAfArray};
1212
use std::ops::Neg;
13-
14-
type Complex32 = Complex<f32>;
15-
type Complex64 = Complex<f64>;
16-
type MutAfArray = *mut self::libc::c_longlong;
17-
type MutDouble = *mut self::libc::c_double;
18-
type MutUint = *mut self::libc::c_uint;
19-
type AfArray = self::libc::c_longlong;
20-
2113
use std::ops::{Add, Sub, Div, Mul, BitAnd, BitOr, BitXor, Not, Rem, Shl, Shr};
2214

2315
#[allow(dead_code)]
@@ -180,12 +172,12 @@ macro_rules! binary_func {
180172
///
181173
/// This is an element wise binary operation.
182174
#[allow(unused_mut)]
183-
pub fn $fn_name(lhs: &Array, rhs: &Array) -> Array {
175+
pub fn $fn_name(lhs: &Array, rhs: &Array, batch: bool) -> Array {
184176
unsafe {
185177
let mut temp: i64 = 0;
186178
let err_val = $ffi_fn(&mut temp as MutAfArray,
187179
lhs.get() as AfArray, rhs.get() as AfArray,
188-
0);
180+
batch as c_int);
189181
HANDLE_ERROR(AfError::from(err_val));
190182
Array::from(temp)
191183
}
@@ -217,6 +209,8 @@ macro_rules! convertable_type_def {
217209
)
218210
}
219211

212+
convertable_type_def!(Complex<f64>);
213+
convertable_type_def!(Complex<f32>);
220214
convertable_type_def!(u64);
221215
convertable_type_def!(i64);
222216
convertable_type_def!(f64);
@@ -350,45 +344,33 @@ pub fn clamp<T, U> (input: &Array, arg1: &T, arg2: &U, batch: bool) -> Array
350344
}
351345

352346
macro_rules! arith_scalar_func {
353-
($rust_type: ty, $op_name:ident, $fn_name: ident, $ffi_fn: ident) => (
347+
($rust_type: ty, $op_name:ident, $fn_name: ident) => (
354348
impl<'f> $op_name<$rust_type> for &'f Array {
355349
type Output = Array;
356350

357351
fn $fn_name(self, rhs: $rust_type) -> Array {
358-
let cnst_arr = constant(rhs, self.dims());
359-
unsafe {
360-
let mut temp: i64 = 0;
361-
let err_val = $ffi_fn(&mut temp as MutAfArray, self.get() as AfArray,
362-
cnst_arr.get() as AfArray, 0);
363-
HANDLE_ERROR(AfError::from(err_val));
364-
Array::from(temp)
365-
}
352+
let temp = rhs.clone();
353+
$fn_name(self, &temp, false)
366354
}
367355
}
368356

369357
impl $op_name<$rust_type> for Array {
370358
type Output = Array;
371359

372360
fn $fn_name(self, rhs: $rust_type) -> Array {
373-
let cnst_arr = constant(rhs, self.dims());
374-
unsafe {
375-
let mut temp: i64 = 0;
376-
let err_val = $ffi_fn(&mut temp as MutAfArray, self.get() as AfArray,
377-
cnst_arr.get() as AfArray, 0);
378-
HANDLE_ERROR(AfError::from(err_val));
379-
Array::from(temp)
380-
}
361+
let temp = rhs.clone();
362+
$fn_name(&self, &temp, false)
381363
}
382364
}
383365
)
384366
}
385367

386368
macro_rules! arith_scalar_spec {
387369
($ty_name:ty) => (
388-
arith_scalar_func!($ty_name, Add, add, af_add);
389-
arith_scalar_func!($ty_name, Sub, sub, af_sub);
390-
arith_scalar_func!($ty_name, Mul, mul, af_mul);
391-
arith_scalar_func!($ty_name, Div, div, af_div);
370+
arith_scalar_func!($ty_name, Add, add);
371+
arith_scalar_func!($ty_name, Sub, sub);
372+
arith_scalar_func!($ty_name, Mul, mul);
373+
arith_scalar_func!($ty_name, Div, div);
392374
)
393375
}
394376

@@ -403,33 +385,51 @@ arith_scalar_spec!(i32);
403385
arith_scalar_spec!(u8);
404386

405387
macro_rules! arith_func {
406-
($op_name:ident, $fn_name:ident, $ffi_fn: ident) => (
388+
($op_name:ident, $fn_name:ident, $delegate:ident) => (
407389
impl $op_name<Array> for Array {
408390
type Output = Array;
409391

410392
fn $fn_name(self, rhs: Array) -> Array {
411-
unsafe {
412-
let mut temp: i64 = 0;
413-
let err_val = $ffi_fn(&mut temp as MutAfArray,
414-
self.get() as AfArray, rhs.get() as AfArray, 0);
415-
HANDLE_ERROR(AfError::from(err_val));
416-
Array::from(temp)
417-
}
393+
$delegate(&self, &rhs, false)
394+
}
395+
}
396+
397+
impl<'a> $op_name<&'a Array> for Array {
398+
type Output = Array;
399+
400+
fn $fn_name(self, rhs: &'a Array) -> Array {
401+
$delegate(&self, rhs, false)
402+
}
403+
}
404+
405+
impl<'a> $op_name<Array> for &'a Array {
406+
type Output = Array;
407+
408+
fn $fn_name(self, rhs: Array) -> Array {
409+
$delegate(self, &rhs, false)
410+
}
411+
}
412+
413+
impl<'a, 'b> $op_name<&'a Array> for &'b Array {
414+
type Output = Array;
415+
416+
fn $fn_name(self, rhs: &'a Array) -> Array {
417+
$delegate(self, rhs, false)
418418
}
419419
}
420420
)
421421
}
422422

423-
arith_func!(Add, add, af_add);
424-
arith_func!(Sub, sub, af_sub);
425-
arith_func!(Mul, mul, af_mul);
426-
arith_func!(Div, div, af_div);
427-
arith_func!(Rem, rem, af_rem);
428-
arith_func!(BitAnd, bitand, af_bitand);
429-
arith_func!(BitOr, bitor, af_bitor);
430-
arith_func!(BitXor, bitxor, af_bitxor);
431-
arith_func!(Shl, shl, af_bitshiftl);
432-
arith_func!(Shr, shr, af_bitshiftr);
423+
arith_func!(Add , add , add );
424+
arith_func!(Sub , sub , sub );
425+
arith_func!(Mul , mul , mul );
426+
arith_func!(Div , div , div );
427+
arith_func!(Rem , rem , rem );
428+
arith_func!(Shl , shl , shiftl);
429+
arith_func!(Shr , shr , shiftr);
430+
arith_func!(BitAnd, bitand, bitand);
431+
arith_func!(BitOr , bitor , bitor );
432+
arith_func!(BitXor, bitxor, bitxor);
433433

434434
#[cfg(op_assign)]
435435
mod op_assign {
@@ -450,8 +450,9 @@ macro_rules! arith_assign_func {
450450
#[allow(unused_variables)]
451451
fn $fn_name(&mut self, rhs: Array) {
452452
let mut idxrs = Indexer::new();
453-
idxrs.set_index(&Seq::<f32>::default(), 0, Some(false));
454-
idxrs.set_index(&Seq::<f32>::default(), 1, Some(false));
453+
for n in 0..self.numdims() {
454+
idxrs.set_index(&Seq::<f32>::default(), n, Some(false));
455+
}
455456
let tmp = assign_gen(self as &Array, &idxrs,
456457
& $func(self as &Array, &rhs, false));
457458
mem::replace(self, tmp);
@@ -477,7 +478,7 @@ macro_rules! bit_assign_func {
477478
let mut idxrs = Indexer::new();
478479
idxrs.set_index(&Seq::<f32>::default(), 0, Some(false));
479480
idxrs.set_index(&Seq::<f32>::default(), 1, Some(false));
480-
let tmp = assign_gen(self as &Array, &idxrs, & $func(self as &Array, &rhs));
481+
let tmp = assign_gen(self as &Array, &idxrs, & $func(self as &Array, &rhs, false));
481482
mem::replace(self, tmp);
482483
}
483484
}

src/array.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@ extern crate libc;
33
use dim4::Dim4;
44
use defines::{AfError, DType, Backend};
55
use error::HANDLE_ERROR;
6-
use util::HasAfEnum;
6+
use util::{AfArray, DimT, HasAfEnum, MutAfArray, MutVoidPtr};
77
use self::libc::{uint8_t, c_void, c_int, c_uint, c_longlong, c_char};
88
use std::ffi::CString;
99

10-
type MutAfArray = *mut self::libc::c_longlong;
11-
type MutDouble = *mut self::libc::c_double;
12-
type MutUint = *mut self::libc::c_uint;
13-
type AfArray = self::libc::c_longlong;
14-
type DimT = self::libc::c_longlong;
15-
type MutVoidPtr = *mut self::libc::c_ulonglong;
16-
type VoidPtr = self::libc::c_ulonglong;
17-
1810
// Some unused functions from array.h in C-API of ArrayFire
1911
// af_create_handle
2012
// af_copy_array

src/blas/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ use defines::AfError;
55
use defines::MatProp;
66
use error::HANDLE_ERROR;
77
use self::libc::{c_uint, c_int};
8-
use util::to_u32;
9-
10-
type MutAfArray = *mut self::libc::c_longlong;
11-
type AfArray = self::libc::c_longlong;
8+
use util::{AfArray, MutAfArray, to_u32};
129

1310
#[allow(dead_code)]
1411
extern {

src/data/mod.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,9 @@ use defines::{AfError, DType, Scalar};
77
use error::HANDLE_ERROR;
88
use self::libc::{uint8_t, c_int, c_uint, c_double};
99
use self::num::Complex;
10-
use util::HasAfEnum;
10+
use util::{AfArray, DimT, HasAfEnum, Intl, MutAfArray, Uintl};
1111
use std::vec::Vec;
1212

13-
type MutAfArray = *mut self::libc::c_longlong;
14-
type MutDouble = *mut self::libc::c_double;
15-
type MutUint = *mut self::libc::c_uint;
16-
type AfArray = self::libc::c_longlong;
17-
type DimT = self::libc::c_longlong;
18-
type Intl = self::libc::c_longlong;
19-
type Uintl = self::libc::c_ulonglong;
20-
2113
#[allow(dead_code)]
2214
extern {
2315
fn af_constant(out: MutAfArray, val: c_double,

0 commit comments

Comments
 (0)