okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
c7d11f789
main
1#!/usr/bin/env python3 2"""P4-SPLIT: check that binaries built without llama.cpp's MMQ prompt kernels (-DSTRATA_MMQ=OFF) hold none of them. 3 4usage: check_no_mmq.py [--nm NM] [--cuobjdump CUOBJDUMP] <binary or library> ... 5 6For every file, three looks, each one where the tool for it exists: 7- the raw bytes: the names and messages only MMQ code carries (kernel names stay readable in an uncompressed fatbin or code object, and 8a Windows .exe keeps the strings even without a symbol table); 9- the symbol table (nm -C; on Linux and the Mac): host functions and the device stubs of launched kernels; 10- the device functions of a CUDA binary (cuobjdump -sass, which also opens a compressed fatbin). 11Exit 0 when nothing is found, 1 with the hits listed (at most 20 per look), 2 on a usage error. 12Strata's own prompt helpers keep the namespace strata::prefill::mmq (gather_native, swiglu, iota, ...): that name is not a marker.""" 13import argparse 14import os 15import re 16import shutil 17import subprocess 18import sys 19 20# llama.cpp's MMQ: the kernels and their templates (mul_mat_q, mul_mat_q_stream_k_fixup, load_tiles_*, vec_dot_*_mma / _dp4a), the q8_1 21# quantizers (quantize_mmq_q8_1, quantize_scatter_mmq_q8_1), ggml-cuda's host side (ggml_cuda_*, ggml_backend_cuda_context) and Strata's MMQ 22# glue (ggml_cuda_host.cu's error text, the K-quant library's file name) 23RAW = [b"mul_mat_q" ,b"quantize_mmq_q8_1" ,b"quantize_scatter_mmq" ,b"ggml_cuda_" ,b"ggml_backend_cuda" ,b"ggml-cuda (strata mmq)" , 24b"libstrata_kq" ,b"strata_kq.dll" ,b"load_tiles_" ,b"mmq_get_" ] 25SYM = re .compile (r"mul_mat_q|quantize_mmq_q8_1|quantize_scatter_mmq|ggml_cuda_|ggml_backend_cuda|load_tiles_|mmq_get_|vec_dot_\w+_(mma|dp4a)" ) 26 27 28def raw_hits (path ): 29data = open (path ,"rb" ).read () 30hits = [] 31for m in RAW : 32n = data .count (m ) 33if n : 34hits .append ("%s x%d" % (m .decode (),n )) 35return hits 36 37 38def tool_lines (cmd ): 39try : 40r = subprocess .run (cmd ,capture_output = True ,text = True ,errors = "replace" ,timeout = 900 ) 41except (OSError ,subprocess .TimeoutExpired )as e : 42return None ,str (e ) 43return r .stdout .splitlines (),None 44 45 46def main (): 47ap = argparse .ArgumentParser () 48ap .add_argument ("--nm" ,default = shutil .which ("nm" )) 49ap .add_argument ("--cuobjdump" ,default = shutil .which ("cuobjdump" )) 50ap .add_argument ("files" ,nargs = "+" ) 51a = ap .parse_args () 52bad = 0 53for f in a .files : 54if not os .path .isfile (f ): 55"%s: missing" % f ) 56return 2 57looks = [] 58h = raw_hits (f ) 59looks .append (("bytes" ,h )) 60if a .nm : 61lines ,err = tool_lines ([a .nm ,"-C" ,f ]) 62if lines is not None : 63looks .append (("nm" ,sorted ({ln .split (None ,2 )[- 1 ]for ln in lines if SYM .search (ln )}))) 64if a .cuobjdump : 65lines ,err = tool_lines ([a .cuobjdump ,"-sass" ,f ]) 66if lines is not None : 67names = [m .group (1 )for ln in lines for m in [re .match (r"\s*Function : (\S+)" ,ln )]if m ] 68if names : 69looks .append (("cuobjdump (%d device functions)" % len (names ),sorted ({n for n in names if SYM .search (n )}))) 70found = [(k ,v )for k ,v in looks if v ] 71"%s: %s" % (f ,"; " .join ("%s %s" % (k ,"CLEAN" if not v else "%d HITS" % len (v ))for k ,v in looks ))) 72for k ,v in found : 73for x in v [:20 ]: 74" %s: %s" % (k ,x [:200 ])) 75bad += bool (found ) 76"no MMQ symbol in %d of %d files" % (len (a .files )- bad ,len (a .files ))) 77return 1 if bad else 0 78 79 80if __name__ == "__main__" : 81sys .exit (main ())