llama-impl.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include "ggml.h" // for ggml_log_level
  3. #include <string>
  4. #include <vector>
  5. #ifdef __GNUC__
  6. # if defined(__MINGW32__) && !defined(__clang__)
  7. # define LLAMA_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__)))
  8. # else
  9. # define LLAMA_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
  10. # endif
  11. #else
  12. # define LLAMA_ATTRIBUTE_FORMAT(...)
  13. #endif
  14. //
  15. // logging
  16. //
  17. LLAMA_ATTRIBUTE_FORMAT(2, 3)
  18. void llama_log_internal (ggml_log_level level, const char * format, ...);
  19. void llama_log_callback_default(ggml_log_level level, const char * text, void * user_data);
  20. #define LLAMA_LOG(...) llama_log_internal(GGML_LOG_LEVEL_NONE , __VA_ARGS__)
  21. #define LLAMA_LOG_INFO(...) llama_log_internal(GGML_LOG_LEVEL_INFO , __VA_ARGS__)
  22. #define LLAMA_LOG_WARN(...) llama_log_internal(GGML_LOG_LEVEL_WARN , __VA_ARGS__)
  23. #define LLAMA_LOG_ERROR(...) llama_log_internal(GGML_LOG_LEVEL_ERROR, __VA_ARGS__)
  24. #define LLAMA_LOG_DEBUG(...) llama_log_internal(GGML_LOG_LEVEL_DEBUG, __VA_ARGS__)
  25. #define LLAMA_LOG_CONT(...) llama_log_internal(GGML_LOG_LEVEL_CONT , __VA_ARGS__)
  26. //
  27. // helpers
  28. //
  29. template <typename T>
  30. struct no_init {
  31. T value;
  32. no_init() { /* do nothing */ }
  33. };
  34. struct time_meas {
  35. time_meas(int64_t & t_acc, bool disable = false);
  36. ~time_meas();
  37. const int64_t t_start_us;
  38. int64_t & t_acc;
  39. };
  40. void replace_all(std::string & s, const std::string & search, const std::string & replace);
  41. // TODO: rename to llama_format ?
  42. LLAMA_ATTRIBUTE_FORMAT(1, 2)
  43. std::string format(const char * fmt, ...);
  44. std::string llama_format_tensor_shape(const std::vector<int64_t> & ne);
  45. std::string llama_format_tensor_shape(const struct ggml_tensor * t);
  46. std::string gguf_kv_to_str(const struct gguf_context * ctx_gguf, int i);