Introducing and modernize FFI system

Note that in the new ffi, we have better backtrace support through lib backtrace, so right now if an exception is thrown from cxx end, the trace will be incorporated into the python trace and also clickable if we are in editors like vscode

from tvm import ffi as tvm_ffi

def error_trace():
    # call a test function that raises error from c++ end
    cxx_test_raise_error = tvm_ffi.get_global_func("testing.test_raise_error")
    cxx_test_raise_error("ValueError", "error XYZ")

error_trace()

Will return something like

Traceback (most recent call last):
  File "/tvm/apps/debug.py", line 25, in <module>
    error_trace()
  File "/tvm/apps/debug.py", line 23, in error_trace
    cxx_test_raise_error("ValueError", "error XYZ")
  File "tvm/ffi/cython/function.pxi", line 228, in tvm.ffi.core.Function.__call__
    raise move_from_last_error().py_error()
  File "/tvm/ffi/src/ffi/testing.cc", line 30, in tvm::ffi::TestRaiseError(tvm::ffi::String, tvm::ffi::String)
    throw ffi::Error(kind, msg, TVM_FFI_TRACEBACK_HERE);
ValueError: error XYZ
1 Like