okami.mom/strata

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

Niko1221Merge f-own-1b (033cfdd8c) into f-own-int: nothing downloads llama.cppb2de2641f

main
1.5 KiB29 linesraw
1#!/bin/bash
2# ggml declares its tables with GGML_TABLE_BEGIN(type, name, size) ... GGML_TABLE_END(); parse that form.
3set -u
4cd "$HOME/strata-mac/dsv41" || exit 1
5python3 - <<'PY'
6import re, os
7s = open("third_party/strata-ggml/strata-quant-common.h").read()   # the text moved here; third_party/ggml/ggml-common.h forwards to it
8out = ['''// metal/src/engine/msl/ggml_grids.h - ggml's i-quant grid tables, for the MSL expert kernels.
9//
10// Generated from third_party/ggml/ggml-common.h (pinned 3cf03257f): the CUDA and Metal kernels must use bit-identical tables,
11// so they are copied from the same file rather than retyped.  MSL cannot include a C header, so each array becomes a
12// `constant` in the address space the kernels need - same values, same order.
13#pragma once
14
15''']
16pat = re.compile(r"GGML_TABLE_BEGIN\(\s*(uint\d+_t)\s*,\s*(\w+)\s*,\s*([^)]+)\)(.*?)GGML_TABLE_END\(\)", re.S)
17msl = {"uint8_t": "uchar", "uint16_t": "ushort", "uint32_t": "uint", "uint64_t": "ulong"}
18got = []
19for ty, name, size, body in pat.findall(s):
20    if name not in ("ksigns_iq2xs", "kmask_iq2xs", "iq2xxs_grid", "iq2xs_grid", "iq3xxs_grid", "iq3s_grid", "iq2s_grid", "kgrid_q4nl"):
21        continue
22    vals = " ".join(body.split())
23    out.append("constant %s %s[%s] = {%s};\n" % (msl[ty], name, size, vals))
24    got.append("%s[%s]" % (name, size))
25open("metal/src/engine/msl/ggml_grids.h", "w").write("\n".join(out))
26print("emitted:", ", ".join(got) if got else "none")
27PY
28ls -l metal/src/engine/msl/ggml_grids.h | awk '{print $5, $9}'
29grep -c "^constant" metal/src/engine/msl/ggml_grids.h