Do more. Code less. Free software for GPU computing.
<scroll to top>

Getting Started

Table of contents

This is a quick introduction to getting your first ArrayFire example running.

Requirements

Compiling and running examples requires:

All included examples assume the ArrayFire directory structure to find headers and common build files. If you wish to build projects outside this directory structure, be sure to set the AF_PATH environment variable to point to the ArrayFire install, or adjust it directly in the Makefile or project configuration.

Licensing

By default, ArrayFire authenticates for free using hosted license servers at www.accelereyes.com (ports 27001 and 27901).

ArrayFire Pro adds several features not found in the free version, including the ability to run offline, run multiple devices in parallel, double-precision linear algebra, sparse linear algebra, and more. Use the Manage Licenses page to start a Pro trial or download a purchased license file.

You can save your license file to one of several locations depending on operating system:

Windows

  1. The CUDA Toolkit installation will set the CUDA_INC_PATH, CUDA_LIB_PATH and CUDA_BIN_PATH environment variables for you and will also update your PATH variable to include the necessary DLLs.
  2. ArrayFire examples come with Visual Studio solution files for both VS 2008 and VS 2010. To build ArrayFire examples, open the project solution file, e.g. AF_PATH/examples/misc/hello_world_vs2008.sln for VS2008. Choose the appropriate configuration (e.g. Win32 Release). When you build and run, you should see something like the output below.
  3. (Recommended) To build and run ArrayFire projects outside the example directory, e.g. move an ArrayFire example folder elsewhere:
    1. Set the AF_PATH environment variable to where you installed ArrayFire. This is used to locate ArrayFire headers and libraries to link against (libaf.lib, libafGFX.lib).
    2. Add the ArrayFire DLLs to your PATH environment variable
      • Win64: %AF_PATH%/examples/bin_x64
      • Win32: %AF_PATH%/examples/bin_Win32

Linux and MacOSX

  1. The examples assume the CUDA Toolkit is installed at /usr/local/cuda or nvcc is in the PATH. You can specify an alternate installation by setting the CUDA environment variable (e.g., CUDA=/opt/software/cuda4.0) or modifying the default variable setting in $AF_PATH/examples/common.mk.
  2. (Recommended) To build ArrayFire examples outside the installed directory, set the AF_PATH environment variable to where you installed ArrayFire.
  3. MacOSX needs X11 to be running only for graphical examples.

sh$ cd arrayfire/examples/misc
sh$ make hello_world
sh$ ./hello_world
ArrayFire v1.0 (build 2746as9) by AccelerEyes (32-bit Linux)
License Type: Concurrent Network (27000@www.accelereyes.com)
Addons: none
CUDA toolkit 4.0, driver 290.10
GPU0 Quadro 600, 1024 MB, Compute 2.1 (single,double)
Display Device: GPU0 Quadro 600
Memory Usage: 852 MB free (1024 MB total)

create a 5-by-3 matrix of random floats on the GPU
A =
        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

element-wise arithmetic
B =
        0.7744     0.5317     0.8006
        0.8962     0.7189     0.3905
        0.1390     0.2097     0.7549
        0.9243     0.5531     0.4509
        0.8987     0.5910     0.7299

Fourier transform the result
C =
        3.6327 +    0.0000i    2.6043 +    0.0000i    3.1267 +    0.0000i
        0.4689 +    0.4640i    0.3193 +    0.0802i    0.1713 +    0.1441i
       -0.3491 -    0.7454i   -0.2923 -    0.4018i    0.2667 +    0.4886i
       -0.3491 +    0.7454i   -0.2923 +    0.4018i    0.2667 -    0.4886i
        0.4689 -    0.4640i    0.3193 -    0.0802i    0.1713 -    0.1441i

grab last row
c =
        0.4689 -    0.4640i    0.3193 -    0.0802i    0.1713 -    0.1441i

zero out every other column
negate the first three elements of middle column
B =
        0.0000    -0.5317     0.0000
        0.0000    -0.7189     0.0000
        0.0000    -0.2097     0.0000
        0.0000     0.5531     0.0000
        0.0000     0.5910     0.0000

create 2-by-3 matrix from host data
D =
        1.0000     3.0000     5.0000
        2.0000     4.0000     6.0000

copy last column onto first
D =
        5.0000     3.0000     5.0000
        6.0000     4.0000     6.0000
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines