Skip to content

v3.4.2 devel to master #112

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 19 commits into from
Feb 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "arrayfire"
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."
version = "3.4.1"
version = "3.4.2"
documentation = "http://arrayfire.github.io/arrayfire-rust/arrayfire/index.html"
homepage = "https://github.com/arrayfire/arrayfire"
repository = "https://github.com/arrayfire/arrayfire-rust"
Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
|:-------:|:-------:|:---:|
| [![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/) |

[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).
[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).

| ArrayFire Upstream | Rust Crate |
|:------------------:|:---------------:|
| 3.3.x | 3.3.x |
| 3.4.x | 3.4.x |

Only, Major & Minor version numbers need to match.

## Documentation

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

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).

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

Create a 5-by-3 matrix of random floats on the GPU
[5 3 1 1]
0.7402 0.4464 0.7762
Expand Down
5 changes: 5 additions & 0 deletions examples/helloworld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ use af::*;
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
6 changes: 1 addition & 5 deletions src/algorithm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ use array::Array;
use defines::{AfError, BinaryOp};
use error::HANDLE_ERROR;
use self::libc::{c_int, uint8_t, c_uint, c_double};

type MutAfArray = *mut self::libc::c_longlong;
type MutDouble = *mut self::libc::c_double;
type MutUint = *mut self::libc::c_uint;
type AfArray = self::libc::c_longlong;
use util::{AfArray, MutAfArray, MutDouble, MutUint};

#[allow(dead_code)]
extern {
Expand Down
107 changes: 54 additions & 53 deletions src/arith/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@ use error::HANDLE_ERROR;
use self::libc::{c_int};
use data::{constant, constant_t, tile};
use self::num::Complex;

use util::{AfArray, Complex32, Complex64, MutAfArray};
use std::ops::Neg;

type Complex32 = Complex<f32>;
type Complex64 = Complex<f64>;
type MutAfArray = *mut self::libc::c_longlong;
type MutDouble = *mut self::libc::c_double;
type MutUint = *mut self::libc::c_uint;
type AfArray = self::libc::c_longlong;

use std::ops::{Add, Sub, Div, Mul, BitAnd, BitOr, BitXor, Not, Rem, Shl, Shr};

#[allow(dead_code)]
Expand Down Expand Up @@ -180,12 +172,12 @@ macro_rules! binary_func {
///
/// This is an element wise binary operation.
#[allow(unused_mut)]
pub fn $fn_name(lhs: &Array, rhs: &Array) -> Array {
pub fn $fn_name(lhs: &Array, rhs: &Array, batch: bool) -> Array {
unsafe {
let mut temp: i64 = 0;
let err_val = $ffi_fn(&mut temp as MutAfArray,
lhs.get() as AfArray, rhs.get() as AfArray,
0);
batch as c_int);
HANDLE_ERROR(AfError::from(err_val));
Array::from(temp)
}
Expand Down Expand Up @@ -217,6 +209,8 @@ macro_rules! convertable_type_def {
)
}

convertable_type_def!(Complex<f64>);
convertable_type_def!(Complex<f32>);
convertable_type_def!(u64);
convertable_type_def!(i64);
convertable_type_def!(f64);
Expand Down Expand Up @@ -350,45 +344,33 @@ pub fn clamp<T, U> (input: &Array, arg1: &T, arg2: &U, batch: bool) -> Array
}

macro_rules! arith_scalar_func {
($rust_type: ty, $op_name:ident, $fn_name: ident, $ffi_fn: ident) => (
($rust_type: ty, $op_name:ident, $fn_name: ident) => (
impl<'f> $op_name<$rust_type> for &'f Array {
type Output = Array;

fn $fn_name(self, rhs: $rust_type) -> Array {
let cnst_arr = constant(rhs, self.dims());
unsafe {
let mut temp: i64 = 0;
let err_val = $ffi_fn(&mut temp as MutAfArray, self.get() as AfArray,
cnst_arr.get() as AfArray, 0);
HANDLE_ERROR(AfError::from(err_val));
Array::from(temp)
}
let temp = rhs.clone();
$fn_name(self, &temp, false)
}
}

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

fn $fn_name(self, rhs: $rust_type) -> Array {
let cnst_arr = constant(rhs, self.dims());
unsafe {
let mut temp: i64 = 0;
let err_val = $ffi_fn(&mut temp as MutAfArray, self.get() as AfArray,
cnst_arr.get() as AfArray, 0);
HANDLE_ERROR(AfError::from(err_val));
Array::from(temp)
}
let temp = rhs.clone();
$fn_name(&self, &temp, false)
}
}
)
}

macro_rules! arith_scalar_spec {
($ty_name:ty) => (
arith_scalar_func!($ty_name, Add, add, af_add);
arith_scalar_func!($ty_name, Sub, sub, af_sub);
arith_scalar_func!($ty_name, Mul, mul, af_mul);
arith_scalar_func!($ty_name, Div, div, af_div);
arith_scalar_func!($ty_name, Add, add);
arith_scalar_func!($ty_name, Sub, sub);
arith_scalar_func!($ty_name, Mul, mul);
arith_scalar_func!($ty_name, Div, div);
)
}

Expand All @@ -403,33 +385,51 @@ arith_scalar_spec!(i32);
arith_scalar_spec!(u8);

macro_rules! arith_func {
($op_name:ident, $fn_name:ident, $ffi_fn: ident) => (
($op_name:ident, $fn_name:ident, $delegate:ident) => (
impl $op_name<Array> for Array {
type Output = Array;

fn $fn_name(self, rhs: Array) -> Array {
unsafe {
let mut temp: i64 = 0;
let err_val = $ffi_fn(&mut temp as MutAfArray,
self.get() as AfArray, rhs.get() as AfArray, 0);
HANDLE_ERROR(AfError::from(err_val));
Array::from(temp)
}
$delegate(&self, &rhs, false)
}
}

impl<'a> $op_name<&'a Array> for Array {
type Output = Array;

fn $fn_name(self, rhs: &'a Array) -> Array {
$delegate(&self, rhs, false)
}
}

impl<'a> $op_name<Array> for &'a Array {
type Output = Array;

fn $fn_name(self, rhs: Array) -> Array {
$delegate(self, &rhs, false)
}
}

impl<'a, 'b> $op_name<&'a Array> for &'b Array {
type Output = Array;

fn $fn_name(self, rhs: &'a Array) -> Array {
$delegate(self, rhs, false)
}
}
)
}

arith_func!(Add, add, af_add);
arith_func!(Sub, sub, af_sub);
arith_func!(Mul, mul, af_mul);
arith_func!(Div, div, af_div);
arith_func!(Rem, rem, af_rem);
arith_func!(BitAnd, bitand, af_bitand);
arith_func!(BitOr, bitor, af_bitor);
arith_func!(BitXor, bitxor, af_bitxor);
arith_func!(Shl, shl, af_bitshiftl);
arith_func!(Shr, shr, af_bitshiftr);
arith_func!(Add , add , add );
arith_func!(Sub , sub , sub );
arith_func!(Mul , mul , mul );
arith_func!(Div , div , div );
arith_func!(Rem , rem , rem );
arith_func!(Shl , shl , shiftl);
arith_func!(Shr , shr , shiftr);
arith_func!(BitAnd, bitand, bitand);
arith_func!(BitOr , bitor , bitor );
arith_func!(BitXor, bitxor, bitxor);

#[cfg(op_assign)]
mod op_assign {
Expand All @@ -450,8 +450,9 @@ macro_rules! arith_assign_func {
#[allow(unused_variables)]
fn $fn_name(&mut self, rhs: Array) {
let mut idxrs = Indexer::new();
idxrs.set_index(&Seq::<f32>::default(), 0, Some(false));
idxrs.set_index(&Seq::<f32>::default(), 1, Some(false));
for n in 0..self.numdims() {
idxrs.set_index(&Seq::<f32>::default(), n, Some(false));
}
let tmp = assign_gen(self as &Array, &idxrs,
& $func(self as &Array, &rhs, false));
mem::replace(self, tmp);
Expand All @@ -477,7 +478,7 @@ macro_rules! bit_assign_func {
let mut idxrs = Indexer::new();
idxrs.set_index(&Seq::<f32>::default(), 0, Some(false));
idxrs.set_index(&Seq::<f32>::default(), 1, Some(false));
let tmp = assign_gen(self as &Array, &idxrs, & $func(self as &Array, &rhs));
let tmp = assign_gen(self as &Array, &idxrs, & $func(self as &Array, &rhs, false));
mem::replace(self, tmp);
}
}
Expand Down
10 changes: 1 addition & 9 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,10 @@ extern crate libc;
use dim4::Dim4;
use defines::{AfError, DType, Backend};
use error::HANDLE_ERROR;
use util::HasAfEnum;
use util::{AfArray, DimT, HasAfEnum, MutAfArray, MutVoidPtr};
use self::libc::{uint8_t, c_void, c_int, c_uint, c_longlong, c_char};
use std::ffi::CString;

type MutAfArray = *mut self::libc::c_longlong;
type MutDouble = *mut self::libc::c_double;
type MutUint = *mut self::libc::c_uint;
type AfArray = self::libc::c_longlong;
type DimT = self::libc::c_longlong;
type MutVoidPtr = *mut self::libc::c_ulonglong;
type VoidPtr = self::libc::c_ulonglong;

// Some unused functions from array.h in C-API of ArrayFire
// af_create_handle
// af_copy_array
Expand Down
5 changes: 1 addition & 4 deletions src/blas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use defines::AfError;
use defines::MatProp;
use error::HANDLE_ERROR;
use self::libc::{c_uint, c_int};
use util::to_u32;

type MutAfArray = *mut self::libc::c_longlong;
type AfArray = self::libc::c_longlong;
use util::{AfArray, MutAfArray, to_u32};

#[allow(dead_code)]
extern {
Expand Down
10 changes: 1 addition & 9 deletions src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@ use defines::{AfError, DType, Scalar};
use error::HANDLE_ERROR;
use self::libc::{uint8_t, c_int, c_uint, c_double};
use self::num::Complex;
use util::HasAfEnum;
use util::{AfArray, DimT, HasAfEnum, Intl, MutAfArray, Uintl};
use std::vec::Vec;

type MutAfArray = *mut self::libc::c_longlong;
type MutDouble = *mut self::libc::c_double;
type MutUint = *mut self::libc::c_uint;
type AfArray = self::libc::c_longlong;
type DimT = self::libc::c_longlong;
type Intl = self::libc::c_longlong;
type Uintl = self::libc::c_ulonglong;

#[allow(dead_code)]
extern {
fn af_constant(out: MutAfArray, val: c_double,
Expand Down
Loading