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:

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