llama-impl.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * llama.cpp - commit 46e3556e01b824e52395fb050b29804b6cff2a7c - do not edit this file
  3. *
  4. * MIT License
  5. *
  6. * Copyright (c) 2023-2024 The ggml authors
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all
  16. * copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. * SOFTWARE.
  25. */
  26. #pragma once
  27. #include "ggml.h" // for ggml_log_level
  28. #include <string>
  29. #include <vector>
  30. #ifdef __GNUC__
  31. #ifdef __MINGW32__
  32. #define LLAMA_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__)))
  33. #else
  34. #define LLAMA_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
  35. #endif
  36. #else
  37. #define LLAMA_ATTRIBUTE_FORMAT(...)
  38. #endif
  39. //
  40. // logging
  41. //
  42. LLAMA_ATTRIBUTE_FORMAT(2, 3)
  43. void llama_log_internal (ggml_log_level level, const char * format, ...);
  44. void llama_log_callback_default(ggml_log_level level, const char * text, void * user_data);
  45. #define LLAMA_LOG(...) llama_log_internal(GGML_LOG_LEVEL_NONE , __VA_ARGS__)
  46. #define LLAMA_LOG_INFO(...) llama_log_internal(GGML_LOG_LEVEL_INFO , __VA_ARGS__)
  47. #define LLAMA_LOG_WARN(...) llama_log_internal(GGML_LOG_LEVEL_WARN , __VA_ARGS__)
  48. #define LLAMA_LOG_ERROR(...) llama_log_internal(GGML_LOG_LEVEL_ERROR, __VA_ARGS__)
  49. #define LLAMA_LOG_DEBUG(...) llama_log_internal(GGML_LOG_LEVEL_DEBUG, __VA_ARGS__)
  50. #define LLAMA_LOG_CONT(...) llama_log_internal(GGML_LOG_LEVEL_CONT , __VA_ARGS__)
  51. //
  52. // helpers
  53. //
  54. template <typename T>
  55. struct no_init {
  56. T value;
  57. no_init() { /* do nothing */ }
  58. };
  59. struct time_meas {
  60. time_meas(int64_t & t_acc, bool disable = false);
  61. ~time_meas();
  62. const int64_t t_start_us;
  63. int64_t & t_acc;
  64. };
  65. void replace_all(std::string & s, const std::string & search, const std::string & replace);
  66. // TODO: rename to llama_format ?
  67. LLAMA_ATTRIBUTE_FORMAT(1, 2)
  68. std::string format(const char * fmt, ...);
  69. std::string llama_format_tensor_shape(const std::vector<int64_t> & ne);
  70. std::string llama_format_tensor_shape(const struct ggml_tensor * t);
  71. std::string gguf_kv_to_str(const struct gguf_context * ctx_gguf, int i);