Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/tests/amd-exec/fp8block_fast.py # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / amd-exec / fp8block_fast.py` 357 lines · 18337 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 """Independent checkpoint oracle and private-output acceptance for fp8gemv_b128f. 4 Python is a measuring instrument only. Objects are emitted by seeded Omega hsaco.om. 5 Run under an externally held queen pool lock and nice; see fp8block_fast.md. 6 """ 7 import argparse 8 from fractions import Fraction 9 import hashlib 10 import json 11 from pathlib import Path 12 import runpy 13 import shutil 14 import struct 15 import subprocess 16 17 PIN = '`2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`' 18 NAME = 'fp8gemv_b128f' 19 SHAPES = ((17408, 5120), (5120, 17408), (12288, 5120), (1024, 5120), 20 (10240, 5120), (6144, 5120), (5120, 6144)) 21 22 23 def sha(path): 24 with Path(path).open('rb') as f: 25 return hashlib.file_digest(f, 'sha256').hexdigest() 26 27 28 def ocp(byte, sg): 29 """F8_E4M3: sign, exponent bias7, 3 fraction bits, signed zero, two NaNs. 30 No executor/native-FNUZ conversion routine is used to construct this table. 31 """ 32 sign, exponent, fraction = byte >> 7, (byte >> 3) & 15, byte & 7 33 if exponent == 15 and fraction == 7: 34 return 0x7fc00000 35 if exponent == 0: 36 value = Fraction(fraction, 512) 37 else: 38 value = Fraction(8 + fraction, 8) * Fraction(2) ** (exponent - 7) 39 return sg['round32'](-value if sign else value) | (sign << 31) 40 41 42 def result(weights, x, scales, table, sg): 43 # Independent exact RN-even oracle: four adjacent products, scale, lane acc; 44 # then one simultaneous XOR32,16,8,4,2,1 reduction for the complete row. 45 lanes = [0] * 64 46 for base in range(0, len(weights), 256): 47 for lane in range(64): 48 start = base + lane * 4 49 if start >= len(weights): 50 continue 51 partial = 0 52 for col in range(start, min(start + 4, len(weights))): 53 partial = sg['fma'](table[weights[col]], x[col], partial) 54 lanes[lane] = sg['fma'](scales[start // 128] << 16, partial, lanes[lane]) 55 for xor in (32, 16, 8, 4, 2, 1): 56 lanes = [sg['fma'](a, 0x3f800000, lanes[i ^ xor]) for i, a in enumerate(lanes)] 57 return lanes[0] 58 59 60 def tolerance(data, actual, rows, table, sg, baseline): 61 # v11 policy unchanged. Exact rational evaluation is stronger than its f64 62 # reference: the same f64-reference allowance remains in the bound. 63 wp, xp, sp, yp, m, k = struct.unpack_from(' 0x7f800000 79 continue 80 products = [sg['finite'](table[w]) * sg['finite'](x[col]) * 81 sg['finite'](scales[col//128] << 16) for col, w in enumerate(weights)] 82 ideal, magnitude = sum(products, Fraction()), sum(map(abs, products), Fraction()) 83 bound = factor*magnitude + Fraction(1, 2**126) 84 assert bits & 0x7fffffff < 0x7f800000 85 assert abs(sg['finite'](bits)-ideal) <= bound, (row, k, bits, ideal, bound) 86 return different 87 88 89 def fixture(m, k, rows, table, sg, real=None, all_bytes=False): 90 nb, mb = (k + 127) // 128, (m + 127) // 128 91 wp = 64 92 xp = (wp + m * k + 63) & ~3 93 sp = xp + k * 4 + 64 94 yp = (sp + mb * nb * 2 + 67) & ~3 95 data = bytearray(b'\xa5') * (yp + m * 4 + 64) 96 struct.pack_into('