Debugging ArrayFire Issues
Using Exceptions
When an error is encountered (incorrect arguments or some calculation error), ArrayFire will raise an exception. This exception contains a stacktrace on which arrayfire function is raising the error and what is the cause for it. For example, this code will raise an print an exception:
import arrayfire as af
x = af.randu(10)
y = af.randu(5)
try:
# Arrays have non-broadcastable shapes
res = x + y
catch Exception as e:
print(e)
This may produce the following output
In function arithOpBroadcast
In file src\api\c\binary.cpp:81
Invalid dimension for argument 1
Expected: ((lshape[d] == rshape[d]) || (lshape[d] == 1 && rshape[d] > 1) || (lshape[d] > 1 && rshape[d] == 1))
0# af::exception::~exception in afcuda
1# af_bilateral in afcuda
2# af_bilateral in afcuda
3# af_add in afcuda
4# ffi_prep_go_closure in libffi_8
5# ffi_call_go in libffi_8
6# ffi_call in libffi_8
7# 0x00007FFCD2833C05 in _ctypes
8# 0x00007FFCD2832ACA in _ctypes
9# 0x00007FFCD28326C8 in _ctypes
Using ArrayFire Debug/Utility Functions
For issues with specific devices or memory limitations, ArrayFire provides functions to inform the user the current device and allocations.
For checking device information we have the functions:
get_device() and get_device_count() gets the devices on the current backend
get_dbl_support(device_id) and get_half_support(device_id) provides information for f64 and f16 type support
device_info(device_id), info(), info_string() provides backend, vendor, and version of device
device_gc() forces garbage collection of unused arrays on current device
get_mem_step_size() and set_mem_step_size(mem_size) allows getting and setting the size of allocation groups
print_mem_info(prepend_message, device_id): Print table of memory used by ArrayFire on the selected device
Using ArrayFire’s environment variables
For internal information related to the kernels generated by the JIT, allocation triggers, and extra information, ArrayFire provides environment variables that enable extra tracing information that will be printed into stdout.
Please check the section of Debugging Environment Variables in Configuring ArrayFire Environment for a list of all the debug variables and their usage.
Further Reading
For outstanding issues related to ArrayFire, you may visit the Github Issues in ArrayFire Python and ArrayFire C/C++ Libraries