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/boundaries.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 / boundaries.py` 60 lines · 1946 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 """Test-only MessagePack oracle: thresholds from the format's bit widths. 4 https://github.com/msgpack/msgpack/blob/master/spec.md#formats 5 Record indices use the unsigned 64-bit wire domain, not kernel-emitted values. 6 """ 7 import pathlib 8 import sys 9 10 UINT_WIDTHS = (7, 8, 16, 32, 64) 11 STR_WIDTHS = (5, 8, 16) 12 13 14 def edges(widths): 15 return sorted({v for width in widths for v in ((1 << width) - 1, 1 << width)}) 16 17 18 def record_indices(): 19 return tuple((1 << 64) - delta for delta in (2, 1)) 20 21 22 def uint_bytes(value): 23 if value < 1 << 7: 24 return bytes([value]) 25 for width, tag in ((8, 0xcc), (16, 0xcd), (32, 0xce), (64, 0xcf)): 26 if value < 1 << width: 27 return bytes([tag]) + value.to_bytes(width // 8, 'big') 28 raise ValueError(value) 29 30 31 def string_bytes(size, fill): 32 if size < 1 << 5: 33 prefix = bytes([0xa0 | size]) 34 else: 35 for width, tag in ((8, 0xd9), (16, 0xda), (32, 0xdb)): 36 if size < 1 << width: 37 prefix = bytes([tag]) + size.to_bytes(width // 8, 'big') 38 break 39 else: 40 raise ValueError(size) 41 return prefix + bytes([fill]) * size 42 43 44 def generate(out): 45 uints = [0] + [v for v in edges(UINT_WIDTHS) if v < 1 << 64] 46 strings = edges(STR_WIDTHS) 47 main = ['fn main to int'] + [f'mpuint {v}' for v in uints] 48 expected = b''.join(uint_bytes(v) for v in uints) 49 for i, size in enumerate(strings): 50 fill = 65 + i 51 main += [f's{i} = new uchar {size} {fill}', f'mpstr s{i}'] 52 expected += string_bytes(size, fill) 53 main += ['flush', 'ret 0', 'end'] 54 (out / 'msgpack-main.om').write_text('\n'.join(main) + '\n') 55 (out / 'msgpack.expected').write_bytes(expected) 56 print(f'BOUNDARIES uint={uints} str={strings} record-index={record_indices()}') 57 58 59 if __name__ == '__main__': 60 generate(pathlib.Path(sys.argv[1]))