1 Configuring ArrayFire Environment {#configuring_environment}
2 ===============================================================================
4 This page lists environment and runtime configurations that will help enhance
5 your experience with ArrayFire.
9 Environment Variables{#environment_variables}
10 ===============================================================================
12 The following are useful environment variable that can be used with ArrayFire.
15 -------------------------------------------------------------------------------
17 This is the path with ArrayFire gets installed, ie. the includes and libs are
18 present in this directory. You can use this variable to add include paths and
19 libraries to your projects.
21 AF_PRINT_ERRORS {#af_print_errors}
22 -------------------------------------------------------------------------------
24 When AF_PRINT_ERRORS is set to 1, the exceptions thrown are more verbose and
25 detailed. This helps in locating the exact failure.
27 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 AF_PRINT_ERRORS=1 ./myprogram
29 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31 AF_CUDA_DEFAULT_DEVICE {#af_cuda_default_device}
32 -------------------------------------------------------------------------------
34 Use this variable to set the default CUDA device. Valid values for this
35 variable are the device identifiers shown when af::info is run.
37 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38 AF_CUDA_DEFAULT_DEVICE=1 ./myprogram_cuda
39 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41 AF_ONEAPI_DEFAULT_DEVICE {#af_oneapi_default_device}
42 -------------------------------------------------------------------------------
44 Use this variable to set the default oneAPI device. Valid values for this
45 variable are the device identifiers shown when af::info is run.
47 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48 AF_ONEAPI_DEFAULT_DEVICE=1 ./myprogram_oneapi
49 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51 Note: af::setDevice call in the source code will take precedence over this
54 AF_OPENCL_DEFAULT_DEVICE {#af_opencl_default_device}
55 -------------------------------------------------------------------------------
57 Use this variable to set the default OpenCL device. Valid values for this
58 variable are the device identifiers shown when af::info is run.
60 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61 AF_OPENCL_DEFAULT_DEVICE=1 ./myprogram_opencl
62 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64 Note: af::setDevice call in the source code will take precedence over this
67 AF_OPENCL_DEFAULT_DEVICE_TYPE {#af_opencl_default_device_type}
68 -------------------------------------------------------------------------------
70 Use this variable to set the default OpenCL device type. Valid values for this
71 variable are: CPU, GPU, ACC (Accelerators).
73 When set, the first device of the specified type is chosen as default device.
75 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76 AF_OPENCL_DEFAULT_DEVICE_TYPE=CPU ./myprogram_opencl
77 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79 Note: `AF_OPENCL_DEFAULT_DEVICE` and af::setDevice takes precedence over this variable.
81 AF_OPENCL_DEVICE_TYPE {#af_opencl_device_type}
82 -------------------------------------------------------------------------------
84 Use this variable to only choose OpenCL devices of specified type. Valid values for this
87 - ALL: All OpenCL devices. (Default behavior).
88 - CPU: CPU devices only.
89 - GPU: GPU devices only.
90 - ACC: Accelerator devices only.
92 When set, the remaining OpenCL device types are ignored by the OpenCL backend.
94 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95 AF_OPENCL_DEVICE_TYPE=CPU ./myprogram_opencl
96 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98 AF_OPENCL_CPU_OFFLOAD {#af_opencl_cpu_offload}
99 -------------------------------------------------------------------------------
101 When ArrayFire runs on devices with unified memory with the host (ie.
102 `CL_DEVICE_HOST_UNIFIED_MENORY` is true for the device) then certain functions
103 are offloaded to run on the CPU using mapped buffers.
105 ArrayFire takes advantage of fast libraries such as MKL while spending no time
106 copying memory from device to host. The device memory is mapped to a host
107 pointer which can be used in the offloaded functions.
109 This functionality can be disabled by using the environment variable
110 `AF_OPENCL_CPU_OFFLOAD=0`.
112 The default bevaior of this has changed in version 3.4.
114 Prior to v3.4, CPU Offload functionality was used only when the user set
115 `AF_OPENCL_CPU_OFFLOAD=1` and disabled otherwise.
117 From v3.4 onwards, CPU Offload is enabled by default and is disabled only when
118 `AF_OPENCL_CPU_OFFLOAD=0` is set.
120 AF_OPENCL_SHOW_BUILD_INFO {#af_opencl_show_build_info}
121 -------------------------------------------------------------------------------
123 This variable is useful when debuggin OpenCL kernel compilation failures. When
124 this variable is set to 1, and an error occurs during a OpenCL kernel
125 compilation, then the log and kernel are printed to screen.
127 AF_DISABLE_GRAPHICS {#af_disable_graphics}
128 -------------------------------------------------------------------------------
130 Setting this variable to 1 will disable window creation when graphics
131 functions are being called. Disabling window creation will disable all other
132 graphics calls at runtime as well.
134 This is a useful enviornment variable when running code on servers and systems
135 without displays. When graphics calls are run on such machines, they will
136 print warning about window creation failing. To suppress those calls, set this
139 AF_SYNCHRONOUS_CALLS {#af_synchronous_calls}
140 -------------------------------------------------------------------------------
142 When this environment variable is set to 1, ArrayFire will execute all
143 functions synchronously.
145 AF_SHOW_LOAD_PATH {#af_show_load_path}
146 -------------------------------------------------------------------------------
148 When using the Unified backend, if this variable is set to 1, it will show the
149 path where the ArrayFire backend libraries are loaded from.
151 If the libraries are loaded from system paths, such as PATH or LD_LIBRARY_PATH
152 etc, then it will print "system path". If the libraries are loaded from other
153 paths, then those paths are shown in full.
155 AF_MEM_DEBUG {#af_mem_debug}
156 -------------------------------------------------------------------------------
158 When AF_MEM_DEBUG is set to 1 (or anything not equal to 0), the caching
159 mechanism in the memory manager is disabled. The device buffers are allocated
160 using native functions as needed and freed when going out of scope.
162 When the environment variable is not set, it is treated to be zero.
164 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165 AF_MEM_DEBUG=1 ./myprogram
166 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169 -------------------------------------------------------------------------------
171 If ArrayFire was built with logging support, this enviornment variable will
172 enable tracing of various modules within ArrayFire. This is a comma separated
173 list of modules to trace. If enabled, ArrayFire will print relevant information
174 to stdout. Currently the following modules are supported:
176 - all: All trace outputs
177 - jit: Logs kernel fetch & respective compile options and any errors.
178 - mem: Memory management allocation, free and garbage collection information
179 - platform: Device management information
180 - unified: Unified backend dynamic loading information
182 Tracing displays the information that could be useful when debugging or
183 optimizing your application. Here is how you would use this variable:
185 AF_TRACE=mem,unified ./myprogram
187 This will print information about memory operations such as allocations,
188 deallocations, and garbage collection.
190 All trace statements printed to the console have a suffix with the following
193 **[category][Seconds since Epoch][Thread Id][source file relative path] <Message>**
195 AF_MAX_BUFFERS {#af_max_buffers}
196 -------------------------------------------------------------------------
198 When AF_MAX_BUFFERS is set, this environment variable specifies the maximum
199 number of buffers allocated before garbage collection kicks in.
201 Please note that the total number of buffers that can exist simultaneously can
202 be higher than this number. This variable tells the garbage collector that it
203 should free any available buffers immediately if the treshold is reached.
205 When not set, the default value is 1000.
207 AF_OPENCL_MAX_JIT_LEN {#af_opencl_max_jit_len}
208 -------------------------------------------------------------------------------
210 When set, this environment variable specifies the maximum height of the OpenCL
211 JIT tree after which evaluation is forced.
213 The default value, as of v3.4, is 50 on OSX, 100 everywhere else. This value was
214 20 for older versions.
216 AF_CUDA_MAX_JIT_LEN {#af_cuda_max_jit_len}
217 -------------------------------------------------------------------------------
219 When set, this environment variable specifies the maximum height of the CUDA JIT
220 tree after which evaluation is forced.
222 The default value, as of v3.4, 100. This value was 20 for older versions.
224 AF_CPU_MAX_JIT_LEN {#af_cpu_max_jit_len}
225 -------------------------------------------------------------------------------
227 When set, this environment variable specifies the maximum length of the CPU JIT
228 tree after which evaluation is forced.
230 The default value, as of v3.4, 100. This value was 20 for older versions.
232 AF_BUILD_LIB_CUSTOM_PATH {#af_build_lib_custom_path}
233 -------------------------------------------------------------------------------
235 When set, this environment variable specifies a custom path along which the
236 symbol manager will search for dynamic (shared library) backends to load. This
237 is useful for specialized build configurations that use the unified backend and
238 build shared libraries separately.
240 By default, no additional path will be searched for an empty value.
243 AF_JIT_KERNEL_TRACE {#af_jit_kernel_trace}
244 -------------------------------------------------------------------------------
246 When set, this environment variable has to be set to one of the following
249 - stdout : generated kernels will be printed to standard output
250 - stderr : generated kernels will be printed to standard error stream
251 - absolute path to a folder on the disk where generated kernels will be stored
253 CUDA backend kernels are stored in files with cu file extension.
255 OpenCL backend kernels are stored in files with cl file extension.
257 AF_JIT_KERNEL_CACHE_DIRECTORY {#af_jit_kernel_cache_directory}
258 -------------------------------------------------------------------------------
260 This variable sets the path to the ArrayFire cache on the filesystem. If set
261 ArrayFire will write the kernels that are compiled at runtime to this directory.
262 If the path is not writeable, the default path is used.
264 This path is different from AF_JIT_KERNEL_TRACE which stores strings. These
265 kernels will store binaries and the content will be dependent on the
266 backend and platforms used.
268 The default path is determined in the following order:
273 1. ArrayFire application Temp folder(Usually
274 C:\\Users\\<user_name>\\AppData\\Local\\Temp\\ArrayFire)