llama.cpp icon indicating copy to clipboard operation
llama.cpp copied to clipboard

make is error ( k_quants.c)

Open zhp8341 opened this issue 2 years ago • 2 comments

llama.cpp$ make

I llama.cpp build info: I UNAME_S: Linux I UNAME_P: x86_64 I UNAME_M: x86_64 I CFLAGS: -I. -O3 -std=c11 -fPIC -DNDEBUG -Wall -Wextra -Wpedantic -Wcast-qual -Wdouble-promotion -Wshadow -Wstrict-prototypes -Wpointer-arith -pthread -march=native -mtune=native -DGGML_USE_K_QUANTS I CXXFLAGS: -I. -I./examples -O3 -std=c++11 -fPIC -DNDEBUG -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wno-multichar -pthread -march=native -mtune=native -DGGML_USE_K_QUANTS I LDFLAGS:
I CC: cc (Ubuntu 7.5.0-3ubuntu1~16.04) 7.5.0 I CXX: g++ (Ubuntu 7.5.0-3ubuntu1~16.04) 7.5.0

cc -I. -O3 -std=c11 -fPIC -DNDEBUG -Wall -Wextra -Wpedantic -Wcast-qual -Wdouble-promotion -Wshadow -Wstrict-prototypes -Wpointer-arith -pthread -march=native -mtune=native -DGGML_USE_K_QUANTS -c -o k_quants.o k_quants.c k_quants.c: In function ‘ggml_vec_dot_q2_K_q8_K’: k_quants.c:1121:36: warning: implicit declaration of function ‘_mm256_set_m128i’; did you mean ‘_mm256_set_epi8’? [-Wimplicit-function-declaration] const __m256i scales[2] = {_mm256_set_m128i(l_scales, l_scales), _mm256_set_m128i(h_scales, h_scales)}; ^~~~~~~~~~~~~~~~ _mm256_set_epi8 k_quants.c:1121:35: warning: missing braces around initializer [-Wmissing-braces] const __m256i scales[2] = {_mm256_set_m128i(l_scales, l_scales), _mm256_set_m128i(h_scales, h_scales)}; ^ { } k_quants.c: In function ‘ggml_vec_dot_q3_K_q8_K’: k_quants.c:1361:35: warning: missing braces around initializer [-Wmissing-braces] const __m256i scales[2] = {_mm256_set_m128i(l_scales, l_scales), _mm256_set_m128i(h_scales, h_scales)}; ^ { } k_quants.c: In function ‘ggml_vec_dot_q4_K_q8_K’: k_quants.c:1635:32: error: incompatible types when initializing type ‘__m256i {aka const __vector(4) long long int}’ using type ‘int’ const __m256i scales = _mm256_set_m128i(sc128, sc128); ^~~~~~~~~~~~~~~~ k_quants.c: In function ‘ggml_vec_dot_q5_K_q8_K’: k_quants.c:1865:32: error: incompatible types when initializing type ‘__m256i {aka const __vector(4) long long int}’ using type ‘int’ const __m256i scales = _mm256_set_m128i(sc128, sc128); ^~~~~~~~~~~~~~~~ : recipe for target 'k_quants.o' failed make: *** [k_quants.o] Error 1

zhp8341 avatar Jun 18 '23 14:06 zhp8341

try upgrading gcc/g++ https://github.com/ggerganov/whisper.cpp/issues/851#issuecomment-1550343987

hbf731eF avatar Jun 19 '23 12:06 hbf731eF

-march=native is not detecting the right CPU instructions to use. Use CMake for better control over the configuration or update the compiler, which may help or not, depending on the OS, etc.

SlyEcho avatar Jun 19 '23 13:06 SlyEcho

Did you manage to get it to work?

irajmoradi avatar Jun 27 '23 01:06 irajmoradi

My pal GPT says the following works too if your intrinsics library does not contain _mm256_set_m128i; just add an alternative implementation to the top of the k_quants.c file and rename the references.

static inline __m256i my_mm256_set_m128i(__m128i hi, __m128i lo) {
    __m256i val = _mm256_castsi128_si256(lo);
    val = _mm256_insertf128_si256(val, hi, 1);
    return val;
}

then replace calls to _mm256_set_m128i with my_mm256_set_m128i

This let me compile and run on an old version of Debian with GCC-7.5.

alecGraves avatar Jun 29 '23 03:06 alecGraves

My pal GPT says the following works too if your intrinsics library does not contain _mm256_set_m128i; just add an alternative implementation to the top of the k_quants.c file and rename the references.

static inline __m256i my_mm256_set_m128i(__m128i hi, __m128i lo) {
    __m256i val = _mm256_castsi128_si256(lo);
    val = _mm256_insertf128_si256(val, hi, 1);
    return val;
}

then replace calls to _mm256_set_m128i with my_mm256_set_m128i

This let me compile and run on an old version of Debian with GCC-7.5.

It works, thanks.

22dimensions avatar Jul 04 '23 03:07 22dimensions

You could also modify the code, adding a check for gcc versions

#include <immintrin.h>
#if <gcc version lt 8?>
static inline __m256i __mm256_set_m128i(__m128i hi, __m128i lo) {
    __m256i val = _mm256_castsi128_si256(lo);
    val = _mm256_insertf128_si256(val, hi, 1);
    return val;
}
#endif

alecGraves avatar Jul 09 '23 21:07 alecGraves

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Apr 10 '24 01:04 github-actions[bot]