]> git.djapps.eu Git - pkg/ggml/sources/ggml/commitdiff
cmake : fix MSVC build (#479)
authorCebtenzzre <redacted>
Mon, 28 Aug 2023 11:36:16 +0000 (07:36 -0400)
committerGitHub <redacted>
Mon, 28 Aug 2023 11:36:16 +0000 (14:36 +0300)
* examples : fix use of M_PI on MSVC

* cmake : make -Werror=vla global

* tests : fix CPU feature options on MSVC

* tests : fix __m256 casts on MSVC

CMakeLists.txt
examples/common.cpp
examples/sam/main.cpp
src/CMakeLists.txt
tests/CMakeLists.txt
tests/test-mul-mat2.c

index 228d863a7da155ae3f370972b112d320242fa980..155e3d394e99333452f9652406b8ce257bc34e88 100644 (file)
@@ -67,6 +67,12 @@ endif()
 #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
 #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=native")
 
+# warning flags
+
+if (NOT MSVC)
+    add_compile_options(-Werror=vla)
+endif()
+
 # dependencies
 
 set(CMAKE_C_STANDARD   11)
index 8a3b00cfa4236277bd06792a87ee0c8f1fde02e4..2b8da8f734219bc72f7ac0921d6c97dc8f1c7cd7 100644 (file)
@@ -1,3 +1,5 @@
+#define _USE_MATH_DEFINES // for M_PI
+
 #include "common.h"
 
 // third-party utilities
 #include <codecvt>
 #include <sstream>
 
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
 #if defined(_MSC_VER)
 #pragma warning(disable: 4244 4267) // possible loss of data
 #endif
index 99b039b5624fc1f9d48bb31da97c73be05c8c4c6..c1fff545bc9d15f88c9089f01de5f9cd095b34b7 100644 (file)
@@ -1,3 +1,5 @@
+#define _USE_MATH_DEFINES // for M_PI
+
 #include "ggml.h"
 
 #include "common.h"
index 3292bc85897a93d6f62d3d2320a56f9a10cea3a8..b329c08e27e9164dced721327e73fb2587c674ac 100644 (file)
@@ -21,7 +21,6 @@ endif()
 # compiler flags
 
 if (NOT MSVC)
-    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=vla")
     #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-math-errno -ffinite-math-only -funsafe-math-optimizations")
 endif()
 
index 8d9d1f79b8a8314eb2cbaebd6e58b4b30eb4153c..b31079b5c5b131b1b84855351c040d3dddf06598 100644 (file)
@@ -86,6 +86,24 @@ else()
         if (F16C_M MATCHES "f16c")
             set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mf16c")
         endif()
+    elseif (MSVC)
+        if (GGML_AVX512)
+            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX512")
+            # MSVC has no compile-time flags enabling specific
+            # AVX512 extensions, neither it defines the
+            # macros corresponding to the extensions.
+            # Do it manually.
+            if (GGML_AVX512_VBMI)
+                add_compile_definitions(__AVX512VBMI__)
+            endif()
+            if (GGML_AVX512_VNNI)
+                add_compile_definitions(__AVX512VNNI__)
+            endif()
+        elseif (GGML_AVX2)
+            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX2")
+        elseif (GGML_AVX)
+            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX")
+        endif()
     else()
         set(CMAKE_C_FLAGS  "${CMAKE_C_FLAGS} -mfma -mf16c -mavx -mavx2")
     endif()
index ad30492b478f27115d82c83f27b50f145688d2a9..944c48e9b7c351be9492bb46b7fb29e154968530 100644 (file)
@@ -1062,7 +1062,7 @@ void quantize_4_row(const float * restrict src, void * restrict dst, int k) {
 #if defined(__AVX2__)
         {
             assert(QK == 64);
-            const int QK8 = QK/8;
+            enum { QK8 = QK/8 };
 
             __m256 srcv[QK8];
             __m256 minv[QK8];
@@ -1647,7 +1647,7 @@ void quantize_5_row(const float * restrict src, void * restrict dst, int k) {
 #if defined(__AVX2__)
         {
             assert(QK == 64);
-            const int QK8 = QK/8;
+            enum { QK8 = QK/8 };
 
             __m256 srcv [QK8];
             __m256 asrcv[QK8];
@@ -1658,7 +1658,7 @@ void quantize_5_row(const float * restrict src, void * restrict dst, int k) {
             }
 
             for (int l = 0; l < QK8; l++) {
-                asrcv[l] = _mm256_and_ps(srcv[l], (__m256) _mm256_set1_epi32(0x7fffffff));
+                asrcv[l] = _mm256_and_ps(srcv[l], _mm256_castsi256_ps(_mm256_set1_epi32(0x7fffffff)));
             }
 
 
@@ -2035,7 +2035,7 @@ void quantize_6_row(const float * restrict src, void * restrict dst, int k) {
 
 #if defined(__AVX2__)
         {
-            const int QK8 = 4;
+            enum { QK8 = 4 };
 
             __m256 srcv [QK8];
             __m256 asrcv[QK8];
@@ -2046,7 +2046,7 @@ void quantize_6_row(const float * restrict src, void * restrict dst, int k) {
             }
 
             for (int l = 0; l < QK8; l++) {
-                asrcv[l] = _mm256_and_ps(srcv[l], (__m256) _mm256_set1_epi32(0x7fffffff));
+                asrcv[l] = _mm256_and_ps(srcv[l], _mm256_castsi256_ps(_mm256_set1_epi32(0x7fffffff)));
             }
 
             for (int l = 0; l < QK8/2; l++) {