• Stars
    star
    120
  • Rank 295,983 (Top 6 %)
  • Language
    C++
  • License
    BSD 3-Clause "New...
  • Created over 9 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ArrayFire.js - ArrayFire for Node.js

NOTICE:

As of 0.16.0 this module has been renamed from arrayfire_js to arrayfire-js. The old arrayfire_js module will be available on the npm for a while.

ArrayFire.js

Please follow this issue for tracking the progress towards release of 1.0.0-beta.

About 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 more accessible."

You can read its introduction int its documentation's index page. It's basically a math accelerator C++ library supporting CPU and GPU based backends on Windows, Linux and Mac. And it's just awesome. It's extremely simple to write the most complex mathematical, statistical, logical computations, image transformations and computer vision algorigthms with it, just a few lines of code. It has excellent batching capability that takes simple operations, make a big computation from them, and runs all at once on the GPU device.

About ArrayFire.js

ArrayFire.js is the Node.js bindings for ArrayFire, it uses CMake.js as of its build system. It takes Node.js' insane level of productivity and mix that with ArrayFire's insane level of performance and simplicity. You'll get something like Matlab just in familiar JavaScript with performance level of x100+ compared to V8 computation preformance (with a good GPU).

Requirements

  • Download and install ArrayFire (3.x RTM is supported right now). Don't forget to add %AF_PATH%\lib directory to PATH on Windows!
  • On Linux or Mac install dependencies (see Linux and Mac docs)
  • Don't forget to install CMake

Install

Before installing location of the ArrayFire installation directory have to be configured for CMake.js. There are two options:

1. Using npm config

for current user:

npm config set cmake_af_path "path_to_arrayfire_installation_directory"

for all users (global)

npm config set cmake_af_path "path_to_arrayfire_installation_directory" --global

2. Setting AF_PATH environment variable

AF_PATH="path_to_arrayfire_installation_directory"

On Windows the installer do this for you, so there is nothing to do on this platform, though.

The above have to be done only once. After you can install ArrayFire.js from the npm:

npm install arrayfire-js --save

Usage

// CPU
var af = require("arrayfire-js")("CPU");
// OpenCL
var af = require("arrayfire-js")("OpenCL");
// CUDA
var af = require("arrayfire-js")("CUDA");

Examples

Calculating pi

Port of the PI calculator from ArrayFire documentation:

C++

// sample 40 million points on the GPU
array x = randu(20e6), y = randu(20e6);
array dist = sqrt(x * x + y * y);

// pi is ratio of how many fell in the unit circle
float num_inside = sum<float>(dist < 1);
float pi = 4.0 * num_inside / 20e6;
af_print(pi);

JavaScript

Notice: Remember, in Node.js everything that blocks or might blocks should be asynchronous, so it is advised to call asynchronous variants of ArrayFire.js functions, however there are synchronous counterparts available too for supporting REPL scenarios. (I suggest use ES6 generators instead of callback hell or even instead of bare promises).

const numberOfPoints = 20000000;

// ...

let x = af.randu(numberOfPoints, af.dtype.f32);
let y = af.randu(numberOfPoints, af.dtype.f32);
let dist = af.sqrt(x.mul(x).add(y.mul(y)));
let numInside = yield af.sumAsync(dist.lt(1));
let piVal = (4.0 *  numInside) / numberOfPoints;

console.log(`PI = ${piVal}`);

It's included in the examples folder. To run on:

  • io.js, enter: iojs examples/es6/bechmarks/pi.js
  • Node.js 0.12 or above, enter: node --harmony examples/es6/bechmarks/pi.js
  • Node.js below 0.12, enter: node examples/es5/bechmarks/pi.js

Neural Network

There is an example of a neural network with batch backpropagation trained to learn the famous MNIST data set. It will run on the fastest device available.

It's in the examples folder. To run on:

  • io.js, enter: iojs examples/es6/machine-learning/neuralNetwork.js
  • Node.js 0.12 or above, enter: node --harmony examples/es6/machine-learning/neuralNetwork.js
  • Node.js below 0.12, enter: node examples/es5/machine-learning/neuralNetwork.js

Performance on Linux Mint x64, i5 3570, Radeon R9:

  • CPU platform: 0.8 sec / epoch
  • OpenCL platform on CPU: 1.0 sec / epoch
  • OpenCL platform on GPU: 0.28 sec / epoch

API Docs

http://arrayfire.github.io/arrayfire-js

Wanna Contribute?

PRs are welcome, but please read the Contributing Guide first.

License

New BSD

Copyright (c) 2014-2015, ArrayFire
Copyright (c) 2015 Gábor MezÅ‘ aka unbornchikken ([email protected])
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

 * Redistributions in binary form must reproduce the above copyright notice, this
  list of conditions and the following disclaimer in the documentation and/or
  other materials provided with the distribution.

 * Neither the name of the ArrayFire nor the names of its
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

More Repositories

1

arrayfire

ArrayFire: a general purpose GPU library.
C++
4,549
star
2

arrayfire-rust

Rust wrapper for ArrayFire
Rust
815
star
3

arrayfire-python

Python bindings for ArrayFire: A general purpose GPU library.
Python
418
star
4

forge

High Performance Visualization
C++
226
star
5

arrayfire-ml

ArrayFire's Machine Learning Library.
C++
102
star
6

arrayfire-dotnet

.NET wrapper for ArrayFire
C#
78
star
7

androidcl

Sample app that runs OpenCL kernels to process camera feed on Android devices
C++
76
star
8

arrayfire-haskell

Haskell bindings to ArrayFire
Haskell
60
star
9

arrayfire-rb

Ruby wrapper for ArrayFire
C
37
star
10

arrayfire-java

Java wrapper for ArrayFire
Java
35
star
11

xilinx_demos

OpenCL Demos for Xilinx FPGAs
C++
31
star
12

arrayfire-fortran

Fortran wrapper for ArrayFire
Fortran
24
star
13

arrayfire-r

R wrapper for ArrayFire
R
22
star
14

arrayfire-go

Go bindings for arrayfire
Go
16
star
15

cuda_deployment_tutorial

Scripts to Deploy GPU Enabled Containers
Shell
13
star
16

arrayfire_opengl_interop

Code sample to show interoperability between ArrayFire and OpenGL.
C++
12
star
17

arrayfire-windows-scripts

Batch Scripts for Building ArrayFire on Windows
Batchfile
11
star
18

arrayfire-lua

Lua wrapper for ArrayFire
Lua
10
star
19

valhalla

Benchmarks for Open Source Libraries with Parallel Vector algorithms.
CMake
8
star
20

arrayfire-project-templates

Template Projects for ArrayFire
CMake
7
star
21

arrayfire-docker

Dockerfile for Building and Using ArrayFire https://github.com/arrayfire/arrayfire.git
Dockerfile
6
star
22

arrayfire-api-cheat-sheet

A quick reference of arrayfire library API; equivalent API in it's language wrappers and other math libraries.
6
star
23

ml_lab

Machine Learning Lab
C++
6
star
24

arrayfire-data

ArrayFire Test Data
5
star
25

ITK-ArrayFire-Bridge-Tutorial

Hands-on tutorial on how to combine ITK with ArrayFire http://www.itk.org
C++
5
star
26

arrayfire-benchmark

Benchmark software for ArrayFire
C++
5
star
27

arrayfire-d

D-lang bindings for arrayfire
D
4
star
28

afQuantumSim

ArrayFire Quantum Simulator
C++
4
star
29

threads

C++
4
star
30

d3m-arrayfire-primitives

DARPA D3M TA1 Accelerated Primitives
Python
3
star
31

assets

Assets for the ArrayFire documentation
3
star
32

freetype2

C
2
star
33

arrayfire-lisp

Lisp bindings for ArrayFire
2
star
34

arrayfire-extras

Add-on functionality for the ArrayFire library
2
star
35

arrayfire-binary-python-wrapper

A python thin wrapper for ArrayFire library
Python
2
star
36

arrayfire-torch

Torch wrapper for ArrayFire
1
star
37

arrayfire.github.io

ArrayFire documentation
HTML
1
star
38

af-sklearn-monkeypatch

Monkey-patch for scikit-learn with accelerated ArrayFire components.
Python
1
star