Skip to content

scalar_microkernel treats beta as a flag rather than a scale (wrong results for beta not in {0,1}) #34

Description

@lwandrebeck

Summary

The AVX-512 microkernels compute acc += beta * C_old with fmadd.
scalar_microkernel() does not: it zeroes C when beta is 0 and otherwise adds
products straight into C, i.e. C_old + A*B with an implicit weight of 1. That is
correct only for beta ∈ {0, 1} and silently wrong for every other value.

The FP32 looper reaches those other values by design: when alpha != 1 it defers
scaling and passes beta/alpha to the microkernel, so an arbitrary alpha with an
arbitrary beta yields an arbitrary ratio. Any host without AVX-512 therefore gets
wrong results from the native FP32 path whenever alpha != 1 and beta != 0.

Reproduce

On a host without AVX-512, force the native path over the gtests' random
alpha/beta and compare against the reference kernel:

ZENDNNL_MATMUL_ALGO=10 ./gtests --seed 424242 --gtest_filter="*TestMatmul.F32_F32*"

Requires the unguarded AVX-512 epilogue helpers (#32) to be fixed first, since
those otherwise fault before reaching this.

After the fix, every remaining failure in that run is transA=1, which the native
path declines outright and which has no AOCL-DLP to fall back to in such a build.

Suggested fix

Scale C by beta, matching the AVX-512 kernels.

Reference branch: https://github.com/lwandrebeck/BullDNN/tree/upstream/native-beta-as-flag

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