llama-mmap.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 <memory>
  28. #include <vector>
  29. struct llama_file;
  30. struct llama_mmap;
  31. struct llama_mlock;
  32. using llama_files = std::vector<std::unique_ptr<llama_file>>;
  33. using llama_mmaps = std::vector<std::unique_ptr<llama_mmap>>;
  34. using llama_mlocks = std::vector<std::unique_ptr<llama_mlock>>;
  35. struct llama_file {
  36. llama_file(const char * fname, const char * mode);
  37. ~llama_file();
  38. size_t tell() const;
  39. size_t size() const;
  40. int fileno() const;
  41. void seek(size_t offset, int whence) const;
  42. void read_raw(void * ptr, size_t len) const;
  43. uint32_t read_u32() const;
  44. void write_raw(const void * ptr, size_t len) const;
  45. void write_u32(uint32_t val) const;
  46. private:
  47. struct impl;
  48. std::unique_ptr<impl> pimpl;
  49. };
  50. struct llama_mmap {
  51. llama_mmap(const llama_mmap &) = delete;
  52. llama_mmap(struct llama_file * file, size_t prefetch = (size_t) -1, bool numa = false);
  53. ~llama_mmap();
  54. size_t size() const;
  55. void * addr() const;
  56. void unmap_fragment(size_t first, size_t last);
  57. static const bool SUPPORTED;
  58. private:
  59. struct impl;
  60. std::unique_ptr<impl> pimpl;
  61. };
  62. struct llama_mlock {
  63. llama_mlock();
  64. ~llama_mlock();
  65. void init(void * ptr);
  66. void grow_to(size_t target_size);
  67. static const bool SUPPORTED;
  68. private:
  69. struct impl;
  70. std::unique_ptr<impl> pimpl;
  71. };
  72. size_t llama_path_max();