char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Xuan-Son Nguyenllama: model_loader: add TENSOR_READ_LAZY (#27794)fac889fb3

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