2024-07-23 13:10:17 +03:00
|
|
|
#pragma once
|
|
|
|
|
2025-01-03 10:18:53 +02:00
|
|
|
#include "ggml.h" // for ggml_log_level
|
2024-07-23 13:10:17 +03:00
|
|
|
|
2024-09-07 15:16:19 +03:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2024-07-23 13:10:17 +03:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#ifdef __MINGW32__
|
|
|
|
#define LLAMA_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__)))
|
|
|
|
#else
|
|
|
|
#define LLAMA_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define LLAMA_ATTRIBUTE_FORMAT(...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// logging
|
|
|
|
//
|
|
|
|
|
|
|
|
LLAMA_ATTRIBUTE_FORMAT(2, 3)
|
|
|
|
void llama_log_internal (ggml_log_level level, const char * format, ...);
|
|
|
|
void llama_log_callback_default(ggml_log_level level, const char * text, void * user_data);
|
|
|
|
|
2024-09-15 20:46:12 +03:00
|
|
|
#define LLAMA_LOG(...) llama_log_internal(GGML_LOG_LEVEL_NONE , __VA_ARGS__)
|
2024-07-23 13:10:17 +03:00
|
|
|
#define LLAMA_LOG_INFO(...) llama_log_internal(GGML_LOG_LEVEL_INFO , __VA_ARGS__)
|
|
|
|
#define LLAMA_LOG_WARN(...) llama_log_internal(GGML_LOG_LEVEL_WARN , __VA_ARGS__)
|
|
|
|
#define LLAMA_LOG_ERROR(...) llama_log_internal(GGML_LOG_LEVEL_ERROR, __VA_ARGS__)
|
2024-09-24 10:15:35 +03:00
|
|
|
#define LLAMA_LOG_DEBUG(...) llama_log_internal(GGML_LOG_LEVEL_DEBUG, __VA_ARGS__)
|
|
|
|
#define LLAMA_LOG_CONT(...) llama_log_internal(GGML_LOG_LEVEL_CONT , __VA_ARGS__)
|
2024-08-09 18:23:52 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// helpers
|
|
|
|
//
|
|
|
|
|
2025-01-03 10:18:53 +02:00
|
|
|
template <typename T>
|
|
|
|
struct no_init {
|
|
|
|
T value;
|
|
|
|
no_init() { /* do nothing */ }
|
|
|
|
};
|
2024-09-07 15:16:19 +03:00
|
|
|
|
2025-01-03 10:18:53 +02:00
|
|
|
struct time_meas {
|
|
|
|
time_meas(int64_t & t_acc, bool disable = false);
|
|
|
|
~time_meas();
|
2024-09-07 15:16:19 +03:00
|
|
|
|
|
|
|
const int64_t t_start_us;
|
|
|
|
|
|
|
|
int64_t & t_acc;
|
|
|
|
};
|
|
|
|
|
2025-01-03 10:18:53 +02:00
|
|
|
void replace_all(std::string & s, const std::string & search, const std::string & replace);
|
2024-09-07 15:16:19 +03:00
|
|
|
|
2025-01-03 10:18:53 +02:00
|
|
|
// TODO: rename to llama_format ?
|
|
|
|
LLAMA_ATTRIBUTE_FORMAT(1, 2)
|
|
|
|
std::string format(const char * fmt, ...);
|
2024-09-08 15:52:07 +02:00
|
|
|
|
2025-01-03 10:18:53 +02:00
|
|
|
std::string llama_format_tensor_shape(const std::vector<int64_t> & ne);
|
|
|
|
std::string llama_format_tensor_shape(const struct ggml_tensor * t);
|
2024-09-07 15:16:19 +03:00
|
|
|
|
2025-01-03 10:18:53 +02:00
|
|
|
std::string gguf_kv_to_str(const struct gguf_context * ctx_gguf, int i);
|