BitNet icon indicating copy to clipboard operation
BitNet copied to clipboard

Compiler error

Open brmarkus opened this issue 10 months ago • 8 comments

Under Ubuntu LTS 24.04.3 I got the following compiler error:

/BitNet/src/ggml-bitnet-mad.cpp:811:18: error: cannot initialize a variable of type 'int8_t *' (aka 'signed char *') with an rvalue of type 'const int8_t *' (aka 'const signed char *')
  811 |         int8_t * y_col = y + col * by;
      |                  ^       ~~~~~~~~~~~~

Using CLANG in v18.1.3 and CMAKE in v3.28.3 and GCC/G++ in v13.3.0 and Python in v3.12.3.

Needed to add "const": 811 | const int8_t * y_col = y + col * by;

brmarkus avatar Feb 03 '26 08:02 brmarkus

Why hasn't this been patched already, just had the same issue.

samcharles93 avatar Feb 17 '26 10:02 samcharles93

Hi maintainers,

I opened PR #418 with a fix for the const-correctness compiler error reported here: https://github.com/microsoft/BitNet/pull/418

Could I please get a review? Thank you.

darsh7807 avatar Mar 08 '26 22:03 darsh7807

Just faced this issue 2 weeks later on Windows 11. Applied @darsh7807 PR and got a little further.

Got another issue.

python setup_env.py -md models/BitNet-b1.58-2B-4T -q i2_spwsh at 11:56:47
INFO:root:Compiling the code using CMake.
ERROR:root:Error occurred while running command: Command '['cmake', '--build', 'build', '--config', 'Release']' returned non-zero exit status 1., check details in logs\compile.log
E:\development\temp\BitNet\3rdparty\llama.cpp\common\common.cpp(445,32): error : no type named 'system_clock' in namespace 'std::chrono' [E:\development\temp\BitNet\build\3rdparty\llama.cpp\common\common.vcxproj]
E:\development\temp\BitNet\3rdparty\llama.cpp\common\common.cpp(447,11): error : 'clock' is not a class, namespace, or enumeration [E:\development\temp\BitNet\build\3rdparty\llama.cpp\common\common.vcxproj]
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\time.h(144,26): message : 'clock' declared here [E:\development\temp\BitNet\build\3rdparty\llama.cpp\common\common.vcxproj]
E:\development\temp\BitNet\3rdparty\llama.cpp\common\common.cpp(447,44): error : 'clock' is not a class, namespace, or enumeration [E:\development\temp\BitNet\build\3rdparty\llama.cpp\common\common.vcxproj]
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\time.h(144,26): message : 'clock' declared here [E:\development\temp\BitNet\build\3rdparty\llama.cpp\common\common.vcxproj]
E:\development\temp\BitNet\3rdparty\llama.cpp\common\common.cpp(448,30): error : 'clock' is not a class, namespace, or enumeration [E:\development\temp\BitNet\build\3rdparty\llama.cpp\common\common.vcxproj]

compile.log

darkedges avatar Mar 22 '26 01:03 darkedges

@darkedges it was due to the missing of "#include chrono".

These two PR will solve, I believe: #494 #446

wrenevens avatar Mar 29 '26 16:03 wrenevens

"cat logs/generate_build_files.log

-- Found OpenMP_C: -fopenmp=libomp (found version "5.1")

-- Found OpenMP_CXX: -fopenmp=libomp (found version "5.1")

-- Found OpenMP: TRUE (found version "5.1")

-- OpenMP found

-- Using llamafile

-- Warning: ccache not found - consider installing it for faster compilation or disable this warning with GGML_CCACHE=OFF

-- CMAKE_SYSTEM_PROCESSOR: x86_64

-- x86 detected

-- Configuring done (0.7s)

-- Generating done (0.0s)

-- Build files have been written to: /////BitNet/build" but "cat logs/compile.log

[ 1%] Building C object 3rdparty/llama.cpp/ggml/src/CMakeFiles/ggml.dir/ggml.c.o

In file included from /////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:7:

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml-quants.h:156:7: warning: no newline at end of file [-Wnewline-eof]

156 | #endif

  |       ^

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:1184:37: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]

1184 | .nrows = 1,

  |                                     ^

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:1181:37: note: previous initialization is here

1181 | .nrows = 1,

  |                                     ^

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:12543:6: warning: no previous prototype for function 'float_act_quant' [-Wmissing-prototypes]

12543 | void float_act_quant(const int K, float* B, int32_t* dst, float* act_scale) {

   |      ^

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:12543:1: note: declare 'static' if the function is not intended to be used outside of this translation unit

12543 | void float_act_quant(const int K, float* B, int32_t* dst, float* act_scale) {

   | ^

   | static 

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:12563:18: warning: implicit conversion increases floating-point precision: 'float' to 'double' [-Wdouble-promotion]

12563 | if (fabs(A[i]) > max){

   |             ~~~~ ^~~~

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:12564:32: warning: implicit conversion increases floating-point precision: 'float' to 'double' [-Wdouble-promotion]

12564 | i2_scale[0] = fabs(A[i]);

   |                           ~~~~ ^~~~

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:12574:37: warning: implicit conversion increases floating-point precision: 'float' to 'double' [-Wdouble-promotion]

12574 | dst[i] = (double)A[i] * i2_scale[0] > 0 ? 1 : -1;

   |                                   ~ ^~~~~~~~~~~

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:12559:6: warning: no previous prototype for function 'weight_quant_f32' [-Wmissing-prototypes]

12559 | void weight_quant_f32(const int M, const int K, float* A, int32_t* dst, float* i2_scale) {

   |      ^

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:12559:1: note: declare 'static' if the function is not intended to be used outside of this translation unit

12559 | void weight_quant_f32(const int M, const int K, float* A, int32_t* dst, float* i2_scale) {

   | ^

   | static 

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:12583:18: warning: implicit conversion increases floating-point precision: 'float' to 'double' [-Wdouble-promotion]

12583 | if (fabs(temp_A) > max){

   |             ~~~~ ^~~~~~

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:12584:32: warning: implicit conversion increases floating-point precision: 'float' to 'double' [-Wdouble-promotion]

12584 | i2_scale[0] = fabs(temp_A);

   |                           ~~~~ ^~~~~~

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:12595:39: warning: implicit conversion increases floating-point precision: 'float' to 'double' [-Wdouble-promotion]

12595 | dst[i] = (double)temp_A * i2_scale[0] > 0 ? 1 : -1;

   |                                     ~ ^~~~~~~~~~~

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:12579:6: warning: no previous prototype for function 'weight_quant_f16' [-Wmissing-prototypes]

12579 | void weight_quant_f16(const int M, const int K, uint16_t* A, int32_t* dst, float* i2_scale) {

   |      ^

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:12579:1: note: declare 'static' if the function is not intended to be used outside of this translation unit

12579 | void weight_quant_f16(const int M, const int K, uint16_t* A, int32_t* dst, float* i2_scale) {

   | ^

   | static 

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:12600:6: warning: no previous prototype for function 'matrixMultiply_int' [-Wmissing-prototypes]

12600 | void matrixMultiply_int(const int M, const int N, const int K, const int32_t* A, const int32_t* B, int32_t* C) {

   |      ^

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:12600:1: note: declare 'static' if the function is not intended to be used outside of this translation unit

12600 | void matrixMultiply_int(const int M, const int N, const int K, const int32_t* A, const int32_t* B, int32_t* C) {

   | ^

   | static 

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:14291:48: warning: passing 'const struct ggml_compute_params *' to parameter of type 'struct ggml_compute_params *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]

14291 | ggml_compute_forward_get_rows_i2_s(params, dst);

   |                                                ^~~~~~

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml.c:14073:42: note: passing argument to parameter 'params' here

14073 | struct ggml_compute_params * params,

   |                                          ^

13 warnings generated.

[ 2%] Building C object 3rdparty/llama.cpp/ggml/src/CMakeFiles/ggml.dir/ggml-alloc.c.o

[ 2%] Building CXX object 3rdparty/llama.cpp/ggml/src/CMakeFiles/ggml.dir/ggml-backend.cpp.o

[ 3%] Building C object 3rdparty/llama.cpp/ggml/src/CMakeFiles/ggml.dir/ggml-quants.c.o

In file included from /////BitNet/3rdparty/llama.cpp/ggml/src/ggml-quants.c:4:

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml-quants.h:156:7: warning: no newline at end of file [-Wnewline-eof]

156 | #endif

  |       ^

/////BitNet/3rdparty/llama.cpp/ggml/src/ggml-quants.c:16179:2: warning: no newline at end of file [-Wnewline-eof]

16179 | }

   |  ^

2 warnings generated.

[ 4%] Building CXX object 3rdparty/llama.cpp/ggml/src/CMakeFiles/ggml.dir/////src/ggml-bitnet-mad.cpp.o

In file included from /////BitNet/src/ggml-bitnet-mad.cpp:5:

In file included from /////BitNet/3rdparty/llama.cpp/ggml/src/./ggml-quants.h:4:

/////BitNet/3rdparty/llama.cpp/ggml/src/./ggml-common.h:154:9: warning: anonymous structs are a GNU extension [-Wgnu-anonymous-struct]

154 | struct {

  |         ^

/////BitNet/3rdparty/llama.cpp/ggml/src/./ggml-common.h:154:9: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]

/////BitNet/3rdparty/llama.cpp/ggml/src/./ggml-common.h:175:9: warning: anonymous structs are a GNU extension [-Wgnu-anonymous-struct]

175 | struct {

  |         ^

/////BitNet/3rdparty/llama.cpp/ggml/src/./ggml-common.h:175:9: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]

/////BitNet/3rdparty/llama.cpp/ggml/src/./ggml-common.h:196:9: warning: anonymous structs are a GNU extension [-Wgnu-anonymous-struct]

196 | struct {

  |         ^

/////BitNet/3rdparty/llama.cpp/ggml/src/./ggml-common.h:196:9: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]

/////BitNet/3rdparty/llama.cpp/ggml/src/./ggml-common.h:261:9: warning: anonymous structs are a GNU extension [-Wgnu-anonymous-struct]

261 | struct {

  |         ^

/////BitNet/3rdparty/llama.cpp/ggml/src/./ggml-common.h:261:9: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]

/////BitNet/3rdparty/llama.cpp/ggml/src/./ggml-common.h:294:9: warning: anonymous structs are a GNU extension [-Wgnu-anonymous-struct]

294 | struct {

  |         ^

/////BitNet/3rdparty/llama.cpp/ggml/src/./ggml-common.h:294:9: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]

/////BitNet/3rdparty/llama.cpp/ggml/src/./ggml-common.h:311:9: warning: anonymous structs are a GNU extension [-Wgnu-anonymous-struct]

311 | struct {

  |         ^

/////BitNet/3rdparty/llama.cpp/ggml/src/./ggml-common.h:311:9: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]

/////BitNet/src/ggml-bitnet-mad.cpp:51:100: warning: unused parameter 'quant_weights' [-Wunused-parameter]

51 | size_t quantize_i2_s(const float * src, void * dst, int64_t nrow, int64_t n_per_row, const float * quant_weights) {

  |                                                                                                    ^

/////BitNet/src/ggml-bitnet-mad.cpp:200:39: warning: cast from 'const void *' to 'unsigned char *' drops const qualifier [-Wcast-qual]

200 | const uint8_t * x = (uint8_t *)vx;

  |                                       ^

/////BitNet/src/ggml-bitnet-mad.cpp:201:38: warning: cast from 'const void *' to 'signed char *' drops const qualifier [-Wcast-qual]

201 | const int8_t * y = (int8_t *)vy;

  |                                      ^

/////BitNet/src/ggml-bitnet-mad.cpp:198:56: warning: unused parameter 'bs' [-Wunused-parameter]

198 | void ggml_vec_dot_i2_i8_s_1x1(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {

  |                                                        ^

/////BitNet/src/ggml-bitnet-mad.cpp:198:112: warning: unused parameter 'by' [-Wunused-parameter]

198 | void ggml_vec_dot_i2_i8_s_1x1(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {

  |                                                                                                                ^

/////BitNet/src/ggml-bitnet-mad.cpp:198:6: warning: no previous prototype for function 'ggml_vec_dot_i2_i8_s_1x1' [-Wmissing-prototypes]

198 | void ggml_vec_dot_i2_i8_s_1x1(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {

  |      ^

/////BitNet/src/ggml-bitnet-mad.cpp:198:1: note: declare 'static' if the function is not intended to be used outside of this translation unit

198 | void ggml_vec_dot_i2_i8_s_1x1(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {

  | ^

  | static 

/////BitNet/src/ggml-bitnet-mad.cpp:416:39: warning: cast from 'const void *' to 'unsigned char *' drops const qualifier [-Wcast-qual]

416 | const uint8_t * x = (uint8_t *)vx;

  |                                       ^

/////BitNet/src/ggml-bitnet-mad.cpp:417:38: warning: cast from 'const void *' to 'signed char *' drops const qualifier [-Wcast-qual]

417 | const int8_t * y = (int8_t *)vy;

  |                                      ^

/////BitNet/src/ggml-bitnet-mad.cpp:414:60: warning: unused parameter 'bs' [-Wunused-parameter]

414 | void ggml_vec_dot_i2_i8_s_1x4_32W(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {

  |                                                            ^

/////BitNet/src/ggml-bitnet-mad.cpp:414:116: warning: unused parameter 'by' [-Wunused-parameter]

414 | void ggml_vec_dot_i2_i8_s_1x4_32W(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {

  |                                                                                                                    ^

/////BitNet/src/ggml-bitnet-mad.cpp:414:6: warning: no previous prototype for function 'ggml_vec_dot_i2_i8_s_1x4_32W' [-Wmissing-prototypes]

414 | void ggml_vec_dot_i2_i8_s_1x4_32W(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {

  |      ^

/////BitNet/src/ggml-bitnet-mad.cpp:414:1: note: declare 'static' if the function is not intended to be used outside of this translation unit

414 | void ggml_vec_dot_i2_i8_s_1x4_32W(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {

  | ^

  | static 

/////BitNet/src/ggml-bitnet-mad.cpp:514:39: warning: cast from 'const void *' to 'unsigned char *' drops const qualifier [-Wcast-qual]

514 | const uint8_t * x = (uint8_t *)vx;

  |                                       ^

/////BitNet/src/ggml-bitnet-mad.cpp:515:38: warning: cast from 'const void *' to 'signed char *' drops const qualifier [-Wcast-qual]

515 | const int8_t * y = (int8_t *)vy;

  |                                      ^

/////BitNet/src/ggml-bitnet-mad.cpp:512:56: warning: unused parameter 'bs' [-Wunused-parameter]

512 | void ggml_vec_dot_i2_i8_s_1xN(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {

  |                                                        ^

/////BitNet/src/ggml-bitnet-mad.cpp:512:112: warning: unused parameter 'by' [-Wunused-parameter]

512 | void ggml_vec_dot_i2_i8_s_1xN(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {

  |                                                                                                                ^

/////BitNet/src/ggml-bitnet-mad.cpp:512:6: warning: no previous prototype for function 'ggml_vec_dot_i2_i8_s_1xN' [-Wmissing-prototypes]

512 | void ggml_vec_dot_i2_i8_s_1xN(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {

  |      ^

/////BitNet/src/ggml-bitnet-mad.cpp:512:1: note: declare 'static' if the function is not intended to be used outside of this translation unit

512 | void ggml_vec_dot_i2_i8_s_1xN(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {

  | ^

  | static 

/////BitNet/src/ggml-bitnet-mad.cpp:793:39: warning: cast from 'const void *' to 'unsigned char *' drops const qualifier [-Wcast-qual]

793 | const uint8_t * x = (uint8_t *)vx;

  |                                       ^

/////BitNet/src/ggml-bitnet-mad.cpp:794:38: warning: cast from 'const void *' to 'signed char *' drops const qualifier [-Wcast-qual]

794 | const int8_t * y = (int8_t *)vy;

  |                                      ^

/////BitNet/src/ggml-bitnet-mad.cpp:811:18: error: cannot initialize a variable of type 'int8_t *' (aka 'signed char *') with an rvalue of type 'const int8_t *' (aka 'const signed char *')

811 | int8_t * y_col = y + col * by;

  |                  ^       ~~~~~~~~~~~~

/////BitNet/src/ggml-bitnet-mad.cpp:791:84: warning: unused parameter 'bx' [-Wunused-parameter]

791 | void ggml_vec_dot_i2_i8_s_Nx1(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {

  |                                                                                    ^

/////BitNet/src/ggml-bitnet-mad.cpp:791:6: warning: no previous prototype for function 'ggml_vec_dot_i2_i8_s_Nx1' [-Wmissing-prototypes]

791 | void ggml_vec_dot_i2_i8_s_Nx1(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {

  |      ^

/////BitNet/src/ggml-bitnet-mad.cpp:791:1: note: declare 'static' if the function is not intended to be used outside of this translation unit

791 | void ggml_vec_dot_i2_i8_s_Nx1(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {

  | ^

  | static 

32 warnings and 1 error generated.

gmake[2]: *** [3rdparty/llama.cpp/ggml/src/CMakeFiles/ggml.dir/build.make:132: 3rdparty/llama.cpp/ggml/src/CMakeFiles/ggml.dir/////src/ggml-bitnet-mad.cpp.o] Error 1

gmake[1]: *** [CMakeFiles/Makefile2:782: 3rdparty/llama.cpp/ggml/src/CMakeFiles/ggml.dir/all] Error 2

gmake: *** [Makefile:136: all] Error 2"

mustafabugraavci avatar Apr 07 '26 20:04 mustafabugraavci

@mustafabugraavci looks still the same as what I originally mentioned:

Turn int8_t * y_col = y + col * by; => into const int8_t * y_col = y + col * by;

brmarkus avatar Apr 08 '26 07:04 brmarkus

Environment Details

  • OS: Ubuntu 24.04.4 LTS (Noble Numbat) / Linux Kernel 6.8.0-124-generic
  • Compiler: g++ (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
  • CMake Version: 3.28.3
  • Conda / Python Version: Conda 26.3.2 / Python 3.9.25
  • Git Branch Status: Up to date with origin/main
  • Commit Hash: 01eb415772c342d9f20dc42772f1583ae1e5b102

Description

When running python setup_env.py -md models/BitNet-b1.58-2B-4T -q i2_s, the CMake compilation fails on my system.

The error is caused by a type mismatch in src/ggml-bitnet-mad.cpp at line 811. The compiler refuses to initialize a mutable int8_t * variable with a const int8_t * rvalue, blocking the build process.

Steps to Reproduce

  1. Clone the repository and update submodules.
  2. Activate environment and download the GGML model.
  3. Run the setup script: python setup_env.py -md models/BitNet-b1.58-2B-4T -q i2_s

Error Log (logs/compile.log)

/home/rogerio/Documentos/BitNet/src/ggml-bitnet-mad.cpp:793:39: warning: cast from 'const void *' to 'unsigned char *' drops const qualifier [-Wcast-qual]
  793 |     const uint8_t *    x = (uint8_t *)vx;

      |                                       ^
/home/rogerio/Documentos/BitNet/src/ggml-bitnet-mad.cpp:794:38: warning: cast from 'const void *' to 'signed char *' drops const qualifier [-Wcast-qual]
  794 |     const int8_t  *    y = (int8_t *)vy;
      |                                      ^
/home/rogerio/Documentos/BitNet/src/ggml-bitnet-mad.cpp:811:18: error: cannot initialize a variable of type 'int8_t *' (aka 'signed char *') with an rvalue of type 'const int8_t *' (aka 'const signed char *')
  811 |         int8_t * y_col = y + col * by;

      |                  ^       ~~~~~~~~~~~~
/home/rogerio/Documentos/BitNet/src/ggml-bitnet-mad.cpp:791:84: warning: unused parameter 'bx' [-Wunused-parameter]
  791 | void ggml_vec_dot_i2_i8_s_Nx1(int n, float * s, size_t bs, const void * vx, size_t bx, const void * vy, size_t by, int nrc) {
      |                                                                                    ^
32 warnings and 1 error generated.
gmake: *** [3rdparty/llama.cpp/ggml/src/CMakeFiles/ggml.dir/build.make:132: 3rdparty/llama.cpp/ggml/src/CMakeFiles/ggml.dir/__/__/__/__/src/ggml-bitnet-mad.cpp.o] Erro 1
gmake: *** [CMakeFiles/Makefile2:777: 3rdparty/llama.cpp/ggml/src/CMakeFiles/ggml.dir/all] Erro 2
gmake: *** [Makefile:136: all] Erro 2

rogeriob2br avatar Jun 05 '26 15:06 rogeriob2br

@rogeriob2br looks still the same as what I originally mentioned:

Turn int8_t * y_col = y + col * by; => into const int8_t * y_col = y + col * by;

brmarkus avatar Jun 05 '26 16:06 brmarkus