You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "junrushao (via GitHub)" <gi...@apache.org> on 2026/02/08 08:02:06 UTC

[PR] doc: More Developer Manuals [tvm-ffi]

junrushao opened a new pull request, #437:
URL: https://github.com/apache/tvm-ffi/pull/437

   (no comment)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] doc: More Developer Manuals [tvm-ffi]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #437:
URL: https://github.com/apache/tvm-ffi/pull/437#issuecomment-3866481419

   ## Summary of Changes
   
   Hello @junrushao, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
   
   This pull request significantly overhauls and expands the project's developer documentation. The primary goal is to centralize and organize information, making it easier for contributors and users to find detailed guides on building, testing, contributing, and understanding core concepts. This involves moving verbose sections from top-level markdown files into dedicated reStructuredText documents, introducing new comprehensive guides for CI/CD and cross-language FFI export mechanisms, and enhancing cross-referencing throughout the documentation. Additionally, a minor code change improves the robustness of an optional PyTorch extension loading mechanism.
   
   ### Highlights
   
   * **Documentation Centralization**: Key developer manuals and guides, previously scattered or embedded, have been centralized into dedicated documentation pages. This includes detailed guides on installation, pre-commit hooks, Docker development, and stability/versioning, which are now referenced from `CONTRIBUTING.md`.
   * **New Developer Guides**: Two comprehensive new guides have been added: one for reproducing CI/CD workflows locally (`docs/dev/ci_cd.rst`) covering linters, tests, and wheel builds, and another for exporting functions and classes across C, C++, and Python (`docs/guides/export_func_cls.rst`).
   * **Improved Documentation Structure**: The `README.md` and `docs/README.md` files have been streamlined, replacing extensive inline content with high-level overviews and links to the new, detailed documentation pages. Existing documentation pages like `quickstart.rst` and `stable_c_abi.rst` have been updated with numerous `seealso` cross-references to related concepts and guides.
   * **Custom Module Documentation**: A new section on 'Custom Modules' has been added to `docs/concepts/func_module.rst`, explaining how to extend `tvm::ffi::ModuleObj` for platform-specific driver APIs, with corresponding updates in `compiler_integration.md`.
   * **Robustness for `torch_c_dlpack_ext` Loading**: The `addons/torch_c_dlpack_ext/build_backend.py` file has been updated to handle `AttributeError` during `torch_c_dlpack_ext` loading, improving robustness when ABI differences exist between `torch_c_dlpack_ext` and `torch`.
   
   🧠 **New Feature in Public Preview:** You can now enable **Memory** to help **Gemini Code Assist** learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. **Click [here](https://codeassist.google/code-review/login) to enable Memory in your admin console.**
   
   <details>
   <summary><b>Changelog</b></summary>
   
   * **CONTRIBUTING.md**
       * Removed detailed sections on installation, pre-commit hooks, Docker development, stability, and versioning.
       * Replaced removed content with a general link to the full developer manual and a list of key pages within it.
   * **README.md**
       * Removed specific documentation links under 'Visit our documentation'.
       * Added a new, comprehensive 'Documentation' section with categorized links to 'Get Started', 'Guides', 'Concepts', 'Packaging', and 'Developer Manual' pages.
   * **addons/torch_c_dlpack_ext/build_backend.py**
       * Imported `contextlib.suppress`.
       * Wrapped the `import torch` and subsequent checks in a `try...except AttributeError` block to handle cases where `ctypes.CDLL` might raise an `AttributeError` due to ABI differences, allowing fallback to JIT.
   * **docs/README.md**
       * Removed detailed sections on build workflows (interactive, one-off, C++/Rust docs) and cleanup instructions.
       * Replaced removed content with a single link to the `build_doc.html` guide.
   * **docs/_stubs/cpp_index.rst**
       * Added the `:orphan:` directive to prevent the C++ API index from appearing in the table of contents.
   * **docs/concepts/func_module.rst**
       * Added a new section `Custom Modules` explaining how to subclass `tvm::ffi::ModuleObj` for platform-specific driver APIs.
   * **docs/conf.py**
       * Added a new function `_mark_exhale_root_orphan` to prepend `:orphan:` to the Exhale-generated C++ API index, ensuring it doesn't appear in the sidebar.
       * Connected `_mark_exhale_root_orphan` to the `source-read` Sphinx event.
   * **docs/dev/build_from_source.md**
       * Removed this file. Its content has likely been moved or refactored into `docs/dev/build_from_source.rst`.
   * **docs/dev/ci_cd.rst**
       * Added a new documentation file providing a comprehensive guide on reproducing CI checks and tests locally, including linters, C++/Python/Rust tests, and building Python wheels.
   * **docs/dev/release_process.rst**
       * Added a `seealso` link to the new `ci_cd` documentation for details on how wheels are built with cibuildwheel.
   * **docs/get_started/quickstart.rst**
       * Added multiple `seealso` links to new or updated documentation pages, including `export_func_cls`, `kernel_library_guide`, `tensor` concepts, `cpp_tooling`, and `func_module`.
   * **docs/get_started/stable_c_abi.rst**
       * Added multiple `seealso` links to new or updated documentation pages, including `any` type, `func_module` concepts, `tensor`, `object_and_class`, `abi_overview`, `exception_handling`, `export_func_cls`, and `compiler_integration`.
       * Updated a reference from `cpp_lang_guide` to `object_and_class`.
       * Expanded the 'What's Next' section with new points on exporting higher-level APIs, shipping kernels, and packaging/distribution.
   * **docs/guides/compiler_integration.md**
       * Removed the detailed 'Advanced: Custom Modules' section.
       * Replaced the removed section with a `seealso` link to the new 'Custom Modules' section in `docs/concepts/func_module.rst`.
   * **docs/guides/export_func_cls.rst**
       * Added a new documentation file providing a comprehensive guide on exporting functions and classes across C, C++, and Python, detailing C Symbols, Global Functions, and Classes.
   * **docs/index.rst**
       * Updated the table of contents to include `guides/export_func_cls.rst`.
       * Updated the 'Developer Manual' section to include `dev/build_from_source.rst`, `dev/build_doc.rst`, and `dev/ci_cd.rst`.
   * **docs/packaging/cpp_tooling.rst**
       * Added a `seealso` link to `../dev/build_from_source`.
   * **docs/packaging/python_packaging.rst**
       * Added a `_sec-load-the-library` anchor for internal linking.
       * Removed the detailed 'Export C++ to Python' section, including sub-sections on TVM-FFI ABI, Global Function, and Class export.
       * Replaced the removed content with a `seealso` link to the new `../guides/export_func_cls` guide.
       * Added a `seealso` link to `../dev/ci_cd` for reproducing wheel builds locally.
   * **docs/reference/cpp/index.rst**
       * Simplified the 'Full API Index' link, removing conditional Sphinx directives.
   * **python/tvm_ffi/_optional_torch_c_dlpack.py**
       * Added `except AttributeError` to the `try...except ImportError` block when attempting to load `torch_c_dlpack_ext`. This handles cases where `ctypes.CDLL` might raise an `AttributeError` due to ABI differences, allowing the system to fall back to JIT compilation.
   </details>
   
   
   
   <details>
   <summary><b>Activity</b></summary>
   
   * The pull request description is empty, providing no explicit intent from the author.
   * There are no comments or reviews on this pull request yet.
   </details>
   
   
   <details>
   <summary><b>Using Gemini Code Assist</b></summary>
   <br>
   
   The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.
   
   <b>Invoking Gemini</b>
   
   You can request assistance from Gemini at any point by creating a comment using either `/gemini <command>` or `@gemini-code-assist <command>`. Below is a summary of the supported commands on the current page.
   
   Feature | Command | Description
   --- | --- | ---
   Code Review | `/gemini review` | Performs a code review for the current pull request in its current state.
   Pull Request Summary | `/gemini summary` | Provides a summary of the current pull request in its current state.
   Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments.
   Help | `/gemini help` | Displays a list of available commands.
   
   <b>Customization</b>
   
   To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
   
   <b>Limitations & Feedback</b>
   
   Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up [here](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
   
   <b>You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the [Gemini Code Assist IDE Extension](https://cloud.google.com/products/gemini/code-assist).</b>
   </details>
   
   
   
   
   [^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] doc: More Developer Manuals [tvm-ffi]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #437:
URL: https://github.com/apache/tvm-ffi/pull/437#discussion_r2779514068


##########
docs/dev/ci_cd.rst:
##########
@@ -0,0 +1,202 @@
+..  Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+..    http://www.apache.org/licenses/LICENSE-2.0
+
+..  Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+Reproduce CI/CD
+===============
+
+This guide explains how to reproduce CI checks and tests locally,
+and how wheel builds and releases work.
+All CI/CD workflows are defined under `.github/workflows/ <https://github.com/apache/tvm-ffi/tree/main/.github/workflows>`__.
+For building the project from source, see :doc:`source_build`.
+
+Linters
+-------
+
+Pre-commit
+~~~~~~~~~~
+
+The project uses `pre-commit <https://pre-commit.com/>`__ to run linters and
+formatters. All hooks are defined in `.pre-commit-config.yaml <https://github.com/apache/tvm-ffi/blob/main/.pre-commit-config.yaml>`__. Install and
+register the git hooks so they run automatically before each commit:
+
+.. code-block:: bash
+
+   uv tool install pre-commit
+   pre-commit install
+
+You can also run hooks manually:
+
+.. code-block:: bash
+
+   # Run all hooks on every file
+   pre-commit run --all-files
+
+   # Run only on staged files
+   pre-commit run
+
+   # Run a single hook in isolation
+   pre-commit run ruff-check --all-files
+   pre-commit run clang-format --all-files
+
+The main linters per language are:
+
+- **Python** -- ``ruff`` (lint + format), ``ty`` (type checking)
+- **C/C++** -- ``clang-format`` (format), ``clang-tidy`` (lint, see below)
+- **Cython** -- ``cython-lint``
+- **CMake** -- ``cmake-format``, ``cmake-lint``
+- **Shell** -- ``shfmt``, ``shellcheck``
+
+If you run into issues with pre-commit:
+
+- **Version problems** -- ensure you have pre-commit 2.18.0 or later
+  (``pre-commit --version``).
+- **Stale cache** -- run ``pre-commit clean`` to clear the hook cache.
+- **Auto-fixed files** -- most formatting hooks fix issues in place. Review the
+  changes, stage them with ``git add -u``, and commit again.
+
+clang-tidy
+~~~~~~~~~~
+
+``clang-tidy`` is run as a separate CI job (not as a pre-commit hook) and only
+checks C++ files that have changed. To reproduce it locally:
+
+.. code-block:: bash
+
+   # Run clang-tidy on specific files
+   uv run --no-project --with "clang-tidy==21.1.1" \
+     python tests/lint/clang_tidy_precommit.py \
+       --build-dir=build-pre-commit \
+       --jobs=$(nproc) \
+       include/tvm/ffi/c_api.h src/some_file.cc
+
+   # Or run on all C++ sources
+   uv run --no-project --with "clang-tidy==21.1.1" \
+     python tests/lint/clang_tidy_precommit.py \
+       --build-dir=build-pre-commit \
+       --jobs=$(nproc)

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The command to run `clang-tidy` on all C++ sources appears to be incomplete. The `tests/lint/clang_tidy_precommit.py` script requires file or directory paths to be provided as arguments. Without them, it will not lint any files. To lint all C++ sources as the comment suggests, you should pass the `include` and `src` directories.
   
   ```suggestion
      # Or run on all C++ sources
      uv run --no-project --with "clang-tidy==21.1.1" \
        python tests/lint/clang_tidy_precommit.py \
          --build-dir=build-pre-commit \
          --jobs=$(nproc) \
          include src
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] doc: More Developer Manuals [tvm-ffi]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #437:
URL: https://github.com/apache/tvm-ffi/pull/437#discussion_r2778865367


##########
docs/guides/export_func_cls.rst:
##########
@@ -0,0 +1,308 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+..
+..   http://www.apache.org/licenses/LICENSE-2.0
+..
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+Export Functions and Classes
+============================
+
+TVM-FFI provides three mechanisms to make functions and classes available across
+C, C++, and Python. Each targets a different use case:
+
+.. list-table::
+   :header-rows: 1
+   :widths: 18 42 40
+
+   * - Mechanism
+     - When to use
+     - How it works
+   * - :ref:`C Symbols <export-c-symbols>`
+     - Kernel libraries, compiler codegen
+     - Export ``__tvm_ffi_<name>`` in a shared library; load via
+       :py:func:`tvm_ffi.load_module`
+   * - :ref:`Global Functions <export-global-functions>`
+     - Application-level APIs, cross-language callbacks
+     - Register by string name; retrieve from any language
+   * - :ref:`Classes <export-classes>`
+     - Structured data with fields and methods
+     - Define a C++ :cpp:class:`~tvm::ffi::Object` subclass; use from Python
+       as a dataclass
+
+Include the umbrella header to access all C++ APIs used in this guide:
+
+.. code-block:: cpp
+
+   #include <tvm/ffi/tvm_ffi.h>
+
+Metadata (type signatures, field names, docstrings) is captured automatically
+and can be turned into Python type hints via stub generation.
+
+.. seealso::
+
+   - All C++ examples in this guide are under
+     `examples/python_packaging/ <https://github.com/apache/tvm-ffi/tree/main/examples/python_packaging>`_;
+     ANSI C examples are under
+     `examples/stable_c_abi/ <https://github.com/apache/tvm-ffi/tree/main/examples/stable_c_abi>`_.
+   - :doc:`../concepts/func_module`: Calling convention, module system, and
+     global registry concepts.
+   - :doc:`../get_started/stable_c_abi`: Low-level C ABI walkthrough.
+   - :doc:`../packaging/python_packaging`: Packaging extensions as Python wheels.
+   - :doc:`../packaging/stubgen`: Generating Python type stubs from C++ metadata.
+
+
+.. _export-c-symbols:
+
+C Symbols
+---------
+
+C symbols are the most direct export mechanism. A function is compiled into a
+shared library with a ``__tvm_ffi_<name>`` symbol, then loaded dynamically at
+runtime. This is the recommended approach for kernel libraries and compiler
+codegen because it keeps the language boundary thin.
+
+.. tip::
+
+   For exporting and calling C symbols from pure ANSI C code, see
+   :doc:`../get_started/stable_c_abi`.
+
+
+Export and Look up in C++
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+**Export.** Use :c:macro:`TVM_FFI_DLL_EXPORT_TYPED_FUNC` to export a C++ function
+as a C symbol that follows the
+:ref:`TVM-FFI calling convention <sec:function-calling-convention>`:
+
+.. literalinclude:: ../../examples/python_packaging/src/extension.cc
+   :language: cpp
+   :start-after: [tvm_ffi_abi.begin]
+   :end-before: [tvm_ffi_abi.end]
+
+This creates a symbol ``__tvm_ffi_add_two`` in the shared library. The macro
+handles argument unmarshalling and error propagation automatically.
+
+**Look up.** Use :cpp:func:`tvm::ffi::Module::LoadFromFile` to load a shared
+library and retrieve functions by name:
+
+.. code-block:: cpp
+
+   namespace ffi = tvm::ffi;
+
+   ffi::Module mod = ffi::Module::LoadFromFile("path/to/library.so");
+   ffi::Function func = mod->GetFunction("add_two").value();
+   int result = func(40).cast<int>();  // -> 42
+
+
+Load from Python
+~~~~~~~~~~~~~~~~
+
+Use :py:func:`tvm_ffi.load_module` to load the shared library and call its
+functions by name:
+
+.. code-block:: python
+
+   import tvm_ffi
+
+   mod = tvm_ffi.load_module("path/to/library.so")
+   result = mod.add_two(40)  # -> 42
+
+.. seealso::
+
+   For DSO loading at Python package level, see :ref:`sec-load-the-library` in
+   the Python packaging guide.
+
+.. _export-embedded-binary-data:
+
+Embedded Binary Data
+~~~~~~~~~~~~~~~~~~~~
+
+Shared libraries can embed a binary symbol ``__tvm_ffi__library_bin`` alongside
+function symbols to support **composite modules** — modules that import custom
+sub-modules (e.g., a PTX module loaded via ``cuModuleLoad``). The binary layout
+is:
+
+.. code-block:: text
+
+   <nbytes: u64> <import_tree> <key0: str> [val0: bytes] <key1: str> [val1: bytes] ...
+
+- ``nbytes``: total byte count following this header.
+- ``import_tree``: a CSR sparse array
+  (``<indptr: vec<u64>> <child_indices: vec<u64>>``) encoding the parent-child
+  relationships among module nodes.
+- Each ``key`` is a module kind string, or the special value ``_lib`` for the
+  host dynamic library itself. For non-\ ``_lib`` entries, ``val`` contains the
+  serialized bytes of the custom sub-module.

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The phrasing "For non-\\_lib entries" is a bit awkward due to the escaped space and might be confusing. Rephrasing it would improve clarity.
   
   ```suggestion
   - Each ``key`` is a module kind string, or the special value ``_lib`` for the
     host dynamic library itself. For entries other than ``_lib``, ``val`` contains the
     serialized bytes of the custom sub-module.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] doc: More Developer Manuals [tvm-ffi]

Posted by "junrushao (via GitHub)" <gi...@apache.org>.
junrushao commented on PR #437:
URL: https://github.com/apache/tvm-ffi/pull/437#issuecomment-3867550601

   /gemini review


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] doc: More Developer Manuals [tvm-ffi]

Posted by "junrushao (via GitHub)" <gi...@apache.org>.
junrushao merged PR #437:
URL: https://github.com/apache/tvm-ffi/pull/437


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org