Skip to content

Post-op chains silently reordered when the fused op is not first in the chain #30

Description

@lwandrebeck

Summary

The native loopers scan the post-op chain for the first fusable op —
relu / gelu_tanh / gelu_erf / sigmoid / tanh / swish — hand it to the
microkernel epilogue, and apply everything else afterwards via
apply_postops_tile(). The scan accepts a match at any index, but the epilogue
runs before the remaining ops, so fusing an op that is not at the head of the
chain silently reorders it.

binary_add:sigmoid computes binary_add(sigmoid(x)) instead of
sigmoid(binary_add(x)).

A binary/residual op followed by an activation is an ordinary pattern, and the
result is wrong numerics with nothing reported.

Not ISA-specific, and not tied to --no-aocldlp

Reproduced on an Intel Xeon 6767P with full AVX-512 (avx512f,
avx512_bf16, avx512_vnni), where the AVX-512 microkernels and epilogue are
the ones running — i.e. the default configuration on mainstream hardware.

Reproduce

Pin the chains through a gtest input file, with alpha=1 and beta=0 so this is
isolated from alpha/beta handling:

256,256,256,binary_add:sigmoid,native_gemm,false,false,1,0,,,tensor
256,256,256,sigmoid:binary_add,native_gemm,false,false,1,0,,,tensor
256,256,256,binary_mul:relu,native_gemm,false,false,1,0,,,tensor
256,256,256,relu:binary_mul,native_gemm,false,false,1,0,,,tensor
256,256,256,clip:tanh,native_gemm,false,false,1,0,,,tensor
256,256,256,tanh:clip,native_gemm,false,false,1,0,,,tensor
./gtests --op matmul --input_file F --ndims 2 --test 2 --seed 424242 \
         --gtest_filter="*TestMatmul.F32_F32/*"
chain fusable op position before after fix
binary_add:sigmoid second FAIL pass
binary_mul:relu second FAIL pass
clip:tanh second FAIL pass
sigmoid:binary_add first pass pass
relu:binary_mul first pass pass
tanh:clip first pass pass

6 passed / 6 failed before, 12 passed / 0 failed after.

Suggested fix

Fuse only when the fusable op sits at index 0; otherwise leave it to the ordered
post-op pass. The same pattern appears in all four native loopers (fp32/bf16
GEMM, fp32/bf16 BRGEMM).

Reference branch: https://github.com/lwandrebeck/BullDNN/tree/upstream/postop-chain-reorder

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions