Repository: ggml-org/llama.cpp
Pull request: Make updates to fix issues with clang-cl builds while using AVX512 flags

- The PR contains fixes to build llama.cpp with enhanced AVX512 flags (AVX512_BF16, AVX512_VNNI, AVX512_VBMI) with clang-cl and Visual Studio Generator
- **Issue :** While trying to build with clang-cl and Visual Studio Generator, while trying to enable to AVX512_VBMI, AVX512_VNNI and AVX512_BF16 flags got the following error
![image](https://github.com/user-attachments/assets/4327eb20-b830-4a18-bf28-7c0d4fa4981d)
![image](https://github.com/user-attachments/assets/00ae45bc-58e7-43bd-82f2-35ef2deb671f)

**Fix :** Requires -mavx512vnni, -mavx512vbmi and -mavx512bf16 as part of compile options

Also,

- Experiments were conducted to test llama.cpp with MSVC (Visual Studio Generator), Clang (Ninja) and Clang-Cl (Visual Studio Generator) and to compare the performance
- Improvements were seen with the usage of Clang-Cl(VS Generator) and Clang (Ninja Generator) over MSVC Compiler
- Both the ninja dependencies and clang dependencies were part of the Visual Studio Installations

**Visual Studio Generator, Clang-Cl (17.0.3) - For which fixes are given**

- For building with Visual Studio Generator, Clang-Cl is obtained from the Visual Studio Installations Path : C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin
- CMAKE Command : cmake -G "Visual Studio 17 2022" -T ClangCL -A x64 -S . -B build -DCMAKE_BUILD_TYPE=Release -DGGML_AVX512_VBMI=ON -DGGML_AVX512_VNNI=ON -DGGML_AVX512_BF16=ON

**Ninja Generator, Clang.exe/Clang++.exe (17.0.3)**

- Clang.exe and clang++.exe are obtained from the same path as clang-cl - C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin
- CMAKE Command : cmake -G "Ninja" -S . -B Windows-build/ -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang.exe -DCMAKE_CXX_COMPILER=clang++.exe
- Ninja path : C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe and version (1.11.0)
- Additional library depedencies are resolved with : set LIB=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\um\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\lib\x64\uwp;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\ucrt\x64 before cmake and build

Both the clang builds are done without the openmp dependencies

The tests were conducted in AMD Raphael 7600X which supports the following flags (The same were kept on in our windows tests) : 
AVX = 1 | AVX_VNNI = 0 | AVX2 = 1 | AVX512 = 1 | AVX512_VBMI = 1 | AVX512_VNNI = 1 | AVX512_BF16 = 1 | FMA = 1 | NEON = 0 | SVE = 0 | ARM_FMA = 0 | F16C = 1 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 0 | SSE3 = 1 | SSSE3 = 1 | VSX = 0 | MATMUL_INT8 = 0 | LLAMAFILE = 1|

**Prompt Processing** 

| model| Compiler/Generator| size| params | backend | threads | test | t/s | speedup | Commit id |
| ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- |------------- | ------------- | ------------- |
| llama 7B Q4_0 | MSVC Compiler/ VS Generator | 3.56 GiB | 6.74 B | CPU | 6 | pp 512 |  48.14  ±  0.67 | | [231f936](https://github.com/ggerganov/llama.cpp/commit/231f9360d94446cd083b6b116f63991b1328c484) |
| llama 7B Q4_0 | clang-cl.exe/ VS Generator | 3.56 GiB | 6.74 B | CPU | 6 | pp 512 |  50.23 ± 0.91 | 4.33% | [231f936](https://github.com/ggerganov/llama.cpp/commit/231f9360d94446cd083b6b116f63991b1328c484)  |
| llama 7B Q4_0 | clang.exe/ Ninja Generator  | 3.56 GiB | 6.74 B | CPU | 6 | pp 512 | 55.69 ± 0.71 | 15.68% | [231f936](https://github.com/ggerganov/llama.cpp/commit/231f9360d94446cd083b6b116f63991b1328c484) |

**Text Generation** 

| model| Compiler/Generator| size| params | backend | threads | test | t/s | speedup | Commit id |
| ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- |------------- | ------------- | ------------- |
| llama 7B Q4_0 | MSVC Compiler/ VS Generator | 3.56 GiB | 6.74 B | CPU | 6 | tg 128 |  14.8 ± 0.01 | | [231f936](https://github.com/ggerganov/llama.cpp/commit/231f9360d94446cd083b6b116f63991b1328c484) |
| llama 7B Q4_0 | clang-cl.exe/ VS Generator | 3.56 GiB | 6.74 B | CPU | 6 | tg 128 |  14.95 ± 0.02 | 1.00% | [231f936](https://github.com/ggerganov/llama.cpp/commit/231f9360d94446cd083b6b116f63991b1328c484)  |
| llama 7B Q4_0 | clang.exe/ Ninja Generator | 3.56 GiB | 6.74 B | CPU | 6 | tg 128 | 14.95 ± 0.02 | 1.00% | [231f936](https://github.com/ggerganov/llama.cpp/commit/231f9360d94446cd083b6b116f63991b1328c484) |

Tests done with [Meta Llama2 7B model](https://huggingface.co/meta-llama/Llama-2-7b) 

Having a clang windows build (especially with the Ninja Generator) as part of the release could help windows users. Authors/Maintainers of llama.cpp, could you please share your thoughts on the same? Thanks




- [x] I have read the [contributing guidelines](https://github.com/ggerganov/llama.cpp/blob/master/CONTRIBUTING.md)
- Self-reported review complexity:
  - [x] Low
  - [ ] Medium
  - [ ] High


Changed files:
filename: ggml/src/ggml-cpu/CMakeLists.txt
patch: @@ -143,14 +143,23 @@ elseif (CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64" OR CMAKE_GENERATOR_PLATFORM_LW
             if (GGML_AVX512_VBMI)
                 add_compile_definitions($<$<COMPILE_LANGUAGE:C>:__AVX512VBMI__>)
                 add_compile_definitions($<$<COMPILE_LANGUAGE:CXX>:__AVX512VBMI__>)
+                if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
+                    list(APPEND ARCH_FLAGS -mavx512vbmi)
+                endif()
             endif()
             if (GGML_AVX512_VNNI)
                 add_compile_definitions($<$<COMPILE_LANGUAGE:C>:__AVX512VNNI__>)
                 add_compile_definitions($<$<COMPILE_LANGUAGE:CXX>:__AVX512VNNI__>)
+                if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
+                    list(APPEND ARCH_FLAGS -mavx512vnni)
+                endif()
             endif()
             if (GGML_AVX512_BF16)
                 add_compile_definitions($<$<COMPILE_LANGUAGE:C>:__AVX512BF16__>)
                 add_compile_definitions($<$<COMPILE_LANGUAGE:CXX>:__AVX512BF16__>)
+                if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
+                    list(APPEND ARCH_FLAGS -mavx512bf16)
+                endif()
             endif()
             if (GGML_AMX_TILE)
                 add_compile_definitions($<$<COMPILE_LANGUAGE:C>:__AMX_TILE__>)