diff --git a/docs/concepts/abi_overview.md b/docs/concepts/abi_overview.md index 125de216..c8e0cd56 100644 --- a/docs/concepts/abi_overview.md +++ b/docs/concepts/abi_overview.md @@ -15,7 +15,7 @@ -# ABI Specification +# ABI Overview This section provides an overview of the ABI convention of TVM FFI. The ABI is designed around the following key principles: diff --git a/docs/packaging/python_packaging.rst b/docs/packaging/python_packaging.rst index 3166fdbf..c4856cfd 100644 --- a/docs/packaging/python_packaging.rst +++ b/docs/packaging/python_packaging.rst @@ -144,6 +144,17 @@ It registry handles type translation, error handling, and metadata. def add_one(x: int) -> int: ... +.. note:: + + Global functions can be retrieved via :py:func:`tvm_ffi.get_global_func` in Python, :cpp:func:`TVMFFIFunctionGetGlobal` in C, + or :cpp:func:`tvm::ffi::Function::GetGlobal` in C++. + + .. code-block:: python + + func = tvm_ffi.get_global_func("my_ffi_extension.add_one") + func(3) # -> 4 + + Class ~~~~~ diff --git a/examples/python_packaging/src/extension.cc b/examples/python_packaging/src/extension.cc index ee66a047..fc066250 100644 --- a/examples/python_packaging/src/extension.cc +++ b/examples/python_packaging/src/extension.cc @@ -39,6 +39,13 @@ TVM_FFI_DLL_EXPORT_TYPED_FUNC(add_two, AddTwo); // [global_function.begin] static int AddOne(int x) { return x + 1; } +TVM_FFI_STATIC_INIT_BLOCK() { + namespace refl = tvm::ffi::reflection; + refl::GlobalDef() // + .def("my_ffi_extension.add_one", AddOne); +} +// [global_function.end] + /*! * \brief Raise a runtime error to demonstrate error propagation. * @@ -56,11 +63,9 @@ static void RaiseError(const ffi::String& msg) { TVM_FFI_THROW(RuntimeError) << TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; - refl::GlobalDef() - .def("my_ffi_extension.add_one", AddOne) + refl::GlobalDef() // .def("my_ffi_extension.raise_error", RaiseError); } -// [global_function.end] // [object.begin] class IntPairObj : public ffi::Object {