Documentation
Project Setup

# Creating or Integrating ArrayFire into Your Projects

The goal of ArrayFire is to not only work well with your code, but be extremely easy to integrate into your projects. This page lists the steps required to create a project for ArrayFire from scratch. User can also refer to this page to see how to integrate ArrayFire into an existing project by looking at the include directories and libraries sections.

For further configuration settings, you can refer to the examples.

# On Windows using Visual Studio

## Setting up Environment Variables

• Before beginning, check that the AF_PATH and CUDA_PATH variables are defined in environment variables and point to the correct directories.
• Also ensure that AF_PATH/lib64 and CUDA_PATH/bin are a part the PATH variable.

## Creating the Project and Configuring for 64-bit

1. Open Visual Studio and click File -> New -> Project.
2. You can create either a C/C++ project or a CUDA project. The CUDA project gives the option to have custom CUDA code in the project. If you are using OpenCL, create a regular C/C++ project.
3. Enter the project name and location of your preference.
4. ArrayFire works only with 64-bit. To set this as active, go to Build -> Configuration Manager.
5. In the Configuration Manager, click the "Active Solution Platforms" drop down and choose "x64".

1. Right click the project and open "Properties". Here, you may want to select the active platform and configurations from the drop downs or select all configurations.
2. If you are using a regular C/C++ project (or using OpenCL), go to Configuration Properties -> C/C++ -> General. If you are using a CUDA project, go to Configuration Properties -> CUDA C/C++ -> Common
• In "Additional Include Directories" enter:
• For CUDA : "$(AF_PATH)\include;$(CUDA_PATH)\include;"
• For OpenCL: "$(AF_PATH)\include;" 3. If you are using a CUDA C/C++ project, you may want to set the compute version of your GPU (optional). • Go to Configuration Properties -> CUDA C/C++ -> Device. Enter your compute version in "Code Generation". You may find out more about the compute version of you card at: https://developer.nvidia.com/cuda-gpus ## Adding Libraries 1. Right click the project and open "Properties". Here, you may want to select the active platform and configurations from the drop downs or select all configurations. 2. Go to Configuration Properties -> Linker. • Go to the General tab. In "Additional Library Directories" enter: • For CUDA : "$(AF_PATH)\lib64;$(CUDA_PATH)\lib\x64;" • For OpenCL: "$(AF_PATH)\lib64;"
• Go to the Input tab. In "Additional Dependencies" enter
• For CUDA : "cuda.lib;cudart.lib;libafcu.lib;"
• For OpenCL: "libafcl.lib;clBLAS.lib;clFFT.lib;OpenCL.lib;"
cuda_libs.png

## Preprocessor Definitions

1. This step is only for OpenCL. Go to Configuration Properties -> C/C++ -> Preprocessor. Add "AFCL;" to Preprocessor Definitions.

# On Linux

## Setting up Environment Variables

• ArrayFire requires that AF_PATH environment variable be set prior to compilation. The easiest way to set up these is using a script file like a bashrc.
• If using ArrayFire CUDA version, ArrayFire also requires CUDA_PATH environment variable to be set up. This should point to the location of the CUDA installation.
• It is also required to set up the LD_LIBRARY_PATH variable.

An example set up of these variable is as below. The actual directories may differ.

export AF_PATH=/opt/arrayfire-2.0
export CUDA_PATH=/usr/local/cuda
export LD_LIBRARY_PATH=$CUDA_PATH/lib/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$CUDA_PATH/lib64/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$AF_PATH/lib64/:$LD_LIBRARY_PATH

## Choosing the Compiler and Configuring for 64-bit

• If you are using ArrayFire with just C/C++ or using ArrayFire OpenCL, use the gcc/g++ compiler. If you are using ArrayFire with custom CUDA code, use the nvcc compiler. NVCC is required only for files using CUDA. GCC/G++ may be used for other files.
• Use the -m64 option to compile 64-bit if using ArrayFire 64-bit.

• If using CUDA, add the flags : "-I$AF_PATH/include -I$CUDA_PATH/include"
• If using OpenCL, add the flags: "-I$AF_PATH/include" ## Adding Libraries • Add the flags: "-L$AF_PATH/lib64"
• If using CUDA, add the flags : "-lafcu -L\$CUDA_PATH/lib64 -lcuda -lcudart"
• If using OpenCL, add the flags: "-lafcl"
• If using gcc, add the flags : "-lstdc++"

## Preprocessor Definitions

• This step is only for OpenCL. Add the "-DAFCL" flag to the compiler command.