llama-mmap.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include <memory>
  3. #include <vector>
  4. struct llama_file;
  5. struct llama_mmap;
  6. struct llama_mlock;
  7. using llama_files = std::vector<std::unique_ptr<llama_file>>;
  8. using llama_mmaps = std::vector<std::unique_ptr<llama_mmap>>;
  9. using llama_mlocks = std::vector<std::unique_ptr<llama_mlock>>;
  10. struct llama_file {
  11. llama_file(const char * fname, const char * mode);
  12. ~llama_file();
  13. size_t tell() const;
  14. size_t size() const;
  15. int fileno() const;
  16. void seek(size_t offset, int whence) const;
  17. void read_raw(void * ptr, size_t len) const;
  18. uint32_t read_u32() const;
  19. void write_raw(const void * ptr, size_t len) const;
  20. void write_u32(uint32_t val) const;
  21. private:
  22. struct impl;
  23. std::unique_ptr<impl> pimpl;
  24. };
  25. struct llama_mmap {
  26. llama_mmap(const llama_mmap &) = delete;
  27. llama_mmap(struct llama_file * file, size_t prefetch = (size_t) -1, bool numa = false);
  28. ~llama_mmap();
  29. size_t size() const;
  30. void * addr() const;
  31. void unmap_fragment(size_t first, size_t last);
  32. static const bool SUPPORTED;
  33. private:
  34. struct impl;
  35. std::unique_ptr<impl> pimpl;
  36. };
  37. struct llama_mlock {
  38. llama_mlock();
  39. ~llama_mlock();
  40. void init(void * ptr);
  41. void grow_to(size_t target_size);
  42. static const bool SUPPORTED;
  43. private:
  44. struct impl;
  45. std::unique_ptr<impl> pimpl;
  46. };
  47. size_t llama_path_max();