Skip to content

Conversation

@tqchen
Copy link
Member

@tqchen tqchen commented Oct 13, 2025

This PR introduces a new C API TVMFFIErrorSetRaisedFromCStrParts.

Background: when DSL compilers report errors, sometimes there are common parts that appears multiple times, such as function signature.

For example, the following are possible error messages from a DSL.

  • Argument 1 mismatch in matmul(x: Tensor, y: Tensor), dtype mismatch
  • Argument 2 mismatch in matmul(x: Tensor, y: Tensor), shape[0] mismatch

While we can store each message as const string and pass them to TVMFFIErrorSetRaisedFromCStr. There are quite a bit of duplication here.

This API allows us to store the error messages in parts, so parts like "mismatch in matmul(x: Tensor, y: Tensor)," get reused across multiple error messages. Because DSLs usually have minimal runtime, having a minimal helper C API would simplify the possible overhead of compiler construction side.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @tqchen, I'm Gemini Code Assist1! 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 enhances the C API for error handling by introducing TVMFFIErrorSetRaisedFromCStrParts. This new function allows developers, especially those building DSL compilers, to construct error messages by concatenating multiple string parts. The primary benefit is to reduce memory overhead and duplication when common elements, such as function signatures, appear in various error reports. This change provides a more flexible and efficient mechanism for error reporting within the FFI framework.

Highlights

  • New C API for Error Reporting: Introduced TVMFFIErrorSetRaisedFromCStrParts, a new C API designed to construct error messages from multiple string parts. This allows for efficient reuse of common message segments.
  • Reduced Duplication in Error Messages: The new API addresses the problem of redundant error message components, particularly in DSL compilers, by enabling the concatenation of reusable string parts (e.g., function signatures).
  • Documentation and Example Updates: Updated documentation in abi_overview.md and compiler_integration.md to reflect the new API. An example C file's comments were also updated to mention the new function.
  • Version Bump: The project version has been updated from 0.1.0b16 to 0.1.0b17 in pyproject.toml and python/tvm_ffi/__init__.py.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

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.

Customization

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.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 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.

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.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces TVMFFIErrorSetRaisedFromCStrParts, a new C API for building error messages from multiple string parts. This is a useful feature for DSL compilers to reduce redundancy in error reporting. The changes are well-contained, including the API definition, implementation, tests, and documentation updates. I have a few suggestions to improve performance and fix minor documentation issues.

This PR introduces a new C API TVMFFIErrorSetRaisedFromCStrParts.

Background: when DSL compilers report errors, sometimes there are common
parts that appears multiple times, such as function signature.

For example, the following are possible error messages from a DSL.

- Argument apache#1 mismatch in `matmul(x: Tensor, y: Tensor)`, dtype mismatch
- Argument apache#2 mismatch in `matmul(x: Tensor, y: Tensor)`, shape[0] mismatch

While we can store each message as const string and pass them
to `TVMFFIErrorSetRaisedFromCStr`. There are quite a bit of duplication here.

This API allows us to store the error messages in parts, so parts
like "mismatch in `matmul(x: Tensor, y: Tensor)`,"  get reused across
multiple error messages. Because DSLs usually have minimal runtime, having
a minimal helper C API would simplify the possible overhead of compiler
construction side.
@tqchen tqchen merged commit 550e92f into apache:main Oct 13, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants