Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BF16 Softmax on EMR got 40% performance regression #2237

Open
a3213105 opened this issue Dec 2, 2024 · 6 comments · May be fixed by #2271
Open

BF16 Softmax on EMR got 40% performance regression #2237

a3213105 opened this issue Dec 2, 2024 · 6 comments · May be fixed by #2271
Assignees
Labels
enhancement A feature or an optimization request platform:cpu-x64 Intel64/AMD64 processors. Codeowner: @oneapi-src/onednn-cpu-x64
Milestone

Comments

@a3213105
Copy link

a3213105 commented Dec 2, 2024

Summary

BF16 Softmax on EMR got 40% performance regression after V3.5 "enable scratchpad for non-f32 dst dt"
Below is the reproducing step, we can see that after commit ad99c73, the average latency of softmax slowdown from 0.198575ms to 0.337924 ms

performance of commit e2d4a8c
$ numactl -N 1 ./tests/benchdnn/benchdnn --soft
max --mode=p --dir=FWD_I --sdt=bf16 --ddt=bf16 --stag=abcd --dtag=abcd --alg=SOFTMAX --
axis=3 64x16x100x100
Output template: perf,%engine%,%impl%,%name%,%prb%,%Gops%,%+ctime%,%-time%,%-Gflops%,%0time%,%0Gflops%
perf,cpu,jit:avx10_1_512,,--mode=P --softmax --dir=FWD_I --sdt=bf16 --ddt=bf16 --stag=abcd --dtag=abcd --axis=3 64x16x100x100,0,0.495605,0.18042,0,0.198575,0
tests:1 passed:1 skipped:0 mistrusted:0 unimplemented:0 invalid_arguments:0 failed:0 listed:0
total perf: min(ms):0.18042 avg(ms):0.198575
total: 3.41s; fill: 0.39s (11%);

performance of commit ad99c73
$ numactl -N 1 ./tests/benchdnn/benchdnn --softmax --mode=p --dir=FWD_I --sdt=bf16 --ddt=bf16 --stag=abcd --dtag=abcd --alg=SOFTMAX --axis=3 64x16x100x100
Output template: perf,%engine%,%impl%,%name%,%prb%,%Gops%,%+ctime%,%-time%,%-Gflops%,%0time%,%0Gflops%
perf,cpu,jit:avx10_1_512,,--mode=P --softmax --dir=FWD_I --sdt=bf16 --ddt=bf16 --stag=abcd --dtag=abcd --axis=3 64x16x100x100,0,0.455322,0.287598,0,0.337924,0
tests:1 passed:1 skipped:0 mistrusted:0 unimplemented:0 invalid_arguments:0 failed:0 listed:0
total perf: min(ms):0.287598 avg(ms):0.337924
total: 3.40s; fill: 0.39s (11%);

Environment

flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cat_l2 cdp_l3 invpcid_single intel_ppin cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req vnmi avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr ibt amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities

Linux emr-qs-01 6.5.0-44-generic #44~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Jun 18 14:36:16 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

cmake version 3.27.5

@a3213105 a3213105 added the sighting Suspicious library behavior. Should be promoted to a bug when confirmed label Dec 2, 2024
@shu1chen shu1chen added the platform:cpu-x64 Intel64/AMD64 processors. Codeowner: @oneapi-src/onednn-cpu-x64 label Dec 2, 2024
@kazukiminemura
Copy link

kazukiminemura commented Dec 2, 2024

Hi team, I confirmed this is regression issue on both of SPR and EMR.

Linux ortce-emr3 6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0
g++ (Ubuntu 13.2.0-23ubuntu4) 13.2.0

only main branch applied "--attr-acc-mode=bf16" option.

platform SPR EMR
e2d4a8c 0.170773 0.363158
ad99c73 0.30731 0.565571
891c69a (latest main) 0.313021 0.603933

@a3213105
Copy link
Author

a3213105 commented Dec 2, 2024

F16 also met the regression

@mgouicem
Copy link
Contributor

mgouicem commented Dec 2, 2024

Thanks for the report. This change in oneDNN implementation was to resolve an accuracy issue, where we used to accumulate with destination datatype (e.g. bf16/f16), instead of f32.

Reverting performance would require to introduce support for accumulation_mode=relaxed attribute to softmax primitive. Is that something that would work for you?

@a3213105
Copy link
Author

a3213105 commented Dec 3, 2024

Thanks for the report. This change in oneDNN implementation was to resolve an accuracy issue, where we used to accumulate with destination datatype (e.g. bf16/f16), instead of f32.

Reverting performance would require to introduce support for accumulation_mode=relaxed attribute to softmax primitive. Is that something that would work for you?

So, you means that I use accumulation_mode=relaxed can fix the perf gap?

Another phenomenon is that the performance regression is obvious when the axis dim is small, and as the dim size grows, the performance gap becomes almost invisible.

Can we do some optimization for small size?

@kminemur
Copy link

kminemur commented Dec 3, 2024

Hi Team,

the option of "--attr-acc-mode=relaxed" does not help for the performance gap.

numactl -N 1 ./tests/benchdnn/benchdnn --softmax --mode=p --dir=FWD_I --sdt=bf16 --ddt=bf16 --stag=abcd --dtag=abcd --alg=SOFTMAX --axis=3 64x16x100x100 --attr-acc-mode=relaxed

Platform SPR EMR
ad99c73 unknown option: softmax '--attr-acc-mode=relaxed' unknown option: softmax '--attr-acc-mode=relaxed'
891c69a (latest main) 0.299256 0.623694

@mgouicem
Copy link
Contributor

@a3213105 @kminemur attr-acc-mode relaxed is not supported yet by the implementation. To restore performance:

  • on oneDNN side, we need to add support for that attribute in implementation
  • on your side, you will need to pass that attribute.

We will update you as we add support for the accumulation mode to the implementation.

@vpirogov vpirogov added enhancement A feature or an optimization request and removed sighting Suspicious library behavior. Should be promoted to a bug when confirmed labels Dec 10, 2024
@vpirogov vpirogov added this to the v3.7 milestone Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature or an optimization request platform:cpu-x64 Intel64/AMD64 processors. Codeowner: @oneapi-src/onednn-cpu-x64
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants