If you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the installation instructions.
The ArrayFire Windows installer creates the following:
C:\Program Files\ArrayFire\v3
The installer will prompt the user for following three options.
If you chose not to modify PATH during installation please make sure to do so manually so that all applications using ArrayFire libraries will be able to find the required DLLs.
This can be done in two ways either by using CMake build tool or using Visual Studio directly.
Configure
button towards the lower left bottom.build
directory if it's not already present. Click yes to create the build directory.F5
.examples/helloworld/helloworld.cpp
to this project."$(AF_PATH)/include;"
to Project Properties -> C/C++ -> General -> Additional Include Directories."$(AF_PATH)/lib;"
to Project Properties -> Linker -> General -> Additional Library Directories.afcpu.lib
or afcuda.lib
or afopencl.lib
to Project Properties -> Linker -> Input -> Additional Dependencies. based on your preferred backend.NOMINMAX
, AF_<CPU/CUDA/OPENCL>
and/or AF_<DEBUG/RELEASE>
in your projects. This can be added to Project Properties -> C/C++ -> General -> Preprocessor-> Preprocessory definitions.This is divided into three parts:
Note: If you plan on using Native CUDA code in the project, use the steps under Part B.
Adding a single backend to an existing project is quite simple.
"$(AF_PATH)/include;"
to Project Properties -> C/C++ -> General -> Additional Include Directories."$(AF_PATH)/lib;"
to Project Properties -> Linker -> General -> Additional Library Directories.afcpu.lib
, afcuda.lib
, afopencl.lib
, or af.lib
to Project Properties -> Linker -> Input -> Additional Dependencies. based on your preferred backend.Lastly, if your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:
"$(AF_PATH)/include;"
to Project Properties -> CUDA C/C++ -> General -> Additional Include Directories."$(AF_PATH)/lib;"
to Project Properties -> Linker -> General -> Additional Library Directories.afcpu.lib
, afcuda.lib
, afopencl.lib
, or af.lib
to Project Properties -> Linker -> Input -> Additional Dependencies. based on your preferred backend.If you wish to create a project that allows you to use all the ArrayFire backends with ease, you should use af.lib
in step 3 from Part A.
You can alternately download the template project from ArrayFire Template Projects
ArrayFire ships with a series of CMake scripts to make finding and using our library easy.
First create a file called CMakeLists.txt
in your project directory:
cd your-project-directory touch CMakeLists.txt
and populate it with the following code:
find_package(ArrayFire) add_executable(<my_executable> [list your source files here]) # To use Unified backend, do the following. # Unified backend lets you choose the backend at runtime target_link_libraries(<my_executable> ArrayFire::af)
where <my_executable>
is the name of the executable you wish to create. See the CMake documentation for more information on how to use CMake. To link with a specific backend directly, replace the ArrayFire::af
with the following for their respective backends.
ArrayFire::afcpu
for CPU backend.ArrayFire::afcuda
for CUDA backend.ArrayFire::afopencl
for OpenCL backend.Next we need to instruct CMake to create build instructions and then compile. We suggest using CMake's out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.
Open Project
in CMake-GUI to open the solution and compile the ALL_BUILD project.