Skip to content

Commit 6fd3d38

Browse files
authored
Merge pull request #81 from arrayfire/devel
Master Update
2 parents f668c4b + 142b44f commit 6fd3d38

32 files changed

+1746
-1375
lines changed

Cargo.toml

+10-6
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.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"
@@ -10,14 +10,18 @@ readme = "./README.md"
1010
keywords = ["CUDA", "OpenCL", "ArrayFire", "Compute"]
1111
license = "BSD-3-Clause"
1212
build = "build.rs"
13+
exclude = [
14+
"arrayfire/*",
15+
]
1316

1417
[dependencies]
15-
libc = "0.1.10"
16-
num = "0.1.27"
17-
time = "0.1.32"
18+
libc = "0.2.11"
19+
num = "0.1.32"
20+
lazy_static = "0.2.1"
1821

19-
[build-dependencies.rustc-serialize]
20-
rustc-serialize = "0.3.16"
22+
[build-dependencies]
23+
rustc-serialize = "0.3.19"
24+
rustc_version = "0.1.7"
2125

2226
[lib]
2327
name = "arrayfire"

README.md

+9-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
# Arrayfire Rust Bindings
1+
# 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)
2+
| Linux | Windows | OSX |
3+
|:-------:|:-------:|:---:|
4+
| [![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/) |
25

3-
[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).
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.3 API. If you find any bugs, please report them [here](https://github.com/arrayfire/arrayfire-rust/issues).
47

58
## Documentation
69

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

1417
We recommend using Rust 1.5 and higher.
1518

19+
Rust 1.8 stabilized the traits for compound assignment operations. These are automatically enabled
20+
based on the rust version you are using.
21+
1622
## Use from Crates.io [![](http://meritbadge.herokuapp.com/arrayfire)](https://crates.io/crates/arrayfire)
1723

1824
To use the rust bindings for ArrayFire from crates.io, the following requirements are to be met
@@ -24,7 +30,7 @@ first.
2430
3. Make sure you add the path to library files to your path environment variables.
2531
- On Linux & OSX: do `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$AF_PATH/lib`
2632
- On Windows: Add `%AF_PATH%\lib` to your PATH environment variable.
27-
4. Add `arrayfire = "3.2.0"` to the dependencies section of your project's Cargo.toml file.
33+
4. Add `arrayfire = "3.3.2"` to the dependencies section of your project's Cargo.toml file.
2834

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

@@ -80,20 +86,6 @@ Create a 5-by-3 matrix of random floats on the GPU
8086
...
8187
```
8288

83-
## Issues
84-
85-
You might see something along the lines of :
86-
87-
```bash
88-
dyld: Library not loaded: @rpath/libafopencl.3.dylib
89-
```
90-
91-
You need to add the location of libaf.{dylib, so, dll} to your LD_LIBRARY_PATH.
92-
93-
## Note
94-
95-
This is a work in progress and is not intended for production use.
96-
9789
## Acknowledgements
9890

9991
The ArrayFire library is written by developers at [ArrayFire](http://arrayfire.com) LLC

arrayfire

Submodule arrayfire updated 459 files

build.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* -- Lots of reuse from: https://github.com/alexcrichton/git2-rs/blob/master/libgit2-sys/build.rs */
22
extern crate rustc_serialize;
3+
extern crate rustc_version;
34

45
use std::env;
56
use std::fs;
@@ -450,4 +451,8 @@ fn main() {
450451
for backend_dir in backend_dirs.iter() {
451452
println!("cargo:rustc-link-search=native={}", backend_dir);
452453
}
454+
// Directly check a semver version requirment
455+
if rustc_version::version_matches(">= 1.8.0") {
456+
println!("cargo:rustc-cfg=op_assign");
457+
}
453458
}

examples/helloworld.rs

+34-51
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[macro_use(af_print)]
12
extern crate arrayfire as af;
23

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

1011
let num_rows: u64 = 5;
1112
let num_cols: u64 = 3;
12-
let values: &[f32] = &[1.0, 2.0, 3.0];
13-
let indices = Array::new(Dim4::new(&[3, 1, 1, 1]), values, Aftype::F32).unwrap();
13+
let values: [f32; 3] = [1.0, 2.0, 3.0];
14+
let indices = Array::new(&values, Dim4::new(&[3, 1, 1, 1]));
1415

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

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

2421
println!("Element-wise arithmetic");
25-
let b = sin(&a)
26-
.and_then(|x| add(&x, &1.5, false))
27-
.unwrap();
22+
let b = add(&sin(&a), &1.5f32, false);
2823

29-
let b2 = sin(&a).
30-
and_then(|x| {
31-
cos(&a)
32-
.and_then(|y| add(&x, &y, false))
33-
})
34-
.unwrap();
24+
let b2 = add(&sin(&a), &cos(&a), false);
3525

3626
let b3 = ! &a;
37-
println!("sin(a) + 1.5 => "); print(&b);
38-
println!("sin(a) + cos(a) => "); print(&b2);
39-
println!("!a => "); print(&b3);
27+
af_print!("sin(a) + 1.5 => ", b);
28+
af_print!("sin(a) + cos(a) => ", b2);
29+
af_print!("!a => ", b3);
4030

41-
let test = &a + &b;
42-
println!("a + b"); print(&test);
31+
let test = a.clone() + b.clone();
32+
af_print!("a + b", test);
4333

4434
// Index array using sequences
45-
let seqs = &[Seq::new(1.0, 3.0, 1.0), Seq::default()];
46-
let sub = index(&a, seqs).unwrap();
47-
println!("a(seq(1,3,1), span)"); print(&sub);
35+
let seqs = &[Seq::new(1u32, 3, 1), Seq::default()];
36+
let sub = index(&a, seqs);
37+
af_print!("a(seq(1,3,1), span)", sub);
4838

4939
//Index array using array and sequence
50-
let seq4gen = Seq::new(0.0, 2.0, 1.0);
40+
let seq4gen = Seq::new(0u32, 2, 1);
5141

52-
let mut idxrs = match Indexer::new() {
53-
Ok(v) => v,
54-
Err(e) => panic!("{}",e),
55-
};
42+
let mut idxrs = Indexer::new();
5643
idxrs.set_index(&indices, 0, None);
5744
idxrs.set_index(&seq4gen, 1, Some(false));
5845

59-
let sub2 = index_gen(&a, idxrs).unwrap();
60-
println!("a(indices, seq(0, 2, 1))"); print(&sub2);
46+
let sub2 = index_gen(&a, idxrs);
47+
af_print!("a(indices, seq(0, 2, 1))", sub2);
6148

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

6653
println!("Fourier transform the result");
67-
fft(&b, 1.0, 0).map(|x| print(&x));
54+
print(&fft(&b, 1.0, 0));
6855

6956
println!("Grab last row & col of the random matrix");
7057
print(&a);
71-
print(&row(&a, num_rows - 1).unwrap());
72-
print(&col(&a, num_cols - 1).unwrap());
58+
print(&row(&a, num_rows - 1));
59+
print(&col(&a, num_cols - 1));
7360

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

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

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

9076
// // Sort A
9177
println!("Sort A and print sorted array and corresponding indices");
92-
sort_index(&a, 0, true)
93-
.map(| x | {
94-
print(&x.0);
95-
print(&x.1);
96-
});
97-
98-
println!("u8 constant array");
99-
let u8_cnst = &constant(1 as u8, dims).unwrap();
100-
print(u8_cnst);
101-
println!("Is u8_cnst array float precision type ? {}", u8_cnst.is_single().unwrap());
78+
let x = sort_index(&a, 0, true);
79+
print(&x.0);
80+
print(&x.1);
81+
82+
let u8_cnst = &constant(1 as u8, dims);
83+
af_print!("u8 constant array", u8_cnst);
84+
println!("Is u8_cnst array float precision type ? {}", u8_cnst.is_single());
10285
}

examples/histogram.rs

+12-24
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,22 @@ fn main() {
1313
let assets_dir = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap())
1414
.join("arrayfire").join("assets").join("examples").join("images");
1515

16-
let img_wnd = match Window::new(480, 640, String::from("Input Image")) {
17-
Ok(v) => { v.set_position(100, 100).unwrap(); v },
18-
Err(e)=> panic!("Window creation failed, exiting: {}", e),
19-
};
20-
21-
let hst_wnd = match Window::new(512, 512, String::from("Input Image Histogram")) {
22-
Ok(v) => { v.set_position(600, 100).unwrap(); v },
23-
Err(e)=> panic!("Window creation failed, exiting: {}", e),
24-
};
25-
26-
let (man, hst) = match load_image(format!("{}/man.jpg", assets_dir.display()), false) {
27-
Ok(v) => match histogram(&v, 256, 0.0, 255.0) {
28-
Ok(h) => (v, h),
29-
Err(e)=> panic!("Histogram computation failed, exiting: {}", e),
30-
},
31-
Err(e)=> panic!("Image loading failed, exiting: {}", e),
32-
};
33-
34-
let disp_img = man.dims()
35-
.and_then(|x| constant(255 as f32, x))
36-
.and_then(|x| div(&man, &x, false))
37-
.unwrap();
16+
let img_wnd = Window::new(480, 640, String::from("Input Image"));
17+
img_wnd.set_position(100, 100);
18+
19+
let hst_wnd = Window::new(512, 512, String::from("Input Image Histogram"));
20+
hst_wnd.set_position(600, 100);
21+
22+
let man = load_image(format!("{}/man.jpg", assets_dir.display()), false);
23+
let hst = histogram(&man, 256, 0.0, 255.0);
24+
25+
let disp_img = div(&man, &constant(255 as f32, man.dims()), false);
3826

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

43-
if img_wnd.is_closed().unwrap() == true { break; }
44-
if hst_wnd.is_closed().unwrap() == true { break; }
31+
if img_wnd.is_closed() == true { break; }
32+
if hst_wnd.is_closed() == true { break; }
4533
}
4634
}

examples/pi.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
#[macro_use(mem_info)]
12
extern crate arrayfire as af;
2-
extern crate time;
33

4-
use time::PreciseTime;
4+
use std::time::Instant;
55
use af::*;
66

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

15-
let x = &randu(dims, Aftype::F32).unwrap();
16-
let y = &randu(dims, Aftype::F32).unwrap();
15+
let x = &randu::<f32>(dims);
16+
let y = &randu::<f32>(dims);
1717

18-
let start = PreciseTime::now();
18+
let start = Instant::now();
19+
20+
mem_info!("Before benchmark");
1921

2022
for bench_iter in 0..100 {
21-
let pi_val = add(&mul(x, x, false).unwrap(), &mul(y, y, false).unwrap(), false)
22-
.and_then( |z| sqrt(&z) )
23-
.and_then( |z| le(&z, &constant(1, dims).unwrap(), false) )
24-
.and_then( |z| sum_all(&z) )
25-
.map( |z| z.0 * 4.0/(samples as f64) )
26-
.unwrap();
23+
let xsqrd = &mul(x, x, false);
24+
let ysqrd = &mul(y, y, false);
25+
let xplusy = &add(xsqrd, ysqrd, false);
26+
let root = &sqrt(xplusy);
27+
let cnst = &constant(1, dims);
28+
let (real, imag) = sum_all(&le(root, cnst, false));
29+
let pi_val = real*4.0/(samples as f64);
2730
}
2831

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

31-
println!("Estimated Pi Value in {} seconds", start.to(end) / 100);
34+
mem_info!("After benchmark");
3235
}

examples/snow.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,13 @@ fn main() {
88
set_device(0);
99
info();
1010

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

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

1815
loop {
19-
randu(dims, Aftype::F32).as_ref()
20-
.map(|arr| wnd.draw_image(arr, None));
16+
wnd.draw_image(&randu::<f32>(dims), None);
2117

22-
if wnd.is_closed().unwrap() == true { break; }
18+
if wnd.is_closed() == true { break; }
2319
}
2420
}

0 commit comments

Comments
 (0)