/src/llama.cpp/src/llama-impl.h
Line | Count | Source |
1 | | #pragma once |
2 | | |
3 | | #include "ggml.h" // for ggml_log_level |
4 | | |
5 | | #include <string> |
6 | | #include <type_traits> |
7 | | #include <vector> |
8 | | |
9 | | #ifdef __GNUC__ |
10 | | # if defined(__MINGW32__) && !defined(__clang__) |
11 | | # define LLAMA_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__))) |
12 | | # else |
13 | | # define LLAMA_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__))) |
14 | | # endif |
15 | | #else |
16 | | # define LLAMA_ATTRIBUTE_FORMAT(...) |
17 | | #endif |
18 | | |
19 | | // |
20 | | // logging |
21 | | // |
22 | | |
23 | | LLAMA_ATTRIBUTE_FORMAT(2, 3) |
24 | | void llama_log_internal (ggml_log_level level, const char * format, ...); |
25 | | void llama_log_callback_default(ggml_log_level level, const char * text, void * user_data); |
26 | | |
27 | | #define LLAMA_LOG(...) llama_log_internal(GGML_LOG_LEVEL_NONE , __VA_ARGS__) |
28 | 0 | #define LLAMA_LOG_INFO(...) llama_log_internal(GGML_LOG_LEVEL_INFO , __VA_ARGS__) Unexecuted instantiation: llama-model.cpp:llama_model::print_info() const::$_0::operator()(unsigned int) const Unexecuted instantiation: llama-model.cpp:llama_model::print_info() const::$_1::operator()(unsigned int) const Unexecuted instantiation: llama-model.cpp:llama_model::print_info() const::$_2::operator()(unsigned int) const Unexecuted instantiation: llama-model.cpp:llama_model::print_info() const::$_3::operator()(unsigned int) const Unexecuted instantiation: llama-model.cpp:llama_model::print_info() const::$_4::operator()(unsigned int) const Unexecuted instantiation: llama-model.cpp:llama_model::print_info() const::$_5::operator()(unsigned int) const Unexecuted instantiation: llama-model.cpp:llama_model::print_info() const::$_6::operator()(unsigned int) const |
29 | 0 | #define LLAMA_LOG_WARN(...) llama_log_internal(GGML_LOG_LEVEL_WARN , __VA_ARGS__) |
30 | 0 | #define LLAMA_LOG_ERROR(...) llama_log_internal(GGML_LOG_LEVEL_ERROR, __VA_ARGS__) |
31 | 0 | #define LLAMA_LOG_DEBUG(...) llama_log_internal(GGML_LOG_LEVEL_DEBUG, __VA_ARGS__) |
32 | 0 | #define LLAMA_LOG_CONT(...) llama_log_internal(GGML_LOG_LEVEL_CONT , __VA_ARGS__) |
33 | | |
34 | | // |
35 | | // helpers |
36 | | // |
37 | | |
38 | | template <typename T> |
39 | | struct no_init { |
40 | | T value; |
41 | | no_init() = default; |
42 | | }; |
43 | | |
44 | | template <typename dst_t, typename src_t> |
45 | 0 | static inline dst_t llama_cast(src_t v) { |
46 | 0 | if constexpr (std::is_same_v<src_t, dst_t>) { |
47 | 0 | return v; |
48 | 0 | } else if constexpr (std::is_same_v<src_t, ggml_fp16_t> && std::is_same_v<dst_t, float>) { |
49 | 0 | return ggml_fp16_to_fp32(v); |
50 | 0 | } else if constexpr (std::is_same_v<src_t, float> && std::is_same_v<dst_t, ggml_fp16_t>) { |
51 | 0 | return ggml_fp32_to_fp16(v); |
52 | | } else { |
53 | | static_assert(std::is_same_v<dst_t, void>, "unsupported type combination"); |
54 | | } |
55 | 0 | } Unexecuted instantiation: llama-graph.cpp:unsigned short llama_cast<unsigned short, float>(float) Unexecuted instantiation: llama-graph.cpp:float llama_cast<float, unsigned short>(unsigned short) Unexecuted instantiation: llama-graph.cpp:float llama_cast<float, float>(float) Unexecuted instantiation: llama-kv-cache.cpp:unsigned short llama_cast<unsigned short, float>(float) Unexecuted instantiation: llama-kv-cache.cpp:float llama_cast<float, float>(float) |
56 | | |
57 | | struct time_meas { |
58 | | time_meas(int64_t & t_acc, bool disable = false); |
59 | | ~time_meas(); |
60 | | |
61 | | const int64_t t_start_us; |
62 | | |
63 | | int64_t & t_acc; |
64 | | }; |
65 | | |
66 | | template <typename T> |
67 | | struct buffer_view { |
68 | | T * data; |
69 | | size_t size = 0; |
70 | | |
71 | 0 | bool has_data() const { |
72 | 0 | return data && size > 0; |
73 | 0 | } Unexecuted instantiation: buffer_view<float>::has_data() const Unexecuted instantiation: buffer_view<int>::has_data() const |
74 | | }; |
75 | | |
76 | | void replace_all(std::string & s, const std::string & search, const std::string & replace); |
77 | | |
78 | | // TODO: rename to llama_format ? |
79 | | LLAMA_ATTRIBUTE_FORMAT(1, 2) |
80 | | std::string format(const char * fmt, ...); |
81 | | |
82 | | std::string llama_format_tensor_shape(const std::vector<int64_t> & ne); |
83 | | std::string llama_format_tensor_shape(const struct ggml_tensor * t); |
84 | | |
85 | | std::string gguf_kv_to_str(const struct gguf_context * ctx_gguf, int i); |
86 | | |
87 | 0 | #define LLAMA_TENSOR_NAME_FATTN "__fattn__" |
88 | 0 | #define LLAMA_TENSOR_NAME_FGDN_AR "__fgdn_ar__" |
89 | 0 | #define LLAMA_TENSOR_NAME_FGDN_CH "__fgdn_ch__" |