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 / branches.py

49 lines · 2203 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Test only: exercise signed SOPP range boundaries against the ISA definition.
4No generated table is input to a production build. The production SGEMM backward
5branch is separately compared to LLVM's complete .text bytes by run.sh.
6"""
7import pathlib
8import struct
9import subprocess
10import sys
11
12exe, source, output = sys.argv[1:]
13out = pathlib.Path(output)
14lines = pathlib.Path(source).read_text().splitlines()
15header = '\n'.join(lines[:next(i for i, line in enumerate(lines) if line.startswith('I '))]) + '\n'
16wait = 'I 4 0xc07f 0x0c\n'
17end = 'I 4 0 0x01\n'
18
19
20def text(data):
21 shoff, = struct.unpack_from('<Q', data, 40)
22 entsize, count = struct.unpack_from('<HH', data, 58)
23 sections = [struct.unpack_from('<IIQQQQIIQQ', data, shoff + i * entsize) for i in range(count)]
24 code = [data[row[4]:row[4] + row[5]] for row in sections if row[1] == 1 and row[2] & 4]
25 assert len(code) == 1
26 return code[0]
27
28
29for label, body, expected, index, imm in (
30 ('forward-max', 'I 4 @99 0x05\n' + wait * 32767 + 'T 99\n' + end, 0, 0, 32767),
31 ('backward-min', 'T 99\n' + wait * 32767 + 'I 4 @99 0x05\n' + end, 0, 32767, 32768),
32 ('forward-overflow', 'I 4 @99 0x05\n' + wait * 32768 + 'T 99\n' + end, 4, 0, 0),
33 ('backward-overflow', 'T 99\n' + wait * 32768 + 'I 4 @99 0x05\n' + end, 4, 0, 0),
34 ('undefined-label', 'I 4 @99 0x05\n' + end, 4, 0, 0),
35 ('duplicate-label', 'T 99\nT 99\n' + end, 4, 0, 0),
36):
37 table = out / (label + '.isa')
38 table.write_text(header + body)
39 result = subprocess.run([exe, str(table)], capture_output=True, timeout=60)
40 assert result.returncode == expected, (label, result.returncode, expected, result.stderr)
41 if expected:
42 assert result.stdout == b'', (label, 'bytes escaped before refusal')
43 print(f'CONTROL {label} CAUGHT exit=4 before output', flush=True)
44 else:
45 assert result.stderr == b''
46 code = text(result.stdout)
47 word, = struct.unpack_from('<I', code, index * 4)
48 assert word == 0xbf850000 | imm, (label, hex(word))
49 print(f'PASS SOPP {label} exact signed-16-bit word={word:08x}', flush=True)