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
This can be done in two ways either by using CMake build tool or using Visual Studio directly.
Configure
button.build
directory if 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
, afcuda.lib
, afoneapi.lib
, or afopencl.lib
to Project Properties -> Linker -> Input -> Additional Dependencies. based on your preferred backend.NOMINMAX
, AF_<CPU/CUDA/ONEAPI/OPENCL>
, 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 the 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]) # The Unified backend lets you choose the backend at runtime. # To use the Unified backend, do the following: target_link_libraries(<my_executable> ArrayFire::af)
, where <my_executable>
is the name of the executable 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::afoneapi
for oneAPI backend.ArrayFire::afopencl
for OpenCL backend.Next, instruct CMake to create build instructions and compile them. 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.