[CPU] Fix Power call-boundary performance and signed-int8 BRGEMM #38667
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?
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?
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?
Agreed. Removed brgemmCtx::has_post_ops, both assignments, and the associated comment. The field had no readers; B-scale configuration remains unchanged.
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.
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.
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?
@v-Golubev fixed thanks
Approved these changes.
v-Golubev
allnes
Details:
powfcall boundaries in both dynamic and static CPU Power emitters. Emitvzeroupperafter spilling live vector registers and before each call, and after the call for SSE4.1 host kernels. Restore the spilled registers afterward. Retain the existingpowfimplementation without approximations or model-specific special cases.Tickets:
AI Assistance: