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/bf16gemv.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 / bf16gemv.py` 106 lines · 4765 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 """Test only: BF16 sign/exponent/fraction -> exact Fraction -> FP32 FMA. 4 No production code, host floating arithmetic, or FP16 rounding implements the oracle. 5 """ 6 from fractions import Fraction 7 import itertools 8 import pathlib 9 import runpy 10 import struct 11 import subprocess 12 import sys 13 14 SG = runpy.run_path(str(pathlib.Path(__file__).with_name('sgemm.py'))) 15 SHAPES = tuple(itertools.product((0, 1, 63, 64, 65), (0, 1, 3, 64, 65, 130))) 16 FINITE = (0x3f80, 0xbf80, 0x3f81, 0xbf81, 0x3f7f, 0x3eab, 0xbe4d, 17 1, 0x8001, 0x007f, 0x807f, 0x0080, 0x8080, 0x7f7f, 0xff7f, 18 0, 0x8000, 0x3380, 0x4c80, 0xcc80) 19 VALUES = FINITE + (0x7f80, 0xff80, 0x7fc1, 0x7f81, 0xffc1, 0xff81) 20 21 22 def decode(bits): 23 # BF16 S1E8M7, bias127; same exponent/sign position as FP32 after exact widening. 24 exponent, fraction = (bits >> 7) & 255, bits & 127 25 sign = (bits >> 15) << 31 26 if exponent == 255: 27 return sign | 0x7f800000 | fraction << 16 28 if not exponent and not fraction: 29 return sign 30 value = Fraction(fraction if not exponent else 128 + fraction, 128) 31 value *= Fraction(2) ** ((exponent if exponent else 1) - 127) 32 if sign: value = -value 33 return SG['round32'](value) 34 35 36 def fixture(m, k, special=False, isolated=False): 37 # A two-byte-aligned, non-dword-aligned base and odd K exercise both row-end alignments. 38 wp = 66 39 xp = (wp + 2*m*k + 19) & ~3 40 yp = xp + 4*k + 16 41 data = bytearray([0xa5] * (yp + 4*m + 64)) 42 struct.pack_into('