Skip to content

[TEST] Add gtest for ffi.StructuralEqual FFI global#597

Closed
tqchen wants to merge 3 commits into
apache:mainfrom
tqchen:tvm-ffi-expose-structuralequal
Closed

[TEST] Add gtest for ffi.StructuralEqual FFI global#597
tqchen wants to merge 3 commits into
apache:mainfrom
tqchen:tvm-ffi-expose-structuralequal

Conversation

@tqchen

@tqchen tqchen commented May 26, 2026

Copy link
Copy Markdown
Member

Background

StructuralEqual::Equal was registered as the ffi.StructuralEqual FFI global
in #453, making the cheap boolean path available to cross-language callers
(Python calls it via tvm_ffi.structural_equal). However, no C++ test
exercised that global through the FFI registry — existing tests call either
the C++ functor (StructuralEqual()(lhs, rhs)) or the static method
(StructuralEqual::Equal(...)) directly, bypassing the registry dispatch path.

Motivated by the Gemini review on apache/tvm#19613, which highlighted the
efficiency win of calling ffi.StructuralEqual instead of
GetFirstStructuralMismatch(...) is None.

Changes

  • tests/cpp/extra/test_structural_equal_hash.cc: add
    StructuralEqualHash.FFIGlobalStructuralEqual which retrieves
    ffi.StructuralEqual and ffi.GetFirstStructuralMismatch via
    Function::GetGlobalRequired and verifies:
    • equal arrays → true
    • unequal arrays → false
    • boolean result is consistent with GetFirstStructuralMismatch returning
      nullopt for the same pair
  • Add #include <tvm/ffi/function.h> for Function::GetGlobalRequired.

Test plan

  • StructuralEqualHash.FFIGlobalStructuralEqual passes
  • Full C++ test suite: 344/344 pass (2 disabled)

tqchen added 2 commits March 1, 2026 07:51
This PR fixes the config loading in windows case, sometimes
in wheel settings the testcase may still need to load core.pyd,
so we by default load the library in config mode when it is windows.
The boolean equality path StructuralEqual::Equal was registered as the
ffi.StructuralEqual global in PR apache#453, but no test exercised that global
via the FFI registry. Add FFIGlobalStructuralEqual to
test_structural_equal_hash.cc which calls Function::GetGlobalRequired to
obtain the registered global and verifies:
- equal arrays return true
- unequal arrays return false
- the boolean result is consistent with GetFirstStructuralMismatch
  returning nullopt for the same pair

Also adds #include <tvm/ffi/function.h> needed for Function::GetGlobalRequired.

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

Copy link
Copy Markdown
Contributor

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 ensures that the library is loaded on Windows even in config CLI mode to set the DLL search path correctly, and adds a C++ unit test verifying the behavior of the FFI globals ffi.StructuralEqual and ffi.GetFirstStructuralMismatch. A review comment suggests explicitly calling .has_value() on the returned Optional wrappers in the test for consistency and correct boolean evaluation.

Comment thread tests/cpp/extra/test_structural_equal_hash.cc Outdated
Match the style used elsewhere in the file. Gemini reviewer flagged
the inconsistency on PR apache#597.
@tqchen tqchen closed this May 26, 2026
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.

1 participant