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
CUDApp / tests / amd / branches.py
| 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. |
| 4 | No generated table is input to a production build. The production SGEMM backward |
| 5 | branch is separately compared to LLVM's complete .text bytes by run.sh. |
| 6 | """ |
| 7 | import pathlib |
| 8 | import struct |
| 9 | import subprocess |
| 10 | import sys |
| 11 | |
| 12 | exe, source, output = sys.argv[1:] |
| 13 | out = pathlib.Path(output) |
| 14 | lines = pathlib.Path(source).read_text().splitlines() |
| 15 | header = '\n'.join(lines[:next(i for i, line in enumerate(lines) if line.startswith('I '))]) + '\n' |
| 16 | wait = 'I 4 0xc07f 0x0c\n' |
| 17 | end = 'I 4 0 0x01\n' |
| 18 | |
| 19 | |
| 20 | def 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 | |
| 29 | for 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) |