Skip to content

Master Update #81

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 46 commits into from
Jul 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
5f9e5da
Removed obselete sections from README
9prady9 Dec 15, 2015
ec474bc
Merge pull request #53 from 9prady9/read_me_fix
9prady9 Dec 15, 2015
86fc951
added gitter chat badge
9prady9 Dec 28, 2015
80651c9
Make Seq generic and make use of generic Seq in helloworld example
tedsta Feb 24, 2016
ab618ad
Made our own One+Zero traits so we can use stable rust
tedsta Feb 25, 2016
70fcd0f
Macro-ify Zero and One trait impls
tedsta Feb 26, 2016
b40c7db
Merge pull request #57 from tedsta/devel
9prady9 Feb 26, 2016
b088f07
API Catchup to 3.3.0 version
9prady9 Mar 11, 2016
bb8f2da
Improved data generation API and Array creation API
9prady9 Mar 12, 2016
b2c042e
Fixing typos
9prady9 Mar 12, 2016
c3f7921
Added mem_info macro
9prady9 Mar 12, 2016
21972e7
Fixed example code in join_many macro documentation
9prady9 Mar 12, 2016
9514647
Merge pull request #59 from 9prady9/af3.3.0
jramapuram Mar 12, 2016
7ba96af
Fixed documentation tests(example code stubs)
9prady9 Mar 13, 2016
69f1a65
Add build badges from ci to README
9prady9 Mar 21, 2016
58a9fd9
unwrap index printing
Mar 25, 2016
9e0b06f
Merge pull request #61 from arrayfire/hotfix/index_test
9prady9 Mar 25, 2016
96bccdf
more unused fixes
Mar 26, 2016
3c2f70c
add unwrap for set_index calls
Mar 26, 2016
cda3c87
Merge pull request #62 from arrayfire/hotfix/index_test
jramapuram Mar 26, 2016
fe4b481
Add support for partialeq & debug to dim4
jramapuram Mar 30, 2016
e666fd6
Merge pull request #64 from arrayfire/hotfix/derives
9prady9 Apr 4, 2016
f22a5fb
add af_print macro
9prady9 Apr 4, 2016
e403475
add clone and partialeq to all enums
jramapuram Apr 20, 2016
01987e0
Merge pull request #69 from arrayfire/hotfix/enum_traits
9prady9 Apr 21, 2016
755544e
Retain the arrays returned from Features's accessors (#68)
mmetcalfe Apr 23, 2016
d737dd4
Replace Result returns in API with callback based error handling
9prady9 Apr 27, 2016
0e19170
Replace error strings with Error trait descriptions
9prady9 Apr 28, 2016
81df62d
Add static mutex lock for mutable error handler fn handle
9prady9 May 3, 2016
c1ebe05
Revert mutex related commit # f48af77q
9prady9 May 4, 2016
af483c4
FEATURE: Compound assignment operators
9prady9 May 4, 2016
df8c153
Thread safety for error handler function pointer
9prady9 May 17, 2016
8b68882
Remove dead code
9prady9 May 18, 2016
c6846d6
Merge pull request #70 from arrayfire/new_error_handling
9prady9 May 18, 2016
4a3ad46
Add version check for compound assignment operator traits
9prady9 May 18, 2016
9633769
Fix for OSX platform w.r.t static arrays
9prady9 May 20, 2016
8c7385a
Exclude arrayfire submodule from crate package
9prady9 May 20, 2016
895e4e5
Update README with v3.3.0 release information
9prady9 May 20, 2016
a46e59b
Remove time dependency & try bump libc
serprex Jun 5, 2016
a781bff
Replace u64 with usize type in device module fns
9prady9 Jun 6, 2016
dc2a7ed
Merge branch 'serprex-devel' into devel
9prady9 Jun 6, 2016
84b6c59
Bump up dependencies(crates) versions
9prady9 Jun 6, 2016
cb7a6f4
BUGFIX: variable size discrepancy with FFI for Rust enums
9prady9 Jun 8, 2016
7a7d453
v3.3.1 Release
9prady9 Jun 8, 2016
5e16c77
Fix compilation issue with rustc 1.10.0
9prady9 Jul 29, 2016
142b44f
v3.3.2 Release
9prady9 Jul 29, 2016
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
16 changes: 10 additions & 6 deletions 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.2.0"
version = "3.3.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 All @@ -10,14 +10,18 @@ readme = "./README.md"
keywords = ["CUDA", "OpenCL", "ArrayFire", "Compute"]
license = "BSD-3-Clause"
build = "build.rs"
exclude = [
"arrayfire/*",
]

[dependencies]
libc = "0.1.10"
num = "0.1.27"
time = "0.1.32"
libc = "0.2.11"
num = "0.1.32"
lazy_static = "0.2.1"

[build-dependencies.rustc-serialize]
rustc-serialize = "0.3.16"
[build-dependencies]
rustc-serialize = "0.3.19"
rustc_version = "0.1.7"

[lib]
name = "arrayfire"
Expand Down
26 changes: 9 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Arrayfire Rust Bindings
# Arrayfire Rust Bindings [![Join the chat at https://gitter.im/arrayfire/arrayfire-rust](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/arrayfire/arrayfire-rust?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
| Linux | Windows | OSX |
|:-------:|:-------:|:---:|
| [![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.2 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. The wrapper is currently compliant with ArrayFire 3.3 API. If you find any bugs, please report them [here](https://github.com/arrayfire/arrayfire-rust/issues).

## Documentation

Expand All @@ -13,6 +16,9 @@ You can find the most recent updated documentation [here](http://arrayfire.githu

We recommend using Rust 1.5 and higher.

Rust 1.8 stabilized the traits for compound assignment operations. These are automatically enabled
based on the rust version you are using.

## Use from Crates.io [![](http://meritbadge.herokuapp.com/arrayfire)](https://crates.io/crates/arrayfire)

To use the rust bindings for ArrayFire from crates.io, the following requirements are to be met
Expand All @@ -24,7 +30,7 @@ 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.2.0"` to the dependencies section of your project's Cargo.toml file.
4. Add `arrayfire = "3.3.2"` to the dependencies section of your project's Cargo.toml file.

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 @@ -80,20 +86,6 @@ Create a 5-by-3 matrix of random floats on the GPU
...
```

## Issues

You might see something along the lines of :

```bash
dyld: Library not loaded: @rpath/libafopencl.3.dylib
```

You need to add the location of libaf.{dylib, so, dll} to your LD_LIBRARY_PATH.

## Note

This is a work in progress and is not intended for production use.

## Acknowledgements

The ArrayFire library is written by developers at [ArrayFire](http://arrayfire.com) LLC
Expand Down
2 changes: 1 addition & 1 deletion arrayfire
Submodule arrayfire updated 459 files
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* -- Lots of reuse from: https://github.com/alexcrichton/git2-rs/blob/master/libgit2-sys/build.rs */
extern crate rustc_serialize;
extern crate rustc_version;

use std::env;
use std::fs;
Expand Down Expand Up @@ -450,4 +451,8 @@ fn main() {
for backend_dir in backend_dirs.iter() {
println!("cargo:rustc-link-search=native={}", backend_dir);
}
// Directly check a semver version requirment
if rustc_version::version_matches(">= 1.8.0") {
println!("cargo:rustc-cfg=op_assign");
}
}
85 changes: 34 additions & 51 deletions examples/helloworld.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[macro_use(af_print)]
extern crate arrayfire as af;

use af::*;
Expand All @@ -9,94 +10,76 @@ fn main() {

let num_rows: u64 = 5;
let num_cols: u64 = 3;
let values: &[f32] = &[1.0, 2.0, 3.0];
let indices = Array::new(Dim4::new(&[3, 1, 1, 1]), values, Aftype::F32).unwrap();
let values: [f32; 3] = [1.0, 2.0, 3.0];
let indices = Array::new(&values, Dim4::new(&[3, 1, 1, 1]));

let dims = Dim4::new(&[num_rows, num_cols, 1, 1]);

println!("Create a 5-by-3 matrix of random floats on the GPU");
let a = match randu(dims, Aftype::F32) {
Ok(value) => value,
Err(error) => panic!("{}", error),
};
print(&a);
let a = randu::<f32>(dims);
af_print!("Create a 5-by-3 matrix of random floats on the GPU", a);

println!("Element-wise arithmetic");
let b = sin(&a)
.and_then(|x| add(&x, &1.5, false))
.unwrap();
let b = add(&sin(&a), &1.5f32, false);

let b2 = sin(&a).
and_then(|x| {
cos(&a)
.and_then(|y| add(&x, &y, false))
})
.unwrap();
let b2 = add(&sin(&a), &cos(&a), false);

let b3 = ! &a;
println!("sin(a) + 1.5 => "); print(&b);
println!("sin(a) + cos(a) => "); print(&b2);
println!("!a => "); print(&b3);
af_print!("sin(a) + 1.5 => ", b);
af_print!("sin(a) + cos(a) => ", b2);
af_print!("!a => ", b3);

let test = &a + &b;
println!("a + b"); print(&test);
let test = a.clone() + b.clone();
af_print!("a + b", test);

// Index array using sequences
let seqs = &[Seq::new(1.0, 3.0, 1.0), Seq::default()];
let sub = index(&a, seqs).unwrap();
println!("a(seq(1,3,1), span)"); print(&sub);
let seqs = &[Seq::new(1u32, 3, 1), Seq::default()];
let sub = index(&a, seqs);
af_print!("a(seq(1,3,1), span)", sub);

//Index array using array and sequence
let seq4gen = Seq::new(0.0, 2.0, 1.0);
let seq4gen = Seq::new(0u32, 2, 1);

let mut idxrs = match Indexer::new() {
Ok(v) => v,
Err(e) => panic!("{}",e),
};
let mut idxrs = Indexer::new();
idxrs.set_index(&indices, 0, None);
idxrs.set_index(&seq4gen, 1, Some(false));

let sub2 = index_gen(&a, idxrs).unwrap();
println!("a(indices, seq(0, 2, 1))"); print(&sub2);
let sub2 = index_gen(&a, idxrs);
af_print!("a(indices, seq(0, 2, 1))", sub2);

// printf("Negate the first three elements of second column\n");
// B(seq(0, 2), 1) = B(seq(0, 2), 1) * -1;
// af_print(B);

println!("Fourier transform the result");
fft(&b, 1.0, 0).map(|x| print(&x));
print(&fft(&b, 1.0, 0));

println!("Grab last row & col of the random matrix");
print(&a);
print(&row(&a, num_rows - 1).unwrap());
print(&col(&a, num_cols - 1).unwrap());
print(&row(&a, num_rows - 1));
print(&col(&a, num_cols - 1));

println!("Set last row to 1's");
let r_dims = Dim4::new(&[3, 1, 1, 1]);
let r_input: [f32; 3] = [1.0, 1.0, 1.0];
let r = Array::new(r_dims, &r_input, Aftype::F32).unwrap();
print(&set_row(&a, &r, num_rows - 1).unwrap());
let r = Array::new(&r_input, r_dims);
let ur = set_row(&a, &r, num_rows - 1);
af_print!("Set last row to 1's", ur);

println!("Create 2-by-3 matrix from host data");
let d_dims = Dim4::new(&[2, 3, 1, 1]);
let d_input: [i32; 6] = [1, 2, 3, 4, 5, 6];
let d = &Array::new(d_dims, &d_input, Aftype::S32).unwrap();
print(d);
let d = Array::new(&d_input, d_dims);
af_print!("Create 2-by-3 matrix from host data", d);

// printf("Copy last column onto first\n");
// D.col(0) = D.col(end);
// af_print(D);

// // Sort A
println!("Sort A and print sorted array and corresponding indices");
sort_index(&a, 0, true)
.map(| x | {
print(&x.0);
print(&x.1);
});

println!("u8 constant array");
let u8_cnst = &constant(1 as u8, dims).unwrap();
print(u8_cnst);
println!("Is u8_cnst array float precision type ? {}", u8_cnst.is_single().unwrap());
let x = sort_index(&a, 0, true);
print(&x.0);
print(&x.1);

let u8_cnst = &constant(1 as u8, dims);
af_print!("u8 constant array", u8_cnst);
println!("Is u8_cnst array float precision type ? {}", u8_cnst.is_single());
}
36 changes: 12 additions & 24 deletions examples/histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,22 @@ fn main() {
let assets_dir = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap())
.join("arrayfire").join("assets").join("examples").join("images");

let img_wnd = match Window::new(480, 640, String::from("Input Image")) {
Ok(v) => { v.set_position(100, 100).unwrap(); v },
Err(e)=> panic!("Window creation failed, exiting: {}", e),
};

let hst_wnd = match Window::new(512, 512, String::from("Input Image Histogram")) {
Ok(v) => { v.set_position(600, 100).unwrap(); v },
Err(e)=> panic!("Window creation failed, exiting: {}", e),
};

let (man, hst) = match load_image(format!("{}/man.jpg", assets_dir.display()), false) {
Ok(v) => match histogram(&v, 256, 0.0, 255.0) {
Ok(h) => (v, h),
Err(e)=> panic!("Histogram computation failed, exiting: {}", e),
},
Err(e)=> panic!("Image loading failed, exiting: {}", e),
};

let disp_img = man.dims()
.and_then(|x| constant(255 as f32, x))
.and_then(|x| div(&man, &x, false))
.unwrap();
let img_wnd = Window::new(480, 640, String::from("Input Image"));
img_wnd.set_position(100, 100);

let hst_wnd = Window::new(512, 512, String::from("Input Image Histogram"));
hst_wnd.set_position(600, 100);

let man = load_image(format!("{}/man.jpg", assets_dir.display()), false);
let hst = histogram(&man, 256, 0.0, 255.0);

let disp_img = div(&man, &constant(255 as f32, man.dims()), false);

loop {
img_wnd.draw_image(&disp_img, None);
hst_wnd.draw_hist(&hst, 0.0, 255.0, None);

if img_wnd.is_closed().unwrap() == true { break; }
if hst_wnd.is_closed().unwrap() == true { break; }
if img_wnd.is_closed() == true { break; }
if hst_wnd.is_closed() == true { break; }
}
}
29 changes: 16 additions & 13 deletions examples/pi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[macro_use(mem_info)]
extern crate arrayfire as af;
extern crate time;

use time::PreciseTime;
use std::time::Instant;
use af::*;

#[allow(unused_must_use)]
Expand All @@ -12,21 +12,24 @@ fn main() {
let samples = 20_000_000;
let dims = Dim4::new(&[samples, 1, 1, 1]);

let x = &randu(dims, Aftype::F32).unwrap();
let y = &randu(dims, Aftype::F32).unwrap();
let x = &randu::<f32>(dims);
let y = &randu::<f32>(dims);

let start = PreciseTime::now();
let start = Instant::now();

mem_info!("Before benchmark");

for bench_iter in 0..100 {
let pi_val = add(&mul(x, x, false).unwrap(), &mul(y, y, false).unwrap(), false)
.and_then( |z| sqrt(&z) )
.and_then( |z| le(&z, &constant(1, dims).unwrap(), false) )
.and_then( |z| sum_all(&z) )
.map( |z| z.0 * 4.0/(samples as f64) )
.unwrap();
let xsqrd = &mul(x, x, false);
let ysqrd = &mul(y, y, false);
let xplusy = &add(xsqrd, ysqrd, false);
let root = &sqrt(xplusy);
let cnst = &constant(1, dims);
let (real, imag) = sum_all(&le(root, cnst, false));
let pi_val = real*4.0/(samples as f64);
}

let end = PreciseTime::now();
println!("Estimated Pi Value in {:?}", start.elapsed());

println!("Estimated Pi Value in {} seconds", start.to(end) / 100);
mem_info!("After benchmark");
}
10 changes: 3 additions & 7 deletions examples/snow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@ fn main() {
set_device(0);
info();

let wnd = match Window::new(1280, 720, String::from("Snow")) {
Ok(v) => v,
Err(e)=> panic!("Window creation failed, exiting"),
};
let wnd = Window::new(1280, 720, String::from("Snow"));

let dims = Dim4::new(&[1280, 720, 3, 1]);

loop {
randu(dims, Aftype::F32).as_ref()
.map(|arr| wnd.draw_image(arr, None));
wnd.draw_image(&randu::<f32>(dims), None);

if wnd.is_closed().unwrap() == true { break; }
if wnd.is_closed() == true { break; }
}
}
Loading