common: attr: include binary select src2 in post-op identity - #5970
Open
MaxFreedomPollard wants to merge 1 commit into
Open
MaxFreedomPollard wants to merge 1 commit into
MaxFreedomPollard wants to merge 1 commit into
Conversation
post_ops_t::entry_t::operator== and get_attr_hash only looked at the algorithm and user_src1_desc of a binary post-op, and serialize() wrote only those two. For binary_select the third operand is a real input, so two post-ops that differ only in user_src2_desc were treated as the same attribute. The primitive cache key compares and hashes attributes, so creating a primitive with a binary_select post-op and then another one that differs only in the third operand returned the first cached primitive, built for the wrong src2 memory descriptor. Compare, hash and serialize user_src2_desc when the entry is a binary with a ternary operator. Non-ternary binary post-ops keep ignoring user_src2_desc, as dnnl_post_ops_append_binary_v2 documents.
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.
Description
The identity of a binary post-op ignores the third operand, so the primitive cache hands back a primitive that was built for a different
src2memory descriptor.post_ops_t::entry_t::operator==(src/common/primitive_attr.hpp:430) compares onlybinary.algandbinary.user_src1_desc, andget_attr_hash(src/common/primitive_hashing.cpp:312) hashes only those same two fields.serializefor post-ops (src/common/primitive_serialization.cpp:197) writes only those two as well. Forbinary_selectthe third operand is a real input to the post-op, not a spare field, so two attributes that differ only inuser_src2_deschash to the same value and compare equal. The primitive cache key compares and hashes attributes with those functions, so the second create returns the primitive built for the firstsrc2descriptor.get_desc_hash(const binary_desc_t &)at src/common/primitive_hashing.cpp:393 already special-casesbinary_selectand hashessrc_desc[2]; the post-op path was never given the same treatment.The fix compares, hashes and serializes
user_src2_descwhenentry.is_binary_with_ternary_op()is true. Non-ternary binary post-ops keep ignoringuser_src2_desc, which is whatdnnl_post_ops_append_binary_v2documents: "If the specified algorithm is not one that requires a ternary input, src2_desc will be ignored."#5520 carries the same three hunks (its commits 17a324a and 0ff511a) inside the avx512_core select-fusion work, but without a test for the identity itself. This PR isolates the cache-key fix and adds that regression test so it can land on its own; #5520 then rebases onto it with no conflict.
Reproducing
Create an
eltwise_forwardwith abinary_selectpost-op whose third operand iss8, then create the same primitive with au8third operand:dnnl_test_get_primitive_cache_sizereports 1 after both creates on main, sop2is the primitive built for thes8operand. With this change it reports 2.Tests
comparison_operators_t.TestBinarySelectPostOpin tests/gtests/internals/test_comparison_operators.cpp is the regression test. It fails on unmodified main withcompare(...) Which is: trueand passes with the change.Everything below was run on macOS 15 arm64 with Apple clang 17, configured as
cmake -DCMAKE_BUILD_TYPE=Release -DDNNL_AARCH64_USE_ACL=OFF -DONEDNN_BUILD_GRAPH=OFF -DDNNL_BUILD_EXAMPLES=OFF -DDNNL_CPU_RUNTIME=SEQ -DDNNL_BUILD_FOR_CI=ON -DONEDNN_TEST_SET=SMOKE, on top of 6b7f1fb.tests/gtests/internals/test_internalstests/gtests/test_iface_attrDepthwiseFusion,InnerProdBlockedWeights, skipped on main too)tests/gtests/test_iface_primitive_cache.github/automation/commit-msg-check.pyandscripts/fix_header_guards.pyboth pass on the commit. I ran clang-format on the four touched files; the only version I have locally is 22, so I kept its output for the new test code and reverted the two hunks it wanted in pre-existing lines ofprimitive_hashing.cppandprimitive_serialization.cppthat clang-format 18 leaves alone. benchdnn was not run.Checklist
General
Bug fixes