-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
build : detect AVX512 in Makefile, add AVX512 option in CMake #2043
Conversation
Thank you for your contribution. I see a few issues in this PR as seen in c3753f9. Issue 1 - AVX-512 as a defaultFor CMake PR defaults to build with AVX-512, which is not ubiquitous. Only recent generations of Intel CPUs and very recent generations of AMD CPUs support them. That's why I don't think it's reasonable to target AVX-512 and force a lot of folks setting WHISPER_NO_AVX512 now. Of course situation may change in next 5 years. Side note: I dislike that we have negative way of expressing x86 ISA extensions. Maybe we should finally change it in whisper.cpp, but this PR most likely wouldn't be the right venue to do that, as such change should be isolated from adding additional stuff.Issue 2 - Different AVX-512 enablement for MSVC vs restPR enables AVX things differently for CMake and make. AVX-512 consists of many instruction subsets, and not all of them have to be supported by CPU.
For non-MSVC CMake and make it uses From compatibility perspective:
set is the safest to go with assuming some form of AVX-512 is supported (and that's why MSVC does what it does). Side note: Xeon Phi is the exception (not supporting VL, DQ, BW), but per https://en.wikipedia.org/wiki/Xeon_Phi: That's why I think for non-MSVC CMake and make we should ideally target the same set. For compiler it should be: Note: |
Updated PR so that for CMake AVX512 must be enabled explicitly. Also added AVX512 subsets for this case as suggested, however I would argue that this will lead to "bad instruction" error during execution in case a particular subset is used by the code, but not supported by the target CPU. Although in practice this may not happen because it looks like the inference code does not use any other AVX512 instruction subsets than AVX512F. |
CMakeLists.txt
Outdated
option(WHISPER_NO_F16C "whisper: disable F16c" OFF) | ||
option(WHISPER_NO_AVX "whisper: disable AVX" OFF) | ||
option(WHISPER_NO_AVX2 "whisper: disable AVX2" OFF) | ||
option(WHISPER_AVX512 "whisper: enable AVX512" OFF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest using WHISPER_NO_AVX512
to be consistent with rest of these settings (until they will be overhauled one day in whisper.cpp to use positive notion instead of negative one), and naturally changing default to ON
in such case.
Sorry if my rant in side note made you misunderstand the expectation for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting to use WHISPER_NO_AVX512
set to ON
by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, to be consistent, because all other ISA extension options in whisper.cpp have such polarity.
(Maybe we'll change it in the future, but if it will happen, then it should be done separately.)
Makefile
Outdated
AVX512F_M := $(shell $(CPUINFO_CMD) | grep -iw 'AVX512F') | ||
ifneq (,$(AVX512F_M)) | ||
CFLAGS += -mavx512f | ||
CXXFLAGS += -mavx512f | ||
endif | ||
|
||
AVX512DQ_M := $(shell $(CPUINFO_CMD) | grep -iw 'AVX512DQ') | ||
ifneq (,$(AVX512DQ_M)) | ||
CFLAGS += -mavx512dq | ||
CXXFLAGS += -mavx512dq | ||
endif | ||
|
||
AVX512CD_M := $(shell $(CPUINFO_CMD) | grep -iw 'AVX512CD') | ||
ifneq (,$(AVX512CD_M)) | ||
CFLAGS += -mavx512cd | ||
CXXFLAGS += -mavx512cd | ||
endif | ||
|
||
AVX512CD_M := $(shell $(CPUINFO_CMD) | grep -iw 'AVX512BW') | ||
ifneq (,$(AVX512BW_M)) | ||
CFLAGS += -mavx512bw | ||
CXXFLAGS += -mavx512bw | ||
endif | ||
|
||
AVX512VL_M := $(shell $(CPUINFO_CMD) | grep -iw 'AVX512VL') | ||
ifneq (,$(AVX512VL_M)) | ||
CFLAGS += -mavx512vl | ||
CXXFLAGS += -mavx512vl | ||
endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest combining them into one block, where we check just for AVX512F, but then add flags related to all 5 AVX-512 subsets (F, CD, VL, DQ, BW). I don't believe Xeon Phi existence is good enough reason check all of these subsets individually. I never suggested checking them individually.
Table at https://en.wikipedia.org/wiki/AVX-512#CPUs_with_AVX-512 explains why.
Let's have a simpler code. If there will be mainstream CPU in the future not fitting into the assumption (F presence means presence of CD, VL, DQ and BW too), then we can start playing again with checking those flags individually.
CXXFLAGS += -mavx512vl | ||
endif | ||
|
||
AVX512VNNI_M := $(shell $(CPUINFO_CMD) | grep -iwE 'AVX512_VNNI|AVX512VNNI') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AVX512_VNNI is for Linux, so just out of curiosity:
Which OS uses AVX512VNNI?
As you're adding VNNI beside basic AVX-512 subsets, I would suggest adding also VBMI, as llama.cpp does it too. It's nice to have some kind of parity between these projects.
Moreover, if you're adding VNNI and VBMI in Makefile, you should add them in CMakeLists.txt too, via WHISPER_NO_AVX512_VNNI
and WHISPER_NO_AVX512_VBMI
, defaulting to ON
. I suggest using add_compile_definitions
similarly like llama.cpp does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added AVX512VNNI for pure symmetry just in case any system does have it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked about AVX512VNNI, didn't request removing. But I see you removed it in dc69460.
So I looked around and it seems AVX512VNNI is the name reported by FreeBSD.
http://fxr.watson.org/fxr/source/x86/x86/identcpu.c#L994
Please bring back grep -iwE 'AVX512_VNNI|AVX512VNNI'
for VNNI detection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, my feeling was right then.
CMakeLists.txt
Outdated
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX512") | ||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:AVX512") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX512") | ||
# from llama.cpp: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I woud suggest removing from llama.cpp
comment line. There are many things shared between llama.cpp and whisper.cpp, in both directions, so if we would be marking all of them, it would be pure noise. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, just wanted to note, that I'm not author of that comment.
So fixing VNNI detection for non-Linux and removing superfluous comment are the only remaining things. |
Tested inference on a Linux machine with AVX512 all five instruction subsets and AVX512 VNNI. |
One little thing. I would suggest changing PR title for two reasons:
I would suggest following one:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…nov#2043) * make : add AVX512 detection to Makefile and CMakeLists.txt * make : autodetect more AVX512 instruction subsets * cmake : do not default to AVX512, must be enabled explicitly * cmake : enable a set of AVX512 subsets, when AVX512 is turned on * make : consolidate AVX512 subsets, add AVX512 VBMI * cmake : revert to NO AVX512 setting, add settings for AVX512 VNNI and VBMI * make : re-introduce AVX512VNNI back * cmake : remove superfluous comment line
…nov#2043) * make : add AVX512 detection to Makefile and CMakeLists.txt * make : autodetect more AVX512 instruction subsets * cmake : do not default to AVX512, must be enabled explicitly * cmake : enable a set of AVX512 subsets, when AVX512 is turned on * make : consolidate AVX512 subsets, add AVX512 VBMI * cmake : revert to NO AVX512 setting, add settings for AVX512 VNNI and VBMI * make : re-introduce AVX512VNNI back * cmake : remove superfluous comment line
…nov#2043) * make : add AVX512 detection to Makefile and CMakeLists.txt * make : autodetect more AVX512 instruction subsets * cmake : do not default to AVX512, must be enabled explicitly * cmake : enable a set of AVX512 subsets, when AVX512 is turned on * make : consolidate AVX512 subsets, add AVX512 VBMI * cmake : revert to NO AVX512 setting, add settings for AVX512 VNNI and VBMI * make : re-introduce AVX512VNNI back * cmake : remove superfluous comment line
…nov#2043) * make : add AVX512 detection to Makefile and CMakeLists.txt * make : autodetect more AVX512 instruction subsets * cmake : do not default to AVX512, must be enabled explicitly * cmake : enable a set of AVX512 subsets, when AVX512 is turned on * make : consolidate AVX512 subsets, add AVX512 VBMI * cmake : revert to NO AVX512 setting, add settings for AVX512 VNNI and VBMI * make : re-introduce AVX512VNNI back * cmake : remove superfluous comment line
Adds missing AVX512 detection to Makefile and CMakeLists.txt