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

Fix warning on fprintf

Open sroussey opened this issue 2 years ago • 5 comments

Use macros for long long (and long long unsigned)

sroussey avatar Jun 06 '23 20:06 sroussey

Isn't it supposed to be PRId64, PRIu64 etc instead?

SlyEcho avatar Jun 06 '23 20:06 SlyEcho

Georgi said he didn’t like that. I would agree with you however (and that was the first try)

sroussey avatar Jun 06 '23 22:06 sroussey

So the proposed change still generates warning with gcc:

$ ▶ git diff
diff --git a/ggml.c b/ggml.c
index 045768f..f8958bd 100644
--- a/ggml.c
+++ b/ggml.c
@@ -14720,12 +14720,12 @@ static void ggml_graph_export_leaf(const struct ggml_tensor * tensor, FILE * fou
     const int64_t * ne = tensor->ne;
     const size_t  * nb = tensor->nb;
 
-    fprintf(fout, "%-6s %-12s %8d %8d %d %d %d %16zu %16zu %16zu %16zu %16p %32s\n",
+    fprintf(fout, "%-6s %-12s %8d %8lld %lld %lld %lld %16zu %16zu %16zu %16zu %16p %32s\n",
             ggml_type_name(tensor->type),
             ggml_op_name  (tensor->op),
             tensor->n_dims,
-            (int) ne[0], (int) ne[1], (int) ne[2], (int) ne[3],
-                  nb[0],       nb[1],       nb[2],       nb[3],
+            ne[0], ne[1], ne[2], ne[3],
+            nb[0], nb[1], nb[2], nb[3],
             tensor->data,
             tensor->name);
 }
 ggerganov ▶ ggerganov-3499 ▶ SSH ▶ ~/development/github/llama.cpp ▶
 06:49:47 ▶ master ▶ ✎ ▶ ⎘ ▶ $ ▶ 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
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
I LDFLAGS:  
I CC:       cc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0
I CXX:      g++ (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.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   -c ggml.c -o ggml.o
ggml.c: In function ‘ggml_graph_export_leaf’:
ggml.c:14723:39: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 6 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
14723 |     fprintf(fout, "%-6s %-12s %8d %8lld %lld %lld %lld %16zu %16zu %16zu %16zu %16p %32s\n",
      |                                   ~~~~^
      |                                       |
      |                                       long long int
      |                                   %8ld
......
14727 |             ne[0], ne[1], ne[2], ne[3],
      |             ~~~~~                      
      |               |
      |               int64_t {aka long int}
ggml.c:14723:44: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 7 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
14723 |     fprintf(fout, "%-6s %-12s %8d %8lld %lld %lld %lld %16zu %16zu %16zu %16zu %16p %32s\n",
      |                                         ~~~^
      |                                            |
      |                                            long long int
      |                                         %ld
......
14727 |             ne[0], ne[1], ne[2], ne[3],
      |                    ~~~~~                    
      |                      |
      |                      int64_t {aka long int}
ggml.c:14723:49: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 8 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
14723 |     fprintf(fout, "%-6s %-12s %8d %8lld %lld %lld %lld %16zu %16zu %16zu %16zu %16p %32s\n",
      |                                              ~~~^
      |                                                 |
      |                                                 long long int
      |                                              %ld
......
14727 |             ne[0], ne[1], ne[2], ne[3],
      |                           ~~~~~                  
      |                             |
      |                             int64_t {aka long int}
ggml.c:14723:54: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 9 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
14723 |     fprintf(fout, "%-6s %-12s %8d %8lld %lld %lld %lld %16zu %16zu %16zu %16zu %16p %32s\n",
      |                                                   ~~~^
      |                                                      |
      |                                                      long long int
      |                                                   %ld
......
14727 |             ne[0], ne[1], ne[2], ne[3],
      |                                  ~~~~~                
      |                                    |
      |                                    int64_t {aka long int}
g++ -I. -I./examples -O3 -std=c++11 -fPIC -DNDEBUG -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wno-multichar -pthread -march=native -mtune=native examples/main/main.cpp ggml.o ggml-quants-k.o llama.o common.o -o main 

Lets do the PRId64 stuff after all

ggerganov avatar Jun 07 '23 03:06 ggerganov

OK, I squashed back to just using PRId64, PRIu64

sroussey avatar Jun 07 '23 15:06 sroussey

And a clean version now.

sroussey avatar Jun 07 '23 15:06 sroussey