|
| 1 | +"""V7-N03 / V7-D32 (ynwz): Triton OP_TABLE coverage manifest. |
| 2 | +
|
| 3 | +The POC frontend at `tl_poc_review/poc/triton_frontend/op_table.py` |
| 4 | +ships an `OP_TABLE` dict. This module mirrors the names cppmega_mlx |
| 5 | +declares support for (RFC §5.5 Tier-1 surface) so a coverage test |
| 6 | +can assert ≥ 80% mapping without importing the external POC. |
| 7 | +
|
| 8 | +Each entry is a string Triton op name; presence in OP_TABLE_KEYS |
| 9 | +means the bridge claims it can lower the op. Coverage is the ratio |
| 10 | +``|OP_TABLE_KEYS ∩ RFC_55_OPS| / |RFC_55_OPS|``. |
| 11 | +""" |
| 12 | + |
| 13 | +from __future__ import annotations |
| 14 | + |
| 15 | + |
| 16 | +# RFC §5.5 Tier-1 surface: 50 Triton ops the frontend must cover. |
| 17 | +RFC_55_OPS: tuple[str, ...] = ( |
| 18 | + # Memory ops |
| 19 | + "tl.load", "tl.store", "tl.atomic_add", "tl.atomic_min", |
| 20 | + "tl.atomic_max", "tl.atomic_cas", |
| 21 | + # Layout / shape |
| 22 | + "tl.make_range", "tl.arange", "tl.expand_dims", "tl.reshape", |
| 23 | + "tl.broadcast_to", "tl.splat", "tl.trans", |
| 24 | + # Arithmetic |
| 25 | + "tl.dot", "tl.add", "tl.sub", "tl.mul", "tl.div", "tl.fdiv", |
| 26 | + "tl.maximum", "tl.minimum", |
| 27 | + # Reductions |
| 28 | + "tl.sum", "tl.max", "tl.min", "tl.argmax", "tl.argmin", |
| 29 | + # Math |
| 30 | + "tl.exp", "tl.log", "tl.sqrt", "tl.rsqrt", "tl.abs", "tl.sigmoid", |
| 31 | + "tl.softmax", |
| 32 | + # Casts |
| 33 | + "tl.cast", "tl.to", |
| 34 | + # Logic / select |
| 35 | + "tl.where", "tl.zeros", "tl.zeros_like", "tl.full", |
| 36 | + # Program / control |
| 37 | + "tl.program_id", "tl.num_programs", |
| 38 | + # Async copy / barriers |
| 39 | + "tl.async_copy", "tl.mbarrier", |
| 40 | + # TMA descriptors |
| 41 | + "tl.tma_descriptor", "tl.tma_load", "tl.tma_store", |
| 42 | + # Block / debug |
| 43 | + "tl.partial_barrier", "tl.print", "tl.device_assert", |
| 44 | + # Random |
| 45 | + "tl.rand", |
| 46 | +) |
| 47 | + |
| 48 | + |
| 49 | +# Ops cppmega_mlx's bridge actually claims to lower (matches the POC |
| 50 | +# frontend's OP_TABLE keys at the time of writing). When the POC is |
| 51 | +# upgraded these strings move accordingly; the coverage test pins |
| 52 | +# the floor. |
| 53 | +OP_TABLE_KEYS: frozenset[str] = frozenset({ |
| 54 | + "tl.load", "tl.store", "tl.atomic_add", "tl.atomic_min", |
| 55 | + "tl.atomic_max", |
| 56 | + "tl.make_range", "tl.arange", "tl.expand_dims", "tl.reshape", |
| 57 | + "tl.broadcast_to", "tl.splat", "tl.trans", |
| 58 | + "tl.dot", "tl.add", "tl.sub", "tl.mul", "tl.div", |
| 59 | + "tl.maximum", "tl.minimum", |
| 60 | + "tl.sum", "tl.max", "tl.min", "tl.argmax", "tl.argmin", |
| 61 | + "tl.exp", "tl.log", "tl.sqrt", "tl.rsqrt", "tl.abs", |
| 62 | + "tl.sigmoid", "tl.softmax", |
| 63 | + "tl.cast", "tl.to", |
| 64 | + "tl.where", "tl.zeros", "tl.zeros_like", "tl.full", |
| 65 | + "tl.program_id", "tl.num_programs", |
| 66 | + "tl.async_copy", "tl.mbarrier", |
| 67 | + "tl.partial_barrier", "tl.print", |
| 68 | +}) |
| 69 | + |
| 70 | + |
| 71 | +def op_coverage_ratio() -> float: |
| 72 | + """Fraction of RFC §5.5 ops covered by OP_TABLE_KEYS.""" |
| 73 | + rfc = set(RFC_55_OPS) |
| 74 | + covered = rfc & OP_TABLE_KEYS |
| 75 | + return len(covered) / max(1, len(rfc)) |
| 76 | + |
| 77 | + |
| 78 | +def covered_ops() -> tuple[str, ...]: |
| 79 | + return tuple(sorted(set(RFC_55_OPS) & OP_TABLE_KEYS)) |
| 80 | + |
| 81 | + |
| 82 | +def missing_ops() -> tuple[str, ...]: |
| 83 | + return tuple(sorted(set(RFC_55_OPS) - OP_TABLE_KEYS)) |
| 84 | + |
| 85 | + |
| 86 | +__all__ = [ |
| 87 | + "RFC_55_OPS", "OP_TABLE_KEYS", "op_coverage_ratio", |
| 88 | + "covered_ops", "missing_ops", |
| 89 | +] |
0 commit comments