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