Skip to content

Commit 89be2d3

Browse files
authored
doc: Final tweaks on Python Packaging (#358)
1 parent a1cb746 commit 89be2d3

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

docs/concepts/abi_overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<!--- specific language governing permissions and limitations -->
1616
<!--- under the License. -->
1717

18-
# ABI Specification
18+
# ABI Overview
1919

2020
This section provides an overview of the ABI convention of TVM FFI. The ABI
2121
is designed around the following key principles:

docs/packaging/python_packaging.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,17 @@ It registry handles type translation, error handling, and metadata.
144144
def add_one(x: int) -> int: ...
145145
146146
147+
.. note::
148+
149+
Global functions can be retrieved via :py:func:`tvm_ffi.get_global_func` in Python, :cpp:func:`TVMFFIFunctionGetGlobal` in C,
150+
or :cpp:func:`tvm::ffi::Function::GetGlobal` in C++.
151+
152+
.. code-block:: python
153+
154+
func = tvm_ffi.get_global_func("my_ffi_extension.add_one")
155+
func(3) # -> 4
156+
157+
147158
Class
148159
~~~~~
149160

examples/python_packaging/src/extension.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ TVM_FFI_DLL_EXPORT_TYPED_FUNC(add_two, AddTwo);
3939
// [global_function.begin]
4040
static int AddOne(int x) { return x + 1; }
4141

42+
TVM_FFI_STATIC_INIT_BLOCK() {
43+
namespace refl = tvm::ffi::reflection;
44+
refl::GlobalDef() //
45+
.def("my_ffi_extension.add_one", AddOne);
46+
}
47+
// [global_function.end]
48+
4249
/*!
4350
* \brief Raise a runtime error to demonstrate error propagation.
4451
*
@@ -56,11 +63,9 @@ static void RaiseError(const ffi::String& msg) { TVM_FFI_THROW(RuntimeError) <<
5663

5764
TVM_FFI_STATIC_INIT_BLOCK() {
5865
namespace refl = tvm::ffi::reflection;
59-
refl::GlobalDef()
60-
.def("my_ffi_extension.add_one", AddOne)
66+
refl::GlobalDef() //
6167
.def("my_ffi_extension.raise_error", RaiseError);
6268
}
63-
// [global_function.end]
6469

6570
// [object.begin]
6671
class IntPairObj : public ffi::Object {

0 commit comments

Comments
 (0)