#!/usr/bin/env python3 """Run whole preset M frames on the engine's own stages and compare the output with the capture. usage: test_frame_m.py CAPTURE_DIR WORK_DIR KVK EVK [frames] Every stage runs as its own process (kvk for the texture stages, evk for the network layers). Only the frame's colour, motion and depth, the exposure values and the kernels' parameter blocks come from the capture; all intermediate data and all temporal history are the engine's own. """ import glob, os, re, struct, subprocess, sys import numpy as np HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) import m_model as mm import swin_model as sm from test_m import pack_layer, defines, token_codes, report cap, work, kvk, evk = sys.argv[1:5] frames = int(sys.argv[5]) if len(sys.argv) > 5 else 2 os.makedirs(work, exist_ok=True) LDR = os.environ.get('LDR') == '1' # a capture without the HDR flag: NGX's *_ldr_* kernels, the shaders' LDR paths R = 'ldr' if LDR else 'hdr' # below a reconstruction/render ratio of 3 the capture holds NGX's rrlite_post_3_2; the engine then needs the # larger shared tile (post_m.comp's TILE_W/TILE_H) POST = os.environ.get('POST_KERNEL') or next((k for k in (f'rrlite_post_3_1_mvlo_{R}_folded', f'rrlite_post_3_2_mvlo_{R}_folded') if glob.glob(f'{cap}/dump/launch-*-{k}-arg*')), f'rrlite_post_3_1_mvlo_{R}_folded') POST_TILE = ['-DTILE_W=15', '-DTILE_H=15'] if '3_2' in POST else [] NAMES = {'enc0': f'rrlite_enc0_4x4_mvlo_{R}_folded', 'dec0': 'rrlite_dec0_4x4_folded', 'post': POST, 'down': f'rrlite_downsample_kernel_static_{R}'} STAGE = ['-DLDR=1'] if LDR else [] class Launch: def __init__(self, kernel, frame): seqs = sorted({int(re.match(r'launch-(\d+)-', os.path.basename(f)).group(1)) for f in glob.glob(f'{cap}/dump/launch-*-{kernel}-arg*')}) self.seq = seqs[frame] self.res = {int(re.search(r'-arg(\d+)-', f).group(1)): f for f in glob.glob(f'{cap}/dump/launch-{self.seq:03d}-{kernel}-arg*')} self.dir = f'{cap}/replay/replay-{self.seq:06d}-{kernel}' self.P = open(self.dir + '/args.bin', 'rb').read() self.allocs = {} for line in open(self.dir + '/manifest.txt'): q = line.split() if q and q[0] == 'alloc': self.allocs[int(q[1])] = (int(q[2], 16), np.fromfile(f'{self.dir}/alloc-{q[1]}.bin', np.uint8)) i2 = lambda s, o: struct.unpack_from('<2i', s.P, o) f2 = lambda s, o: struct.unpack_from('<2f', s.P, o) f1 = lambda s, o: struct.unpack_from('