Bug 258708 - [LibWebRTC] Enable AVX2 extensions only if host supports AVX2
Summary: [LibWebRTC] Enable AVX2 extensions only if host supports AVX2
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Diego Pino
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-06-29 20:24 PDT by Diego Pino
Modified: 2023-07-06 20:00 PDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Diego Pino 2023-06-29 20:24:53 PDT
265400@main updated the CMake list of LibWebRTC sources after update to M115 (265320@main).

In the sources update, a new block was added to include specialized files that make use of AVX2 extensions if the host is X64. This condition is too broad, since not all X64 computers have support for AVX2 extensions (rare nowadays, but it may happen).

Another issue we found out was that since the AVX2 files are built with `-march=native` the host may emit AVX512 instructions if the host supports that extension. This may cause compatibility issues if a binary is built in a host with AVX512 support and it is executed in a host without AVX512 suport (the result will be a crash due to 'invalid instruction').

The build flag `m=no-avx512f` prevents emitting AVX512 instructions.

https://stackoverflow.com/questions/60815316/disabling-all-avx512-extensions
Comment 1 Diego Pino 2023-06-29 20:39:29 PDT
Pull request: https://github.com/webkit/webkit/pull/15432
Comment 2 EWS 2023-06-30 01:18:09 PDT
Committed 265646@main (d95cad7579b5): <https://commits.webkit.org/265646@main>

Reviewed commits have been landed. Closing PR #15432 and removing active labels.
Comment 3 Radar WebKit Bug Importer 2023-06-30 01:19:15 PDT
<rdar://problem/111556402>
Comment 4 Diego Pino 2023-07-03 20:14:02 PDT
After chatting with Carlos Lopez in a private conversation, we concluded that the LibWebRTC's AVX2 files should be included always, regardless of whether the host machine that builds WebKit has support for it or not.

The flags `-march=machine -mno-avx512f` added to CMAKE_CXX_FLAGS should be removed because they affect all files. Instead, these flags should only apply to the set of AVX2 files. To enable compilation with AVX2 extension is enough with adding '-mavx2'. This is how Chromium does it:

https://webrtc.googlesource.com/src/+/refs/heads/main/modules/audio_processing/aec3/BUILD.gn#269

CMake macro `set_source_files_properties` can be used to apply build flags to a set of files.

https://cmake.org/cmake/help/latest/prop_sf/COMPILE_OPTIONS.html#prop_sf:COMPILE_OPTIONS
Comment 5 Diego Pino 2023-07-03 20:21:03 PDT
Pull request: https://github.com/webkit/webkit/pull/15527
Comment 6 EWS 2023-07-04 07:45:25 PDT
Committed 265754@main (0de2717c0029): <https://commits.webkit.org/265754@main>

Reviewed commits have been landed. Closing PR #15527 and removing active labels.
Comment 7 Diego Pino 2023-07-05 21:38:50 PDT
Re-opening for pull request https://github.com/webkit/webkit/pull/15586
Comment 8 EWS 2023-07-05 21:48:08 PDT
Committed 265790@main (48d7dce49219): <https://commits.webkit.org/265790@main>

Reviewed commits have been landed. Closing PR #15586 and removing active labels.
Comment 9 Diego Pino 2023-07-06 19:47:55 PDT
Re-opening for pull request https://github.com/webkit/webkit/pull/15622
Comment 10 EWS 2023-07-06 20:00:16 PDT
Committed 265832@main (aff1c9e1b48a): <https://commits.webkit.org/265832@main>

Reviewed commits have been landed. Closing PR #15622 and removing active labels.