Skip to content
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

cmake : add sanitizer flags for llama.cpp #11279

Merged
merged 11 commits into from
Jan 18, 2025
Merged

cmake : add sanitizer flags for llama.cpp #11279

merged 11 commits into from
Jan 18, 2025

Conversation

ggerganov
Copy link
Owner

ref #11252 (comment)

Also, enable compile flags for tests.

Comment on lines 7 to 22
if (NOT MSVC)
if (LLAMA_SANITIZE_THREAD)
add_compile_options(-fsanitize=thread)
link_libraries (-fsanitize=thread)
endif()

if (LLAMA_SANITIZE_ADDRESS)
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
link_libraries (-fsanitize=address)
endif()

if (LLAMA_SANITIZE_UNDEFINED)
add_compile_options(-fsanitize=undefined)
link_libraries (-fsanitize=undefined)
endif()
endif()
Copy link
Collaborator

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.txt it should automatically apply to all included subdirectories.

Copy link
Owner Author

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 existing LLAMA_FATAL_WARNINGS and LLAMA_ALL_WARNINGS options.

Moved a single call of llama_add_compile_flags() to the top-level CMakeLists.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 the examples tree that would not be a subject to the llama.cpp compile flags.

Copy link
Collaborator

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.

Copy link
Owner Author

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.

@github-actions github-actions bot added build Compilation issues testing Everything test related labels Jan 17, 2025
@@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, compiler warnings normally pick this up, but not here it seems

@JohannesGaessler
Copy link
Collaborator

The reason the tests are failing is another bug in test-gguf. The original and read contexts don't have 100% the same tensors because the first tensor in the read context is the binary blob followed by all of the tensors from the original context. I pushed a fix to jg/llama-sanitize. I did not find a bug outside the test code (but I added a call to ggml_set_name for the binary blob for better bookkeeping).

@ggerganov
Copy link
Owner Author

@JohannesGaessler Thanks for taking a look. I've cherry-picked your commit into this branch. Let's see if the CI passes now.

@github-actions github-actions bot added the ggml changes relating to the ggml tensor library for machine learning label Jan 18, 2025
@github-actions github-actions bot added the devops improvements to build systems and github actions label Jan 18, 2025
@ggerganov ggerganov requested a review from slaren January 18, 2025 10:33
@ggerganov ggerganov merged commit 4dd34ff into master Jan 18, 2025
1 check passed
@ggerganov ggerganov deleted the gg/llama-sanitize branch January 18, 2025 14:18
anagri pushed a commit to BodhiSearch/llama.cpp that referenced this pull request Jan 26, 2025
* cmake : add sanitizer flags for llama.cpp

ggml-ci

* tests : fix compile warnings

ggml-ci

* cmake : move sanitizer flags to llama_add_compile_flags

ggml-ci

* cmake : move llama.cpp compile flags to top level lists

ggml-ci

* cmake : apply only sanitizer flags at top level

ggml-ci

* tests : fix gguf context use in same_tensor_data

* gguf-test: tensor data comparison

* dummy : trigger ggml-ci

* unicode : silence gcc warnings

ggml-ci

* ci : use sanitizer builds only in Debug mode

ggml-ci

* cmake : add status messages [no ci]

---------

Co-authored-by: Johannes Gäßler <johannesg@5d6.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Compilation issues devops improvements to build systems and github actions examples ggml changes relating to the ggml tensor library for machine learning testing Everything test related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants