-
Notifications
You must be signed in to change notification settings - Fork 13.6k
cmake : add sanitizer flags for llama.cpp #11279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
72dc7bf
cmake : add sanitizer flags for llama.cpp
ggerganov ce293d8
tests : fix compile warnings
ggerganov 9a03bc8
cmake : move sanitizer flags to llama_add_compile_flags
ggerganov 9d1b20a
cmake : move llama.cpp compile flags to top level lists
ggerganov e872097
cmake : apply only sanitizer flags at top level
ggerganov 7000623
tests : fix gguf context use in same_tensor_data
ggerganov a3a2a06
gguf-test: tensor data comparison
JohannesGaessler 84aef8d
dummy : trigger ggml-ci
ggerganov 9945478
unicode : silence gcc warnings
ggerganov d076b6a
ci : use sanitizer builds only in Debug mode
ggerganov e9c43b8
cmake : add status messages [no ci]
ggerganov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,7 @@ enum handcrafted_file_type { | |
| HANDCRAFTED_DATA_CUSTOM_ALIGN = 810 + offset_has_data, | ||
| }; | ||
|
|
||
| std::string handcrafted_file_type_name(const enum handcrafted_file_type hft) { | ||
| static std::string handcrafted_file_type_name(const enum handcrafted_file_type hft) { | ||
| switch (hft) { | ||
| case HANDCRAFTED_HEADER_BAD_MAGIC: return "HEADER_BAD_MAGIC"; | ||
| case HANDCRAFTED_HEADER_BAD_VERSION_1: return "HEADER_BAD_VERSION_1"; | ||
|
|
@@ -99,7 +99,7 @@ static bool expect_context_not_null(const enum handcrafted_file_type hft) { | |
|
|
||
| typedef std::pair<enum ggml_type, std::array<int64_t, GGML_MAX_DIMS>> tensor_config_t; | ||
|
|
||
| std::vector<tensor_config_t> get_tensor_configs(std::mt19937 & rng) { | ||
| static std::vector<tensor_config_t> get_tensor_configs(std::mt19937 & rng) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious, compiler warnings normally pick this up, but not here it seems |
||
| std::vector<tensor_config_t> tensor_configs; | ||
| tensor_configs.reserve(100); | ||
|
|
||
|
|
@@ -122,7 +122,7 @@ std::vector<tensor_config_t> get_tensor_configs(std::mt19937 & rng) { | |
| return tensor_configs; | ||
| } | ||
|
|
||
| std::vector<std::pair<enum gguf_type, enum gguf_type>> get_kv_types(std::mt19937 rng) { | ||
| static std::vector<std::pair<enum gguf_type, enum gguf_type>> get_kv_types(std::mt19937 rng) { | ||
| std::vector<std::pair<enum gguf_type, enum gguf_type>> kv_types; | ||
| kv_types.reserve(100); | ||
|
|
||
|
|
@@ -626,8 +626,6 @@ static bool handcrafted_check_tensor_data(const gguf_context * gguf_ctx, const u | |
|
|
||
| bool ok = true; | ||
|
|
||
| const uint32_t alignment = GGUF_DEFAULT_ALIGNMENT; | ||
|
|
||
| for (int i = 0; i < int(tensor_configs.size()); ++i) { | ||
| const ggml_type type = tensor_configs[i].first; | ||
| const std::array<int64_t, GGML_MAX_DIMS> shape = tensor_configs[i].second; | ||
|
|
@@ -866,13 +864,13 @@ static struct random_gguf_context_result get_random_gguf_context(ggml_backend_t | |
| case GGUF_TYPE_COUNT: | ||
| default: { | ||
| GGML_ABORT("fatal error"); | ||
| } break; | ||
| } | ||
| } | ||
| } break; | ||
| case GGUF_TYPE_COUNT: | ||
| default: { | ||
| GGML_ABORT("fatal error"); | ||
| } break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -938,7 +936,7 @@ static bool all_kv_in_other(const gguf_context * ctx, const gguf_context * other | |
| } | ||
|
|
||
| if (type == GGUF_TYPE_ARRAY) { | ||
| const int arr_n = gguf_get_arr_n(ctx, id); | ||
| const size_t arr_n = gguf_get_arr_n(ctx, id); | ||
| if (arr_n != gguf_get_arr_n(other, idx_other)) { | ||
| ok = false; | ||
| continue; | ||
|
|
@@ -953,7 +951,7 @@ static bool all_kv_in_other(const gguf_context * ctx, const gguf_context * other | |
| if (type_arr == GGUF_TYPE_BOOL) { | ||
| const int8_t * data = reinterpret_cast<const int8_t *>(gguf_get_arr_data(ctx, id)); | ||
| const int8_t * data_other = reinterpret_cast<const int8_t *>(gguf_get_arr_data(other, idx_other)); | ||
| for (int arr_i = 0; arr_i < arr_n; ++arr_i) { | ||
| for (size_t arr_i = 0; arr_i < arr_n; ++arr_i) { | ||
| if (bool(data[arr_i]) != bool(data_other[arr_i])) { | ||
| ok = false; | ||
| } | ||
|
|
@@ -962,7 +960,7 @@ static bool all_kv_in_other(const gguf_context * ctx, const gguf_context * other | |
| } | ||
|
|
||
| if (type_arr == GGUF_TYPE_STRING) { | ||
| for (int arr_i = 0; arr_i < arr_n; ++arr_i) { | ||
| for (size_t arr_i = 0; arr_i < arr_n; ++arr_i) { | ||
| const std::string str = gguf_get_arr_str(ctx, id, arr_i); | ||
| const std::string str_other = gguf_get_arr_str(other, idx_other, arr_i); | ||
| if (str != str_other) { | ||
|
|
@@ -1057,7 +1055,7 @@ static bool same_tensor_data(const struct ggml_context * orig, const struct ggml | |
| ok = false; | ||
| } | ||
|
|
||
| return true; | ||
| return ok; | ||
ggerganov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| static std::pair<int, int> test_roundtrip(ggml_backend_dev_t dev, const unsigned int seed, const bool only_meta) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is done in the top-level
CMakeLists.txtit should automatically apply to all included subdirectories.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved them to the
llama_add_compile_flags()to be consistent with the existingLLAMA_FATAL_WARNINGSandLLAMA_ALL_WARNINGSoptions.Moved a single call of
llama_add_compile_flags()to the top-levelCMakeLists.txt. It's OK for now, but in general I think that having separate calls in the sub-trees is better, because it allows for example to have 3rd-party code in theexamplestree that would not be a subject to the llama.cpp compile flags.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sanitizer flags should still be applied to 3rd-party code regardless, but maybe not other flags like warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the sanitizer flags are now at the top level. Also removed the
GGML_SANITIZE_*options as they are not actually useful, because all the code must be compiled with sanitizers.