interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / tests / amd-exec / log.py

35 lines · 1581 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Test instrument: CDNA3 V_LOG_F32 base2, 1ULP, FTZ (ISA p187)."""
4from decimal import Decimal, localcontext
5from fractions import Fraction
6from functools import lru_cache
7import pathlib
8import random
9import runpy
10import struct
11import subprocess
12import sys
13ref=runpy.run_path(str(pathlib.Path(__file__).with_name('attention.py')))
14finite,enclosure,ftz= (ref[n] for n in ('finite','enclosure','ftz'))
15@lru_cache(None)
16def logbound(bits):
17 x=finite(ftz(bits))
18 assert x>0
19 if x==1: return Fraction(0),Fraction(0)
20 with localcontext() as ctx:
21 ctx.prec=120
22 value=(Decimal(x.numerator)/Decimal(x.denominator)).ln()/Decimal(2).ln()
23 return enclosure(Fraction(value))
24def suite(exe):
25 rng=random.Random(942033)
26 values=list(range(0x3f7fff00,0x3f800100))+[rng.randrange(0x800000,0x7f800000) for _ in range(4096)]
27 result=subprocess.run([exe],input=b''.join(struct.pack('<II',33,x) for x in values),capture_output=True,timeout=60)
28 assert result.returncode==0 and not result.stderr and len(result.stdout)==4*len(values),result
29 worst=Fraction(0)
30 for i,x in enumerate(values):
31 y=finite(struct.unpack_from('<I',result.stdout,4*i)[0]); lo,hi=logbound(x)
32 assert lo<=y<=hi,f'LOG interval escape input={x:08x} value={y} bound={lo,hi}'
33 worst=max(worst,abs(y-(lo+hi)/2))
34 print(f'PASS LOG Decimal120 inputs={len(values)} interval_escapes=0 worst_midpoint_error={float(worst):.12g} seed=942033')
35if __name__=='__main__': suite(sys.argv[1])