Skip to content

ukernels: add bf16 * bf16 -> bf16 optimized tile functions for x86 and arm64. - #15543

Merged
bjacob merged 1 commit into
mainfrom
bjacob-ukernel-bf16bf16bf16
Nov 14, 2023
Merged

bjacob merged 1 commit into
mainfrom
bjacob-ukernel-bf16bf16bf16

Conversation

@bjacob

@bjacob bjacob commented Nov 10, 2023

Copy link
Copy Markdown
Collaborator

This should fix the "50x slowdown" performance issue #15504.

@bjacob
bjacob force-pushed the bjacob-ukernel-test-improvements branch from 0cfef67 to 2fe4ae1 Compare November 10, 2023 20:16
@bjacob
bjacob force-pushed the bjacob-ukernel-bf16bf16bf16 branch 3 times, most recently from b2d7384 to 6508cec Compare November 10, 2023 21:40
@bjacob
bjacob marked this pull request as ready for review November 10, 2023 21:44
@bjacob
bjacob requested a review from benvanik as a code owner November 10, 2023 21:44
@bjacob

bjacob commented Nov 14, 2023

Copy link
Copy Markdown
Collaborator Author

PTAL @benvanik

Base automatically changed from bjacob-ukernel-test-improvements to main November 14, 2023 15:58
bjacob added a commit that referenced this pull request Nov 14, 2023
* Consistently compare with/without skipping of intermediate roundings.
A catch is that the ukernel may fall back to a generic code path (and
that fallback is consistently exercised by the test, even when a
non-fallback path is also available and tested). And generic code paths
("tile functions") never skipped intermediate roundings, even if allowed
to by the flag. This caused complicated test code retrying again on
error. This PR simply adds the skipping-intermediate-roundings generic
tile functions, so the test code is simpler, and concretely I just
needed that for #15543 as I'm adding bf16-accumulator tile functions
that are skipping intermediate roundings.
* I had to also update `iree-e2e-matmul-test` to switch to skipping
intermediate roundings. Unlike the ukernels' own tests, which really
must test both flavors, in `iree-e2e-matmul-test` we are e2e testing
what the compiler produces, and that is skippig intermediate roundings
at least by default, and while that could be overridden with
`--iree-llvmcpu-skip-intermediate-roundings=false`, we don't currently
test that in e2e matmul tests.
* Generate better random test input values. Some were too large - when
we generate random bfloat16 to accumulate into bfloat16, they better be
very small as we don't want to grow accumulators to the point where they
would start rounding. It's OK, because bfloat16 kernels use bfloat16
arithmetic instructions, not bit hacks, so correctness is sufficiently
tested on very small values. Conversely, for int8/int16 test input
values, we were generating a very narrow range and that was potentially
missing important coverage as some of our int kernels are starting to do
evil bit hacks (#15525).
@bjacob
bjacob force-pushed the bjacob-ukernel-bf16bf16bf16 branch from 6508cec to 3e19a88 Compare November 14, 2023 15:59
@bjacob

bjacob commented Nov 14, 2023

Copy link
Copy Markdown
Collaborator Author

PTAL @benvanik - sorry for the insistence, it's just that earlier today you approved the other PR #15542 in this queue and not this one, and I wonder if that's intentional or just fell between cracks.

@bjacob
bjacob merged commit 0908ff8 into main Nov 14, 2023
@bjacob
bjacob deleted the bjacob-ukernel-bf16bf16bf16 branch November 14, 2023 16:55
Comment on lines +63 to +64
__m256i loaded = _mm256_loadu_si256((const __m256i*)(out_ptr + i * 16));
acc[i] = _mm512_cvtpbh_ps(*(const __m256bh*)&loaded);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see errors here building on my Windows machine:

[build] [739/7322   9% :: 11.296] Building C object runtime\src\iree\builtins\ukernel\arch\x86_64\CMakeFiles\iree_builtins_ukernel_arch_x86_64_x86_64_avx512_bf16.objects.dir\mmt4d_x86_64_avx512_bf16.c.obj
[build] FAILED: runtime/src/iree/builtins/ukernel/arch/x86_64/CMakeFiles/iree_builtins_ukernel_arch_x86_64_x86_64_avx512_bf16.objects.dir/mmt4d_x86_64_avx512_bf16.c.obj 
[build] ccache C:\PROGRA~2\MICROS~1\2022\Preview\VC\Tools\MSVC\1431~1.311\bin\Hostx64\x64\cl.exe  /nologo  -external:ID:\dev\projects\iree -external:ID:\dev\projects\iree-build -external:ID:\dev\projects\iree\runtime\src\iree\.. -external:ID:\dev\projects\iree-build\runtime\src\iree\.. -external:W0 /DWIN32 /D_WINDOWS /Z7 /O2 /Ob1  -MD /DWIN32_LEAN_AND_MEAN /DNOMINMAX /D_USE_MATH_DEFINES /D_CRT_SECURE_NO_WARNINGS /D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES /GR- /bigobj /Zc:preprocessor /std:c11 /W3 /wd4200 /wd4018 /wd4146 /wd4244 /wd4267 /wd4005 /wd4065 /wd4141 /wd4624 /wd5105 /arch:AVX512 -std:c11 /showIncludes /Foruntime\src\iree\builtins\ukernel\arch\x86_64\CMakeFiles\iree_builtins_ukernel_arch_x86_64_x86_64_avx512_bf16.objects.dir\mmt4d_x86_64_avx512_bf16.c.obj /Fdruntime\src\iree\builtins\ukernel\arch\x86_64\CMakeFiles\iree_builtins_ukernel_arch_x86_64_x86_64_avx512_bf16.objects.dir\ /FS -c D:\dev\projects\iree\runtime\src\iree\builtins\ukernel\arch\x86_64\mmt4d_x86_64_avx512_bf16.c
[build] D:\dev\projects\iree\runtime\src\iree\builtins\ukernel\arch\x86_64\mmt4d_x86_64_avx512_bf16.c(64): warning C4013: '_mm512_cvtpbh_ps' undefined; assuming extern returning int
[build] D:\dev\projects\iree\runtime\src\iree\builtins\ukernel\arch\x86_64\mmt4d_x86_64_avx512_bf16.c(64): error C2440: '=': cannot convert from 'int' to '__m512'

CI looks green though. Guess my machine has avx512 and the CI doesn't, or something like that?

bjacob added a commit that referenced this pull request Nov 15, 2023
…#15589)

As reported by @ScottTodd in
#15543 (comment)

At least this MSVC version, identified by `_MSC_VER=1930`, lacks the
`_mm512_cvtpbh_ps` intrinsic. On the other hand, the CI builders are
doing OK, and they have `_MSC_VER=1937`.
ramiro050 pushed a commit to ramiro050/iree that referenced this pull request Dec 19, 2023
* Consistently compare with/without skipping of intermediate roundings.
A catch is that the ukernel may fall back to a generic code path (and
that fallback is consistently exercised by the test, even when a
non-fallback path is also available and tested). And generic code paths
("tile functions") never skipped intermediate roundings, even if allowed
to by the flag. This caused complicated test code retrying again on
error. This PR simply adds the skipping-intermediate-roundings generic
tile functions, so the test code is simpler, and concretely I just
needed that for iree-org#15543 as I'm adding bf16-accumulator tile functions
that are skipping intermediate roundings.
* I had to also update `iree-e2e-matmul-test` to switch to skipping
intermediate roundings. Unlike the ukernels' own tests, which really
must test both flavors, in `iree-e2e-matmul-test` we are e2e testing
what the compiler produces, and that is skippig intermediate roundings
at least by default, and while that could be overridden with
`--iree-llvmcpu-skip-intermediate-roundings=false`, we don't currently
test that in e2e matmul tests.
* Generate better random test input values. Some were too large - when
we generate random bfloat16 to accumulate into bfloat16, they better be
very small as we don't want to grow accumulators to the point where they
would start rounding. It's OK, because bfloat16 kernels use bfloat16
arithmetic instructions, not bit hacks, so correctness is sufficiently
tested on very small values. Conversely, for int8/int16 test input
values, we were generating a very narrow range and that was potentially
missing important coverage as some of our int kernels are starting to do
evil bit hacks (iree-org#15525).
ramiro050 pushed a commit to ramiro050/iree that referenced this pull request Dec 19, 2023
…and arm64. (iree-org#15543)

This should fix the "50x slowdown" performance issue iree-org#15504.
ramiro050 pushed a commit to ramiro050/iree that referenced this pull request Dec 19, 2023
…iree-org#15589)

As reported by @ScottTodd in
iree-org#15543 (comment)

At least this MSVC version, identified by `_MSC_VER=1930`, lacks the
`_mm512_cvtpbh_ps` intrinsic. On the other hand, the CI builders are
doing OK, and they have `_MSC_VER=1937`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants