]> git.djapps.eu Git - pkg/ggml/sources/ggml/commitdiff
cmake : enable some basic warnings globally (#482)
authorCebtenzzre <redacted>
Mon, 28 Aug 2023 11:44:18 +0000 (07:44 -0400)
committerGitHub <redacted>
Mon, 28 Aug 2023 11:44:18 +0000 (14:44 +0300)
* cmake : make -Werror=vla global

* cmake : make -Wuninitialized global (part of -Wall)

* tests : fix some -Wunused warnings

This flag is not enabled by default. There are still some warnings
remaining.

* cmake : make -Wsign-compare global (part of -Wall)

* cmake : make -Wall global (minus -Wunused)

* cmake : make -Wstrict-prototypes global

* cmake : add -Wpedantic -Wformat=2 globally

---------

Co-authored-by: Georgi Gerganov <redacted>
16 files changed:
CMakeLists.txt
examples/dolly-v2/main.cpp
examples/gpt-2/main.cpp
examples/gpt-j/main.cpp
examples/gpt-neox/main.cpp
examples/mnist/main-cpu.cpp
examples/mpt/main.cpp
examples/replit/main.cpp
examples/sam/main.cpp
examples/starcoder/main.cpp
examples/starcoder/starcoder-mmap.cpp
src/CMakeLists.txt
tests/test-grad0.cpp
tests/test-mul-mat0.c
tests/test-mul-mat2.c
tests/test-vec1.c

index 155e3d394e99333452f9652406b8ce257bc34e88..6589e78bbcdc3b2bdcae7bd6959e7ebc80207056 100644 (file)
@@ -69,6 +69,20 @@ endif()
 
 # warning flags
 
+if (GGML_ALL_WARNINGS)
+    if (NOT MSVC)
+        set(c_flags   -Wall -Wpedantic -Wformat=2 -Wno-unused -Wstrict-prototypes)
+        set(cxx_flags -Wall -Wpedantic -Wformat=2)
+    else()
+        # todo : windows
+    endif()
+
+    add_compile_options(
+        "$<$<COMPILE_LANGUAGE:C>:${c_flags}>"
+        "$<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>"
+    )
+endif()
+
 if (NOT MSVC)
     add_compile_options(-Werror=vla)
 endif()
index a09cad6156352fb104c7c561c62569496da6f8cf..18ad1ad843fdb24d0325ce4946401b26c360b685 100644 (file)
@@ -705,8 +705,8 @@ std::string execute_prompt(
     params.n_predict = std::min(params.n_predict, model.hparams.n_ctx - (int)embd_inp.size());
 
     printf("%s: number of tokens in prompt = %zu\n", __func__, embd_inp.size());
-    for (int i = 0; i < embd_inp.size(); i++) {
-        printf("%s: token[%d] = %6d, %s\n", __func__, i, embd_inp[i], vocab.id_to_token.at(embd_inp[i]).c_str());
+    for (size_t i = 0; i < embd_inp.size(); i++) {
+        printf("%s: token[%zu] = %6d, %s\n", __func__, i, embd_inp[i], vocab.id_to_token.at(embd_inp[i]).c_str());
     }
     printf("\n");
 
@@ -716,7 +716,7 @@ std::string execute_prompt(
 
     const int32_t end_token = vocab.token_to_id["### End"];
 
-    for (int i = embd.size(); i < embd_inp.size() + params.n_predict; i++) {
+    for (size_t i = embd.size(); i < embd_inp.size() + params.n_predict; i++) {
         // predict
         if (embd.size() > 0) {
             const int64_t t_start_us = ggml_time_us();
@@ -754,9 +754,9 @@ std::string execute_prompt(
             embd.push_back(id);
         } else {
             // if here, it means we are still processing the input prompt
-            for (int k = i; k < embd_inp.size(); k++) {
+            for (size_t k = i; k < embd_inp.size(); k++) {
                 embd.push_back(embd_inp[k]);
-                if (embd.size() > params.n_batch) {
+                if (int32_t(embd.size()) > params.n_batch) {
                     break;
                 }
             }
@@ -875,7 +875,7 @@ int main(int argc, char ** argv) {
     }
 
 #if defined(DOLLY_INTERACTIVE_PORT)
-    int sockfd;
+    int sockfd = -1;
     if (params.interactive_port != -1) {
         sockfd = setup_port(params.interactive_port);
         if (sockfd == -1) {
@@ -890,7 +890,7 @@ int main(int argc, char ** argv) {
         while (true) {
             std::string prompt_input;
 #if defined(DOLLY_INTERACTIVE_PORT)
-            int clientfd;
+            int clientfd = -1;
             if (params.interactive_port != -1) {
                 sockaddr_in clientaddr;
                 socklen_t clientaddrlen = sizeof(clientaddr);
index ed405002a720c28d659fbaa6f167a0a4725c3b93..14caf2cc9d9dbed80c362e1ae8bde4ec32df80b4 100644 (file)
@@ -816,7 +816,7 @@ int main(int argc, char ** argv) {
     // this reduces the memory usage during inference, at the cost of a bit of speed at the beginning
     std::vector<gpt_vocab::id> embd;
 
-    for (int i = embd.size(); i < embd_inp.size() + params.n_predict; i++) {
+    for (size_t i = embd.size(); i < embd_inp.size() + params.n_predict; i++) {
         // predict
         if (embd.size() > 0) {
             const int64_t t_start_us = ggml_time_us();
@@ -854,9 +854,9 @@ int main(int argc, char ** argv) {
             embd.push_back(id);
         } else {
             // if here, it means we are still processing the input prompt
-            for (int k = i; k < embd_inp.size(); k++) {
+            for (size_t k = i; k < embd_inp.size(); k++) {
                 embd.push_back(embd_inp[k]);
-                if (embd.size() >= params.n_batch) {
+                if (int32_t(embd.size()) >= params.n_batch) {
                     break;
                 }
             }
index b23ad3d24c41aea2281b6e46122ff3082b0b9f96..d5fca51b0826d83998f558610c632607790367d4 100644 (file)
@@ -671,7 +671,7 @@ int main(int argc, char ** argv) {
     size_t mem_per_token = 0;
     gptj_eval(model, params.n_threads, 0, { 0, 1, 2, 3 }, logits, mem_per_token);
 
-    for (int i = embd.size(); i < embd_inp.size() + params.n_predict; i++) {
+    for (size_t i = embd.size(); i < embd_inp.size() + params.n_predict; i++) {
         // predict
         if (embd.size() > 0) {
             const int64_t t_start_us = ggml_time_us();
@@ -709,9 +709,9 @@ int main(int argc, char ** argv) {
             embd.push_back(id);
         } else {
             // if here, it means we are still processing the input prompt
-            for (int k = i; k < embd_inp.size(); k++) {
+            for (size_t k = i; k < embd_inp.size(); k++) {
                 embd.push_back(embd_inp[k]);
-                if (embd.size() > params.n_batch) {
+                if (int32_t(embd.size()) > params.n_batch) {
                     break;
                 }
             }
index 80ee6643187a0ea209202026bc0c91fdb8cda015..68ba723dc1f4be4127cf4dace5349e90d2e49a72 100644 (file)
@@ -726,8 +726,8 @@ int main(int argc, char ** argv) {
     params.n_predict = std::min(params.n_predict, model.hparams.n_ctx - (int) embd_inp.size());
 
     printf("%s: number of tokens in prompt = %zu\n", __func__, embd_inp.size());
-    for (int i = 0; i < embd_inp.size(); i++) {
-        printf("%s: token[%d] = %6d, %s\n", __func__, i, embd_inp[i], vocab.id_to_token.at(embd_inp[i]).c_str());
+    for (size_t i = 0; i < embd_inp.size(); i++) {
+        printf("%s: token[%zu] = %6d, %s\n", __func__, i, embd_inp[i], vocab.id_to_token.at(embd_inp[i]).c_str());
     }
     printf("\n");
 
@@ -737,7 +737,7 @@ int main(int argc, char ** argv) {
     size_t mem_per_token = 0;
     gpt_neox_eval(model, params.n_threads, 0, { 0, 1, 2, 3 }, logits, mem_per_token);
 
-    for (int i = embd.size(); i < embd_inp.size() + params.n_predict; i++) {
+    for (size_t i = embd.size(); i < embd_inp.size() + params.n_predict; i++) {
         // predict
         if (embd.size() > 0) {
             const int64_t t_start_us = ggml_time_us();
@@ -775,9 +775,9 @@ int main(int argc, char ** argv) {
             embd.push_back(id);
         } else {
             // if here, it means we are still processing the input prompt
-            for (int k = i; k < embd_inp.size(); k++) {
+            for (size_t k = i; k < embd_inp.size(); k++) {
                 embd.push_back(embd_inp[k]);
-                if (embd.size() > params.n_batch) {
+                if (int32_t(embd.size()) > params.n_batch) {
                     break;
                 }
             }
index ba0c313677e4dced2e9f8b445c0eb68004274780..6e1e39801ad88cac978f21c1cb37476a714d0248 100644 (file)
@@ -42,7 +42,7 @@ int mnist_eval(
     struct ggml_cgraph gfi = ggml_graph_import(fname_cgraph, &ctx_data, &ctx_eval);
 
     // param export/import test
-    GGML_ASSERT(ggml_graph_get_tensor(&gfi, "fc1_bias")->op_params[0] == 0xdeadbeef);
+    GGML_ASSERT(ggml_graph_get_tensor(&gfi, "fc1_bias")->op_params[0] == int(0xdeadbeef));
 
     // allocate work context
     // needed during ggml_graph_compute() to allocate a work tensor
index 2fda67cc71fd2f560a409493102176e6cca12faa..5fec3c12a23db2500c2d589bc5a8c72cb58a98e8 100644 (file)
@@ -243,7 +243,7 @@ bool mpt_model_load(const std::string & fname, mpt_model & model, gpt_vocab & vo
             // Convert token from utf-8
             std::wstring word_multibytes = convert_to_wstring(word);
             word.resize(word_multibytes.size());
-            for (int w = 0; w < word_multibytes.size(); w++) {
+            for (size_t w = 0; w < word_multibytes.size(); w++) {
                 word[w] = uint8_t(word_multibytes[w]);
             }
 
index 3fb664d83edb04e6ab39a2e4a5569f9a302ca80c..bd614399d1ae9997b12ab5debf3d8e51863740b6 100644 (file)
@@ -52,9 +52,9 @@ std::pair<std::vector<std::size_t>, float> encode_word(const std::string & word,
     std::vector<float> best_segmentations_scores(word.length() + 1, -std::numeric_limits<float>::infinity());
     best_segmentations_scores[0] = 1.0;
 
-    for (int start_idx = 0; start_idx < word.length(); ++start_idx) {
+    for (size_t start_idx = 0; start_idx < word.length(); ++start_idx) {
         float best_score_at_start = best_segmentations_scores[start_idx];
-        for (int end_idx = start_idx + 1; end_idx <= word.length(); ++end_idx) {
+        for (size_t end_idx = start_idx + 1; end_idx <= word.length(); ++end_idx) {
             std::string token = word.substr(start_idx, end_idx - start_idx);
             if (model.count(token) && best_score_at_start != -std::numeric_limits<float>::infinity()) {
                 float token_score = model.at(token).second;
@@ -92,7 +92,7 @@ bool replit_tokenizer_load(replit_tokenizer & tokenizer, std::istream & fin, int
     std::string word;
     std::vector<char> buf(128);
 
-    for (std::size_t i = 0; i < max_vocab_size; i++) {
+    for (int i = 0; i < max_vocab_size; i++) {
         uint32_t len;
         fin.read((char *)&len, sizeof(len));
 
@@ -702,8 +702,8 @@ int main(int argc, char ** argv) {
 
     printf("%s: number of tokens in prompt = %zu\n", __func__, embd_inp.size());
 
-    for (int i = 0; i < embd_inp.size(); i++) {
-        printf("%s: token[%d] = %6zu\n", __func__, i, embd_inp[i]);
+    for (size_t i = 0; i < embd_inp.size(); i++) {
+        printf("%s: token[%zu] = %6zu\n", __func__, i, embd_inp[i]);
         // vocab.id_to_token.at(embd_inp[i]).c_str()
     }
     printf("\n");
@@ -716,7 +716,7 @@ int main(int argc, char ** argv) {
     size_t mem_per_token = 0;
     replit_eval(model, params.n_threads, 0, {0, 1, 2, 3}, logits, false, mem_per_token);
 
-    for (int i = embd.size(); i < embd_inp.size() + params.n_predict; i++) {
+    for (size_t i = embd.size(); i < embd_inp.size() + params.n_predict; i++) {
         // predict
         if (embd.size() > 0) {
             const int64_t t_start_us = ggml_time_us();
@@ -755,9 +755,9 @@ int main(int argc, char ** argv) {
             embd.push_back(id);
         } else {
             // if here, it means we are still processing the input prompt
-            for (int k = i; k < embd_inp.size(); k++) {
+            for (size_t k = i; k < embd_inp.size(); k++) {
                 embd.push_back(embd_inp[k]);
-                if (embd.size() > params.n_batch) {
+                if (int32_t(embd.size()) > params.n_batch) {
                     break;
                 }
             }
index c1fff545bc9d15f88c9089f01de5f9cd095b34b7..f57156911d957261f7d199d0c01c05185c48c08e 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <cassert>
 #include <cmath>
+#include <cstddef>
 #include <cstdio>
 #include <cstring>
 #include <fstream>
@@ -1027,7 +1028,7 @@ bool sam_model_load(const std::string & fname, sam_model & model) {
             }
         }
 
-        if (n_tensors != model.tensors.size()) {
+        if (n_tensors != ptrdiff_t(model.tensors.size())) {
             fprintf(stderr, "%s: model file has %d tensors, but %d tensors were expected\n", __func__, n_tensors, (int) model.tensors.size());
             return false;
         }
index 56576a6630cb167dd461fbb56283ba0cdedc5d0f..548ebed7738b5dc716acd6907734b5b846a2133a 100644 (file)
@@ -146,7 +146,7 @@ bool starcoder_model_load(const std::string & fname, starcoder_model & model, gp
         }
 
         // Add StarChat special tokens.
-        for (const std::string & token : {
+        for (std::string token : {
                 "<|system|>",
                 "<|user|>",
                 "<|assistant|>",
@@ -809,8 +809,8 @@ int main(int argc, char ** argv) {
 
     printf("%s: prompt: '%s'\n", __func__, params.prompt.c_str());
     printf("%s: number of tokens in prompt = %zu\n", __func__, embd_inp.size());
-    for (int i = 0; i < embd_inp.size(); i++) {
-        printf("%s: token[%d] = %6d, %s\n", __func__, i, embd_inp[i], vocab.id_to_token.at(embd_inp[i]).c_str());
+    for (size_t i = 0; i < embd_inp.size(); i++) {
+        printf("%s: token[%zu] = %6d, %s\n", __func__, i, embd_inp[i], vocab.id_to_token.at(embd_inp[i]).c_str());
     }
     printf("\n\n");
 
@@ -836,7 +836,7 @@ int main(int argc, char ** argv) {
     size_t mem_per_token = 0;
     starcoder_eval(model, params.n_threads, 0, { 0, 1, 2, 3 }, logits, mem_per_token);
 
-    for (int i = embd.size(); i < embd_inp.size() + params.n_predict; i++) {
+    for (size_t i = embd.size(); i < embd_inp.size() + params.n_predict; i++) {
         // predict
         if (embd.size() > 0) {
             const int64_t t_start_us = ggml_time_us();
@@ -876,13 +876,13 @@ int main(int argc, char ** argv) {
             last_n_tokens.push_back(id);
         } else {
             // if here, it means we are still processing the input prompt
-            for (int k = i; k < embd_inp.size(); k++) {
+            for (size_t k = i; k < embd_inp.size(); k++) {
                 embd.push_back(embd_inp[k]);
 
                 last_n_tokens.erase(last_n_tokens.begin());
                 last_n_tokens.push_back(embd_inp[k]);
 
-                if (embd.size() >= params.n_batch) {
+                if (int32_t(embd.size()) >= params.n_batch) {
                     break;
                 }
             }
index b7d26f4765f3cc031fee78c41751438ec9672c59..b86926944726ecedc4ff9618168034fa8e832a34 100644 (file)
@@ -264,7 +264,7 @@ bool starcoder_model_load(const std::string & fname, starcoder_model & model, gp
         }
 
         // Add StarChat special tokens.
-        for (const std::string & token : {
+        for (std::string token : {
                 "<|system|>",
                 "<|user|>",
                 "<|assistant|>",
@@ -1009,8 +1009,8 @@ int main(int argc, char ** argv) {
 
     printf("%s: prompt: '%s'\n", __func__, params.prompt.c_str());
     printf("%s: number of tokens in prompt = %zu\n", __func__, embd_inp.size());
-    for (int i = 0; i < embd_inp.size(); i++) {
-        printf("%s: token[%d] = %6d, %s\n", __func__, i, embd_inp[i], vocab.id_to_token.at(embd_inp[i]).c_str());
+    for (size_t i = 0; i < embd_inp.size(); i++) {
+        printf("%s: token[%zu] = %6d, %s\n", __func__, i, embd_inp[i], vocab.id_to_token.at(embd_inp[i]).c_str());
     }
     printf("\n\n");
 
@@ -1032,7 +1032,7 @@ int main(int argc, char ** argv) {
     printf("Calling starcoder_eval\n");
     starcoder_eval(model, params.n_threads, 0, { 0, 1, 2, 3 }, logits, mem_per_token);
 
-    for (int i = int(embd.size()); i < embd_inp.size() + params.n_predict; i++) {
+    for (size_t i = embd.size(); i < embd_inp.size() + params.n_predict; i++) {
         // predict
         if (embd.size() > 0) {
             const int64_t t_start_us = ggml_time_us();
@@ -1073,9 +1073,9 @@ int main(int argc, char ** argv) {
             embd.push_back(id);
         } else {
             // if here, it means we are still processing the input prompt
-            for (int k = i; k < embd_inp.size(); k++) {
+            for (size_t k = i; k < embd_inp.size(); k++) {
                 embd.push_back(embd_inp[k]);
-                if (embd.size() >= params.n_batch) {
+                if (int32_t(embd.size()) >= params.n_batch) {
                     break;
                 }
             }
index b329c08e27e9164dced721327e73fb2587c674ac..81d041513cd04a278ac4ce9601fa9248409405b7 100644 (file)
@@ -1,14 +1,10 @@
 if (GGML_ALL_WARNINGS)
-    if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
-        #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
+    if (NOT MSVC)
         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
-            -Wall                           \
+            -Wunused                        \
             -Wextra                         \
-            -Wpedantic                      \
             -Wshadow                        \
             -Wcast-qual                     \
-            -Wstrict-prototypes             \
-            -Wpointer-arith                 \
             -Wdouble-promotion              \
             -Wno-unused-function            \
             -Wmissing-prototypes            \
index 75a698d73dc673f7a86b6dcfcf072d30c78bb5cc..8b912bae79ecfa24f5b1c724d40686263d66a85f 100644 (file)
@@ -208,26 +208,6 @@ static struct ggml_tensor * get_random_tensor_i32(
     return result;
 }
 
-static void print_elements(const char* label, const struct ggml_tensor * t) {
-    if (!t) {
-        printf("%s: %s = null\n", __func__, label);
-        return;
-    }
-    const int nelements = ggml_nelements(t);
-    printf("%s: %s = [", __func__, label);
-    for (int k = 0; k < nelements; ++k) {
-        if (k > 0) { printf(", "); }
-        printf("%.5f", ggml_get_f32_1d(t, k));
-    }
-    printf("] shape: [");
-    for (int k = 0; k < t->n_dims; ++k) {
-        if (k > 0) { printf(", "); }
-        printf("%d", (int)t->ne[k]);
-    }
-    printf("]\n");
-
-}
-
 static bool check_gradient(
         const char * op_name,
         struct ggml_context * ctx0,
index 1bd6e140ba86b407fc5edf898d9f0f0593d12fb2..6212da41a6bb144c10a5f0ce66a9556c52de889b 100644 (file)
@@ -13,7 +13,7 @@
 
 #define MAX_NARGS 2
 
-float frand() {
+float frand(void) {
     return (float)rand()/(float)RAND_MAX;
 }
 
@@ -163,10 +163,6 @@ bool check_mat_mul(
         const struct ggml_tensor * y,
         const struct ggml_tensor * x0,
         const struct ggml_tensor * x1) {
-    float * dst  = (float *) y->data;
-    float * src0 = (float *) x0->data;
-    float * src1 = (float *) x1->data;
-
     const int64_t n00 = x0->ne[0];
     const int64_t n10 = x0->ne[1];
     const int64_t n20 = x0->ne[2];
index 944c48e9b7c351be9492bb46b7fb29e154968530..89af28636dd42cf7a0fdd029477e88c393dbe72d 100644 (file)
@@ -54,7 +54,7 @@ const int K = 1280;
 #define gq_t_bits 64
 #define gq_quant_t uint64_t
 
-float frand() {
+float frand(void) {
     return (float) rand() / (float) RAND_MAX;
 }
 
@@ -127,7 +127,7 @@ static inline int quantize_1_blocks_per_row(int k) {
     return k/QK;
 }
 
-static inline int quantize_1_quants_per_block() {
+static inline int quantize_1_quants_per_block(void) {
     return QK/gq_t_bits;
 }
 
@@ -286,7 +286,7 @@ static inline int quantize_2_blocks_per_row(int k) {
     return k/QK;
 }
 
-static inline int quantize_2_quants_per_block() {
+static inline int quantize_2_quants_per_block(void) {
     return QK/gq_t_bits;
 }
 
@@ -662,9 +662,6 @@ void mul_mat_gq_2(
     int m, int n, int k) {
     assert(k % QK == 0);
 
-    const int nb = quantize_2_blocks_per_row(k);
-    const int nq = quantize_2_quants_per_block();
-
     for (int ir0 = 0; ir0 < m; ir0++) {
         for (int ir1 = 0; ir1 < n; ir1++) {
             vec_dot_gq_2(k, dst + ir1, src0, src1);
@@ -686,7 +683,7 @@ static inline int quantize_3_blocks_per_row(int k) {
     return k/QK;
 }
 
-static inline int quantize_3_quants_per_block() {
+static inline int quantize_3_quants_per_block(void) {
     return QK/gq_t_bits;
 }
 
@@ -2355,8 +2352,6 @@ void mul_mat_gq_6(
     int m, int n, int k) {
     assert(k % 32 == 0);
 
-    const int nb = quantize_6_blocks_per_row(k);
-
     for (int ir0 = 0; ir0 < m; ir0++) {
         for (int ir1 = 0; ir1 < n; ir1++) {
             vec_dot_gq_6(k, dst + ir1, src0, src1);
index fefcd68f7fb4c4ac4aba2e0213f8aa21c8c4468d..567cb061740d5c4c922df90015f2c2852b5fbd06 100644 (file)
@@ -460,7 +460,7 @@ void mul_mat_vec_f16_3(
     }
 }
 
-uint64_t get_time_us() {
+uint64_t get_time_us(void) {
     struct timeval tv;
     gettimeofday(&tv, NULL);
     return tv.tv_sec * 1000000 + tv.tv_usec;