llama-mmap.h 1.4 KB

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