Skip to content

Fix MSVC build by disabling AVX-512-BF16 in non-latest MSVC versions. - #15589

Merged
bjacob merged 3 commits into
iree-org:mainfrom
bjacob:avx512bf16-broken-in-msc-ver-1930
Nov 15, 2023
Merged

bjacob merged 3 commits into
iree-org:mainfrom
bjacob:avx512bf16-broken-in-msc-ver-1930

Conversation

@bjacob

@bjacob bjacob commented Nov 14, 2023

Copy link
Copy Markdown
Collaborator

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.

@bjacob
bjacob marked this pull request as ready for review November 14, 2023 19:54
@bjacob
bjacob requested a review from benvanik as a code owner November 14, 2023 19:54
@bjacob
bjacob requested a review from ScottTodd November 14, 2023 19:54
check_cxx_compiler_flag("${IREE_UK_COPTS_X86_64_AVX512_BF16}" IREE_UK_BUILD_X86_64_AVX512_BF16)
endif()

if (MSVC_VERSION AND ("${MSVC_VERSION}" VERSION_LESS 1937))

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 see errors building the iree_builtins_ukernel_arch_x86_64_x86_64_avx512_bf16 target with this change.

CMake debugging... I'm not sure unset is doing what we want here 🤔

[cmake] -- MSVC_VERSION: 1931
[cmake] -- IREE_UK_BUILD_X86_64_AVX512_BF16: 1
[cmake] -- missing _mm512_cvtpbh_ps, calling unset
[cmake] -- IREE_UK_BUILD_X86_64_AVX512_BF16: 1
[cmake] -- IREE_UK_BUILD_X86_64_AVX512_BF16, adding x86_64_avx512_bf16

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.

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.

Okay nice, unset(IREE_UK_BUILD_X86_64_AVX512_BF16 CACHE) did the trick.

Is this the right cache behavior as written, or should we do this?

if ((CMAKE_C_COMPILER_ID STREQUAL GNU) AND
    (CMAKE_C_COMPILER_VERSION VERSION_LESS 12))
# Old GCC versions have incompatible x86 intrinsics. Supporting them
# is not considered worth it. By not defining these tokens, we leave these
# code paths out. At least GCC 9 is known to be problematic, while GCC 12 is
# known working, so the current test is based on that.
else()
check_cxx_compiler_flag("${IREE_UK_COPTS_X86_64_AVX2_FMA}" IREE_UK_BUILD_X86_64_AVX2_FMA)
check_cxx_compiler_flag("${IREE_UK_COPTS_X86_64_AVX512_BASE}" IREE_UK_BUILD_X86_64_AVX512_BASE)
check_cxx_compiler_flag("${IREE_UK_COPTS_X86_64_AVX512_VNNI}" IREE_UK_BUILD_X86_64_AVX512_VNNI)
if (MSVC_VERSION AND ("${MSVC_VERSION}" VERSION_LESS 1937))
  # Missing _mm512_cvtpbh_ps intrinsic at _MSC_VER=1930.
  unset(IREE_UK_BUILD_X86_64_AVX512_BF16 CACHE)
else()
  check_cxx_compiler_flag("${IREE_UK_COPTS_X86_64_AVX512_BF16}" IREE_UK_BUILD_X86_64_AVX512_BF16)
endif()
endif()

(with some formatting)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ah, thanks for debugging that! is the new commit here what's needed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Is this the right cache behavior as written, or should we do this?

Yeah I thought about that but i like how the current way it's written avoids nesting, and it should not make a difference in practice as the compiler can't be simultaneously GNU and MSVC, and the non-nested for keeps things more orthogonal.

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.

If I'm understanding the CMake cache correctly, check_cxx_compiler_flag will run a check and write the result to the cache, but then unset will clear the result of the check, so future configures will run the check_cxx_compiler_flag check again. If we add nesting then the check won't happen at all (first configure and future configures)

// first configure
check_cxx_compiler_flag --> 1
unset

// second configure
check_cxx_compiler_flag --> 1
unset

when we could have

// first configure
unset

// second configure
unset

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.

Hmm... yeah, I see this each time I configure:

[cmake] -- Performing Test IREE_UK_BUILD_X86_64_AVX512_BF16
[cmake] -- Performing Test IREE_UK_BUILD_X86_64_AVX512_BF16 - Success

Adds a bit of log noise and configure time overhead if we always end up ignoring the result on this compiler version.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@ScottTodd new version, PTAL!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Note, since we are now skipping the configure-check and not unset-ing anything, you will need to wipe your IREE_UK_BUILD_* cached variables from CMakeCache.txt before rerunning.

@ScottTodd ScottTodd left a comment

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.

Thanks!

@bjacob
bjacob merged commit 1012586 into iree-org:main Nov 15, 2023
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.

2 participants