Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/concepts/abi_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!--- specific language governing permissions and limitations -->
<!--- under the License. -->

# 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:
Expand Down
11 changes: 11 additions & 0 deletions docs/packaging/python_packaging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~

Expand Down
11 changes: 8 additions & 3 deletions examples/python_packaging/src/extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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 {
Expand Down