llama.cpp: Compilation failed on macOS 10.7-8-9: 'clock_gettime' produce warnings and errors

PREREQUISITES

EXPECTED BEHAVIOR

  • Attempted to compile the binary for macOS 10.7, 10.8 and 10.9.
  • Expected to run the chat app on an old macOS, that will be isolated from Internet.

ACTUAL BEHAVIOR

  • Compilation is terminated with warnings and errors.

ENVIRONMENT AND CONTEXT

  • Macbook pro 15 2012: macOS 10.8 Mountain Lion on Core i7 + 512 SDD + 16Gb RAM
    • Parallels Virtual Machine: macOS 10.7 Lion on 20Gb HDD + 4Gb RAM
      • X-Code 4.6.3
      • Command Line Tools OS X Lion Nov2012
      • MacPorts 2.8.1 10.7 (Lion)
        • git --version 2.40.0
        • clang --version 11.1.0
          • port select --set clang mp-clang-11
        • gcc --version 12.2.0
          • port select --set gcc mp-gcc12
      • export CC=gcc (in another re-try: export CC=clang)
      • export CXX=gcc (in another re-try: export CXX=clang)

FAILURE INFORMATION

  • Same issue is reproduced on macOS 10.8 on VM and macOS 10.9 on real machine.
  • Same issue is reproduced with gcc6 installed through Tigerbrew on macOS 10.9 real machine.
  • Same issue is reproduced for ‘alpaca.cpp’: ‘clock_gettime’ produce mostly the same warnings and errors on this environment.
  • ‘stdatomic.h’ issue is reproduced if latest gcc and clang versions are not set in ports and also CC and CXX vars are not set
  • ‘-gnu11’, ‘-lrt’ and ‘-D_POSIX_C_SOURCE=199309L’ flags doesn’t help, ‘-gnu99’ gives more errors
  • Compilation successful on macOS 10.14 (Mojave) VM with Command Line Tools for Xcode 11.3.1. Chat + 7b is working.
  • Fix on this issue states that older OSX versions don’t implement ‘clock_gettime ()’ and author seem to find solution

STEPS TO REPRODUCE

  1. Clone the repo (or download the latest build and un-tar gz using tar -xvzf)
  2. cd the llama.cpp dir (or rename the latest build dir to ‘llama.cpp’ and cd there)
  3. make

FAILURE LOGS

CC=gcc and CXX=gcc env vars set:

I llama.cpp build info: 
I UNAME_S:  Darwin
I UNAME_P:  i386
I UNAME_M:  x86_64
I CFLAGS:   -I.              -O3 -DNDEBUG -std=c11   -fPIC -Wall -Wextra -Wpedantic -Wcast-qual -Wdouble-promotion -Wshadow -Wstrict-prototypes -Wpointer-arith -Wno-unused-function -pthread -march=native -mtune=native -DGGML_USE_ACCELERATE
I CXXFLAGS: -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -pthread -march=native -mtune=native
I LDFLAGS:   -framework Accelerate
I CC:       gcc (MacPorts gcc12 12.2.0_2+stdlib_flag) 12.2.0
I CXX:      gcc (MacPorts gcc12 12.2.0_2+stdlib_flag) 12.2.0

gcc  -I.              -O3 -DNDEBUG -std=c11   -fPIC -Wall -Wextra -Wpedantic -Wcast-qual -Wdouble-promotion -Wshadow -Wstrict-prototypes -Wpointer-arith -Wno-unused-function -pthread -march=native -mtune=native -DGGML_USE_ACCELERATE   -c ggml.c -o ggml.o
ggml.c: In function 'ggml_time_ms':
ggml.c:376:5: warning: implicit declaration of function 'clock_gettime' [-Wimplicit-function-declaration]
  376 |     clock_gettime(CLOCK_MONOTONIC, &ts);
      |     ^~~~~~~~~~~~~
ggml.c:376:19: error: 'CLOCK_MONOTONIC' undeclared (first use in this function)
  376 |     clock_gettime(CLOCK_MONOTONIC, &ts);
      |                   ^~~~~~~~~~~~~~~
ggml.c:376:19: note: each undeclared identifier is reported only once for each function it appears in
ggml.c: In function 'ggml_time_us':
ggml.c:382:19: error: 'CLOCK_MONOTONIC' undeclared (first use in this function)
  382 |     clock_gettime(CLOCK_MONOTONIC, &ts);
      |                   ^~~~~~~~~~~~~~~
ggml.c: In function 'quantize_row_q4_1':
ggml.c:856:27: warning: unused variable 'y' [-Wunused-variable]
  856 |     block_q4_1 * restrict y = vy;
      |                           ^
ggml.c:854:15: warning: unused variable 'nb' [-Wunused-variable]
  854 |     const int nb = k / QK;
      |               ^~
ggml.c: In function 'ggml_vec_sum_f32':
ggml.c:2531:14: warning: passing argument 1 of 'vDSP_sve' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
 2531 |     vDSP_sve(x, 1, s, n);
      |              ^
In file included from /System/Library/Frameworks/vecLib.framework/Headers/vecLib.h:41,
                 from /System/Library/Frameworks/Accelerate.framework/Headers/Accelerate.h:20,
                 from ggml.c:143:
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:4191:17: note: expected 'float *' but argument is of type 'const float *'
 4191 |   float *       __vDSP_A,
      |   ~~~~~~~~~~~~~~^~~~~~~~
ggml.c: In function 'ggml_vec_max_f32':
ggml.c:2543:15: warning: passing argument 1 of 'vDSP_maxv' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
 2543 |     vDSP_maxv(x, 1, s, n);
      |               ^
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:3625:17: note: expected 'float *' but argument is of type 'const float *'
 3625 |   float *       __vDSP_A,
      |   ~~~~~~~~~~~~~~^~~~~~~~
make: *** [ggml.o] Error 1

CC=clang and CXX=clang env vars set:

I llama.cpp build info: 
I UNAME_S:  Darwin
I UNAME_P:  i386
I UNAME_M:  x86_64
I CFLAGS:   -I.              -O3 -DNDEBUG -std=c11   -fPIC -Wall -Wextra -Wpedantic -Wcast-qual -Wdouble-promotion -Wshadow -Wstrict-prototypes -Wpointer-arith -Wno-unused-function -pthread -march=native -mtune=native -DGGML_USE_ACCELERATE
I CXXFLAGS: -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -pthread -march=native -mtune=native
I LDFLAGS:   -framework Accelerate
I CC:       clang version 11.1.0
I CXX:      clang version 11.1.0

clang  -I.              -O3 -DNDEBUG -std=c11   -fPIC -Wall -Wextra -Wpedantic -Wcast-qual -Wdouble-promotion -Wshadow -Wstrict-prototypes -Wpointer-arith -Wno-unused-function -pthread -march=native -mtune=native -DGGML_USE_ACCELERATE   -c ggml.c -o ggml.o
ggml.c:376:5: warning: implicit declaration of function 'clock_gettime' is invalid in C99 [-Wimplicit-function-declaration]
    clock_gettime(CLOCK_MONOTONIC, &ts);
    ^
ggml.c:376:19: error: use of undeclared identifier 'CLOCK_MONOTONIC'
    clock_gettime(CLOCK_MONOTONIC, &ts);
                  ^
ggml.c:382:5: warning: implicit declaration of function 'clock_gettime' is invalid in C99 [-Wimplicit-function-declaration]
    clock_gettime(CLOCK_MONOTONIC, &ts);
    ^
ggml.c:382:19: error: use of undeclared identifier 'CLOCK_MONOTONIC'
    clock_gettime(CLOCK_MONOTONIC, &ts);
                  ^
ggml.c:854:15: warning: unused variable 'nb' [-Wunused-variable]
    const int nb = k / QK;
              ^
ggml.c:856:27: warning: unused variable 'y' [-Wunused-variable]
    block_q4_1 * restrict y = vy;
                          ^
ggml.c:1813:5: warning: implicit conversion increases floating-point precision: 'float' to 'ggml_float' (aka 'double') [-Wdouble-promotion]
    GGML_F16_VEC_REDUCE(sumf, sum);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ggml.c:1427:37: note: expanded from macro 'GGML_F16_VEC_REDUCE'
#define GGML_F16_VEC_REDUCE         GGML_F32Cx8_REDUCE
                                    ^
ggml.c:1417:33: note: expanded from macro 'GGML_F32Cx8_REDUCE'
#define GGML_F32Cx8_REDUCE      GGML_F32x8_REDUCE
                                ^
ggml.c:1364:11: note: expanded from macro 'GGML_F32x8_REDUCE'
    res = _mm_cvtss_f32(_mm_hadd_ps(t1, t1));                     \
        ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ggml.c:2372:9: warning: implicit conversion increases floating-point precision: 'float' to 'ggml_float' (aka 'double') [-Wdouble-promotion]
        GGML_F16_VEC_REDUCE(sumf[k], sum[k]);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ggml.c:1427:37: note: expanded from macro 'GGML_F16_VEC_REDUCE'
#define GGML_F16_VEC_REDUCE         GGML_F32Cx8_REDUCE
                                    ^
ggml.c:1417:33: note: expanded from macro 'GGML_F32Cx8_REDUCE'
#define GGML_F32Cx8_REDUCE      GGML_F32x8_REDUCE
                                ^
ggml.c:1364:11: note: expanded from macro 'GGML_F32x8_REDUCE'
    res = _mm_cvtss_f32(_mm_hadd_ps(t1, t1));                     \
        ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ggml.c:2531:14: warning: passing 'const float *' to parameter of type 'float *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
    vDSP_sve(x, 1, s, n);
             ^
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:4191:17: note: passing argument to parameter '__vDSP_A' here
  float *       __vDSP_A,
                ^
ggml.c:2543:15: warning: passing 'const float *' to parameter of type 'float *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
    vDSP_maxv(x, 1, s, n);
              ^
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:3625:17: note: passing argument to parameter '__vDSP_A' here
  float *       __vDSP_A,
                ^
8 warnings and 2 errors generated.
make: *** [ggml.o] Error 1

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 20 (3 by maintainers)

Most upvoted comments

I have also compiled alpaca.cpp for macOS 10.7 and looks like it is working on real machine with macOS 10.8:

main: seed = 1680900951
llama_model_load: loading model from 'ggml-alpaca-7b-q4.bin' - please wait ...
llama_model_load: ggml ctx size = 6065.34 MB
llama_model_load: memory_size =  2048.00 MB, n_mem = 65536
llama_model_load: loading model part 1/1 from 'ggml-alpaca-7b-q4.bin'
llama_model_load: .................................... done
llama_model_load: model size =  4017.27 MB / num tensors = 291

system_info: n_threads = 4 / 8 | AVX = 1 | AVX2 = 0 | AVX512 = 0 | FMA = 0 | NEON = 0 | ARM_FMA = 0 | F16C = 1 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 1 | VSX = 0 | 
main: interactive mode on.
sampling parameters: temp = 0.100000, top_k = 40, top_p = 0.950000, repeat_last_n = 64, repeat_penalty = 1.300000


== Running in chat mode. ==
 - Press Ctrl+C to interject at any time.
 - Press Return to return control to LLaMA.
 - If you want to submit another line, end your input in '\'.

> Hello!                                
Welcome!
> I have compiled the version of this chat model for my old mac and I can talk to you at last!
That sounds great. We are looking forward to chatting with you soon :)

…I love this ‘We are’ 😃

Haven’t tried configuring it yet, but at least - it is compiled successfully and running. Now I’m planning to investigate the whole environment setup and find the minimum configuration to compile on these old OS. Let me know if it will be useful to share this info.

Thank you all very much for helping me out!

I wouldn’t worry too much about those if it works ok!

As far as I can tell, the only consequence will be that the time values that will be printed out will all be 0. Feel free to open a PR adding an alternate timing mechanism that can be used if the more accurate one is unavailable?