[TEST] Add gtest for ffi.StructuralEqual FFI global#597
Closed
tqchen wants to merge 3 commits into
Closed
Conversation
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.
Contributor
There was a problem hiding this comment.
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.
Match the style used elsewhere in the file. Gemini reviewer flagged the inconsistency on PR apache#597.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
StructuralEqual::Equalwas registered as theffi.StructuralEqualFFI globalin #453, making the cheap boolean path available to cross-language callers
(Python calls it via
tvm_ffi.structural_equal). However, no C++ testexercised 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.StructuralEqualinstead ofGetFirstStructuralMismatch(...) is None.Changes
tests/cpp/extra/test_structural_equal_hash.cc: addStructuralEqualHash.FFIGlobalStructuralEqualwhich retrievesffi.StructuralEqualandffi.GetFirstStructuralMismatchviaFunction::GetGlobalRequiredand verifies:GetFirstStructuralMismatchreturningnullopt for the same pair
#include <tvm/ffi/function.h>forFunction::GetGlobalRequired.Test plan
StructuralEqualHash.FFIGlobalStructuralEqualpasses