← Back to Pull requests

[CPU] Fix Power call-boundary performance and signed-int8 BRGEMM #38667

Merged
allnes merged 6 files (449 lines) on Oct 13, 2026 14:32 UTC
View on GitHub
allnes allnes commented on Oct 07, 2026 15:17 UTC
Author

Details:

  • Avoid AVX-to-SSE transition penalties at scalar powf call boundaries in both dynamic and static CPU Power emitters. Emit vzeroupper after spilling live vector registers and before each call, and after the call for SSE4.1 host kernels. Restore the spilled registers afterward. Retain the existing powf implementation without approximations or model-specific special cases.

  • Correct signed-int8 BRGEMM ISA selection on non-AMX hosts. AVX-512 VNNI shifts signed inputs to unsigned and requires compensation that this wrapper does not supply. Select AVX10.2 when available, otherwise AVX2 VNNI2, to use native signed-int8 dot products without compensation. Leave AMX and non-int8 ISA selection unchanged.
  • Tickets:

  • CVS-185352
  • AI Assistance:

  • AI assistance used: yes.
  • Diff: 449 lines (+279 / -170) across 6 files Reviewer: v-Golubev Review duration: 8594m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.47) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 449 lines diff across 6 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.86 · 5 substantive comment(s)
    0.86
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    88%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.366
    Real PR Conversation Timeline
    10 items
    v-Golubev v-Golubev commented on code on Oct 08, 2026 10:51 UTC
    Code Review
    src/plugins/intel_cpu/src/nodes/kernels/x64/brgemm_kernel.cpp:1
    @@ -315,7 +309,7 @@ void BrgemmKernel::init_brgemm(brgemmCtx& ctx,
         if (use_amx) {
             amx_tile_configure(ctx.palette);
         }
    -    // s8s8 kernel are only support for amx/vnni_2, s8s8 vis compensation pass is not support
    +    // Native s8s8 kernels do not require signed-input compensation post-ops.

    As far as I see, brgemmCtx::has_post_ops is not read anywhere: it is set to true for B scales above and then unconditionally reset here. So the new comment documents a flag that affects nothing. Let's remove the field together with both assignments instead of updating the comment. What do you think?

    v-Golubev v-Golubev commented on code on Oct 08, 2026 10:51 UTC
    Code Review
    src/plugins/intel_cpu/src/emitters/plugin/x64/jit_eltwise_emitters.cpp:1
    @@ -1887,7 +1892,12 @@ void jit_power_static_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs,
                 const Address& source = h->ptr[h->rsp + h->rbx + i * sizeof(float)];
                 h->uni_vmovss(xmm0, source);
                 h->uni_vmovss(xmm1, h->ptr[h->rsp + h->rbx + get_vec_length() + i * sizeof(float)]);
    +            // All live vector registers are spilled; avoid AVX-to-SSE transitions in libm.

    Optional: the whole spill -> powf call -> restore sequence is identical in jit_power_dynamic_emitter and jit_power_static_emitter, so this PR had to patch it twice. Could we extract it into a shared helper?

    v-Golubev v-Golubev commented on code on Oct 08, 2026 11:36 UTC
    Code Review
    src/plugins/intel_cpu/src/emitters/plugin/x64/jit_eltwise_emitters.cpp:1
    @@ -895,7 +895,12 @@ void jit_power_dynamic_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs,
             const Address& source = h->ptr[h->rsp + h->rbx + i * sizeof(float)];
             h->uni_vmovss(xmm0, source);
             h->uni_vmovss(xmm1, h->ptr[h->rsp + h->rbx + get_vec_length() + i * sizeof(float)]);
    +        // All live vector registers are spilled; avoid AVX-to-SSE transitions in libm.
    +        h->uni_vzeroupper();
             h->call(h->rbp);
    +        if (isa == x64::sse41) {
    +            h->uni_vzeroupper();
    +        }

    Let's discuss this change offline: I have following questions:
    1. Why do we need this code?
    2. Why the 2nd uni_vzeroupper is needed for SSE41?
    3. Should this modification be applied to all h->call patterns in x64 emitters?

    allnes allnes commented on code on Oct 08, 2026 17:22 UTC
    Code Review
    src/plugins/intel_cpu/src/nodes/kernels/x64/brgemm_kernel.cpp:1
    @@ -315,7 +309,7 @@ void BrgemmKernel::init_brgemm(brgemmCtx& ctx,
         if (use_amx) {
             amx_tile_configure(ctx.palette);
         }
    -    // s8s8 kernel are only support for amx/vnni_2, s8s8 vis compensation pass is not support
    +    // Native s8s8 kernels do not require signed-input compensation post-ops.

    Agreed. Removed brgemmCtx::has_post_ops, both assignments, and the associated comment. The field had no readers; B-scale configuration remains unchanged.

    allnes allnes commented on code on Oct 08, 2026 17:22 UTC
    Code Review
    src/plugins/intel_cpu/src/emitters/plugin/x64/jit_eltwise_emitters.cpp:1
    @@ -1887,7 +1892,12 @@ void jit_power_static_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs,
                 const Address& source = h->ptr[h->rsp + h->rbx + i * sizeof(float)];
                 h->uni_vmovss(xmm0, source);
                 h->uni_vmovss(xmm1, h->ptr[h->rsp + h->rbx + get_vec_length() + i * sizeof(float)]);
    +            // All live vector registers are spilled; avoid AVX-to-SSE transitions in libm.

    Done. Extracted the complete spill → scalar powf calls → restore sequence into a file-local emit_powf helper shared by dynamic and static Power. This preserves the register handling, stack alignment, numerical behavior, and ISA-specific transition handling.

    allnes allnes commented on code on Oct 08, 2026 17:22 UTC
    Code Review
    src/plugins/intel_cpu/src/emitters/plugin/x64/jit_eltwise_emitters.cpp:1
    @@ -895,7 +895,12 @@ void jit_power_dynamic_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs,
             const Address& source = h->ptr[h->rsp + h->rbx + i * sizeof(float)];
             h->uni_vmovss(xmm0, source);
             h->uni_vmovss(xmm1, h->ptr[h->rsp + h->rbx + get_vec_length() + i * sizeof(float)]);
    +        // All live vector registers are spilled; avoid AVX-to-SSE transitions in libm.
    +        h->uni_vzeroupper();
             h->call(h->rbp);
    +        if (isa == x64::sse41) {
    +            h->uni_vzeroupper();
    +        }

    1. Wide-vector operations before powf leave dirty upper vector state. Entering a legacy-SSE path in libm can then incur an AVX→SSE transition penalty once per lane. This was the measured Power bottleneck. All live vector registers are already spilled, so vzeroupper is safe here and does not change the scalar arguments or result.

    2. libm dispatches independently of the emitter’s ISA and may use AVX even when the emitter targets SSE41. The second vzeroupper clears upper state before the emitter resumes legacy-SSE stores and restores. For AVX2/AVX512 emitters, execution resumes with VEX/EVEX instructions, so this additional cleanup is unnecessary.

    3. The same concern can apply to other external-call boundaries, but inserting vzeroupper before every h->call is not automatically safe. We must verify that live upper lanes are saved and that wide-vector arguments or return values are not destroyed. The other sites use different executor/BRGEMM/debug call conventions. I inspected them but kept this change scoped to the two measured scalar-libm paths; broader handling needs per-boundary validation.

    The updated implementation passed checks on NVL-P, NVL-S, and Sapphire Rapids, including SSE41/AVX2/AVX512 Power coverage and AMX INT8 BRGEMM tests.

    v-Golubev v-Golubev commented on code on Oct 09, 2026 12:53 UTC
    Code Review
    src/plugins/intel_cpu/src/emitters/plugin/x64/jit_eltwise_emitters.cpp:1
    @@ -891,22 +892,28 @@ void jit_power_dynamic_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs,
         h->sub(h->rsp, h->rbx);
     
         // Take src, apply powf on it and replace value on a stack with dst.
    -    for (size_t i = 0; i < get_vec_length() / sizeof(float); ++i) {
    +    for (size_t i = 0; i < vlen / sizeof(float); ++i) {
             const Address& source = h->ptr[h->rsp + h->rbx + i * sizeof(float)];
             h->uni_vmovss(xmm0, source);
    -        h->uni_vmovss(xmm1, h->ptr[h->rsp + h->rbx + get_vec_length() + i * sizeof(float)]);
    +        h->uni_vmovss(xmm1, h->ptr[h->rsp + h->rbx + vlen + i * sizeof(float)]);
    +        // All live vector registers are spilled; avoid AVX-to-SSE transitions in libm.
    +        h->uni_vzeroupper();
             h->call(h->rbp);
    +        if (isa == x64::sse41) {
    +            // libm may use AVX internally; clear upper state before returning to legacy SSE.

    It's hard to understand the context by these comments. Could you please reuse your (1) and (2) answers from here and expand the comment?

    allnes allnes commented on code on Oct 12, 2026 14:14 UTC
    Code Review
    src/plugins/intel_cpu/src/emitters/plugin/x64/jit_eltwise_emitters.cpp:1
    @@ -891,22 +892,28 @@ void jit_power_dynamic_emitter::emit_isa(const std::vector<size_t>& in_vec_idxs,
         h->sub(h->rsp, h->rbx);
     
         // Take src, apply powf on it and replace value on a stack with dst.
    -    for (size_t i = 0; i < get_vec_length() / sizeof(float); ++i) {
    +    for (size_t i = 0; i < vlen / sizeof(float); ++i) {
             const Address& source = h->ptr[h->rsp + h->rbx + i * sizeof(float)];
             h->uni_vmovss(xmm0, source);
    -        h->uni_vmovss(xmm1, h->ptr[h->rsp + h->rbx + get_vec_length() + i * sizeof(float)]);
    +        h->uni_vmovss(xmm1, h->ptr[h->rsp + h->rbx + vlen + i * sizeof(float)]);
    +        // All live vector registers are spilled; avoid AVX-to-SSE transitions in libm.
    +        h->uni_vzeroupper();
             h->call(h->rbp);
    +        if (isa == x64::sse41) {
    +            // libm may use AVX internally; clear upper state before returning to legacy SSE.

    @v-Golubev fixed thanks

    v-Golubev v-Golubev approved these changes on Oct 13, 2026 07:53 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    allnes allnes
    Labels
    risk: low confidence: 88.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 46.9% (MEDIUM) · Higher = larger blast radius
    46.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 88.6% · Lower = rushed or shallow review
    88.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 5.3% · Safe to merge
    5.3%