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