okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-mac-rel (Mac Metal support) into f-144-rel6a74320ca

main
1.2 KiB37 linesraw
1// metal/src/gguf_lite.h - a minimal GGUF v3 reader for the Metal test programs: tensor names, shapes, types and
2// file offsets, the file mmapped read-only (no copy; wrapped as one MTLBuffer by the caller).
3#pragma once
4
5#include <cstddef>
6#include <cstdint>
7#include <map>
8#include <string>
9#include <vector>
10
11namespace gguf {
12
13struct Tensor {
14    std::string name;
15    std::vector<uint64_t> shape;   // ggml order: shape[0] is the contiguous (row) dimension
16    int type = -1;
17    uint64_t offset = 0;           // from the start of the FILE (data start + tensor offset)
18    uint64_t bytes = 0;
19};
20
21struct File {
22    std::string path;
23    void* map = nullptr;           // page-aligned mapping of the whole file
24    size_t map_bytes = 0;          // rounded up to the page size
25    size_t file_bytes = 0;
26    std::map<std::string, Tensor> tensors;
27    std::map<std::string, std::string> meta_str;
28    std::map<std::string, double> meta_num;
29    bool open(const std::string& path, std::string& err);
30    const Tensor* find(const std::string& name) const {
31        auto it = tensors.find(name);
32        return it == tensors.end() ? nullptr : &it->second;
33    }
34    ~File();
35};
36
37}  // namespace gguf