#CUDA #OpenCL #Compute #ArrayFire


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.

14 stable releases

✓ Uses Rust 2018 edition

3.7.0 Mar 14, 2020
3.6.2 Jul 25, 2019
3.6.0 Sep 27, 2018
3.5.0 Jun 28, 2017
3.2.0-rc0 Nov 14, 2015

#15 in Concurrency

Download history 26/week @ 2020-02-09 59/week @ 2020-02-16 59/week @ 2020-02-23 5/week @ 2020-03-01 44/week @ 2020-03-08 35/week @ 2020-03-15 82/week @ 2020-03-22 17/week @ 2020-03-29 41/week @ 2020-04-05 102/week @ 2020-04-12 20/week @ 2020-04-19 17/week @ 2020-04-26 15/week @ 2020-05-03 9/week @ 2020-05-10 18/week @ 2020-05-17 28/week @ 2020-05-24

175 downloads per month
Used in less than 7 crates


10K SLoC

Arrayfire Rust Bindings

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.

arrayfire-rust ArrayFire
M.m.p1 M.m.p2

Only, Major(M) & Minor(m) version numbers need to match. p1 and p2 are patch/fix updates for arrayfire-rust & ArrayFire respectively, and they don't need to match.


You can find the most recent updated documentation here.


Supported platforms

Linux, Windows and OSX. Rust 1.15.1 or higher is required.

Use from Crates.io

To use the rust bindings for ArrayFire from crates.io, the following requirements are to be met first.

  1. Download and install ArrayFire binaries based on your operating system.
  2. Set the evironment variable AF_PATH to point to ArrayFire installation root folder.
  3. Make sure to add the path to lib files to your path environment variables.
    • On Linux: do export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$AF_PATH/lib64
    • On Windows: Add %AF_PATH%\lib to your PATH environment variable.
  4. Add arrayfire = "3.7" to the dependencies section of your project's Cargo.toml file. Make sure to change the version to latest available.

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.

Build from Source

Edit build.conf to modify the build flags. The structure is a simple JSON blob. Currently Rust does not allow key:value pairs to be passed from the CLI. To use an existing ArrayFire installation modify the first three JSON values. You can install ArrayFire using one of the following two ways.

To build arrayfire submodule available in the rust wrapper, you have to do the following.

git submodule update --init --recursive
cargo build

This is recommended way to build Rust wrapper since the submodule points to the most compatible version of ArrayFire the Rust wrapper has been tested with. You can find the ArrayFire dependencies below.


let num_rows: u64 = 5;
let num_cols: u64 = 3;
let dims = Dim4::new(&[num_rows, num_cols, 1, 1]);
let a = randu::<f32>(dims);
af_print!("Create a 5-by-3 matrix of random floats on the GPU", a);

Sample output

~/p/arrayfire_rust> cargo run --example helloworld
Create a 5-by-3 matrix of random floats on the GPU
[5 3 1 1]
    0.7402     0.4464     0.7762
    0.9210     0.6673     0.2948
    0.0390     0.1099     0.7140
    0.9690     0.4702     0.3585
    0.9251     0.5132     0.6814


The ArrayFire library is written by developers at ArrayFire LLC with contributions from several individuals.

The developers at ArrayFire LLC have received partial financial support from several grants and institutions. Those that wish to receive public acknowledgement are listed below:


This material is based upon work supported by the DARPA SBIR Program Office under Contract Numbers W31P4Q-14-C-0012 and W31P4Q-15-C-0008. Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the DARPA SBIR Program Office.


~15K SLoC