Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions ggml/src/ggml-alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,32 @@
//#define AT_PRINTF(...) GGML_LOG_DEBUG(__VA_ARGS__)
#define AT_PRINTF(...)

static size_t g_alloc_call_count = 0;
static size_t g_alloc_fail_at = SIZE_MAX;
static bool g_alloc_fail_enabled = false;

static void ggml_alloc_error_injection_init(void) {
const char* fail_at_str = getenv("GGML_TEST_ALLOC_FAIL_AT");
if (fail_at_str != NULL) {
g_alloc_fail_at = (size_t)atoi(fail_at_str);
g_alloc_fail_enabled = true;
}
}

static bool ggml_alloc_should_fail(void) {
if (!g_alloc_fail_enabled) {
return false;
}
g_alloc_call_count++;
return g_alloc_call_count == g_alloc_fail_at;
}

static void ggml_alloc_error_injection_reset(void) {
g_alloc_call_count = 0;
g_alloc_fail_at = SIZE_MAX;
g_alloc_fail_enabled = false;
}


static bool ggml_is_view(const struct ggml_tensor * t) {
return t->view_src != NULL;
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ if (NOT LLAMA_SANITIZE_ADDRESS)
endif()
llama_build_and_test(test-gguf.cpp)
llama_build_and_test(test-backend-ops.cpp)
llama_build_and_test(test-memory-exhaustion.cpp)
llama_build_and_test(test-invalid-inputs.cpp)

llama_build_and_test(test-model-load-cancel.cpp LABEL "model")
llama_build_and_test(test-autorelease.cpp LABEL "model")
Expand Down
1 change: 0 additions & 1 deletion tests/test-backend-ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5433,7 +5433,6 @@ struct test_falcon : public test_llm {
}
};


// ###########################################
// ## Section 3: GGML Op Test Instantiation ##
// ###########################################
Expand Down
Loading
Loading