okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
6a74320ca
main
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 { 14std ::string name ; 15std ::vector < uint64_t > shape ;// ggml order: shape[0] is the contiguous (row) dimension 16int type = -1 ; 17uint64_t offset = 0 ;// from the start of the FILE (data start + tensor offset) 18uint64_t bytes = 0 ; 19}; 20 21struct File { 22std ::string path ; 23void * map = nullptr;// page-aligned mapping of the whole file 24size_t map_bytes = 0 ;// rounded up to the page size 25size_t file_bytes = 0 ; 26std ::map < std ::string ,Tensor > tensors ; 27std ::map < std ::string ,std ::string > meta_str ; 28std ::map < std ::string ,double > meta_num ; 29bool open (const std ::string & path ,std ::string & err ); 30const Tensor * find (const std ::string & name )const { 31 autoit = tensors .find (name ); 32return it == tensors .end () ? nullptr :& it -> second ; 33 } 34 ~File (); 35}; 36 37}// namespace gguf