From bde76ec959c6fc04f88a54b5b98034ff57cdd337 Mon Sep 17 00:00:00 2001 From: Yangwook Kang Date: Sun, 5 Apr 2026 00:25:41 -0700 Subject: [PATCH] =?UTF-8?q?Cube-view:=2045=C2=B0=20diagonal=20from=20route?= =?UTF-8?q?r,=20then=20straight=20to=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All connectors now start with 45° diagonal from router edge, then go straight (vertical/horizontal) to the component block. Applies to PE, M_CPU/SRAM, PE→HBM, and UCIe connectors. Co-Authored-By: Claude Opus 4.6 (1M context) --- docs/diagrams/cube_view.svg | 68 ++++++++--------- src/kernbench/topology/visualizer.py | 108 ++++++++++++++++----------- 2 files changed, 97 insertions(+), 79 deletions(-) diff --git a/docs/diagrams/cube_view.svg b/docs/diagrams/cube_view.svg index 3809682..15c6b9f 100644 --- a/docs/diagrams/cube_view.svg +++ b/docs/diagrams/cube_view.svg @@ -135,12 +135,12 @@ r0c0 PE0 - + r0c1 PE1 - + r0c2 @@ -161,17 +161,17 @@ r1c4 PE2 - + r1c5 PE3 - + r2c0 M_CPU - + r2c1 @@ -182,7 +182,7 @@ r3c0 SRAM - + r3c1 @@ -193,12 +193,12 @@ r4c0 PE4 - + r4c1 PE5 - + r4c2 @@ -219,84 +219,84 @@ r5c4 PE6 - + r5c5 PE7 - - + + 256GB/s - + 256GB/s - + 256GB/s - + 256GB/s - + 256GB/s - + 256GB/s - + 256GB/s - + 256GB/s UCIe-W c0 - + c1 - + c2 - + c3 - + UCIe-N c0 - + c1 - + c2 - + c3 - + UCIe-E c0 - + c1 - + c2 - + c3 - + UCIe-S c0 - + c1 - + c2 - + c3 - + PE Router diff --git a/src/kernbench/topology/visualizer.py b/src/kernbench/topology/visualizer.py index 04c40cb..8d21ff0 100644 --- a/src/kernbench/topology/visualizer.py +++ b/src/kernbench/topology/visualizer.py @@ -632,47 +632,50 @@ def _render_cube_view_svg(view: ViewGraph, spec: dict) -> str: f'text-anchor="middle" font-family="monospace" font-size="{font_sz}" ' f'font-weight="bold" fill="{style["text"]}">{_escape(label)}' ) - # Connector line: block → router (45° L-bend) + # Connector line: router → component (diagonal out from router, then straight) sc = style["stroke"] if kind in ("mcpu", "sram"): - # From block right edge, 45° bend to router - x1 = bx + blk_w + # Router → 45° diagonal → horizontal to block + x1 = bx + blk_w # block right edge y1 = by + blk_h / 2 - x2 = px - r_size + x2 = px - r_size # router left edge y2 = py - # 45° bend: go horizontal first, then diagonal - mid_x = x2 - abs(y2 - y1) + dy = abs(y2 - y1) + # From router: diagonal 45° toward block, then horizontal + mid_x = x2 - dy # 45° means dx == dy if mid_x < x1: - mid_x = (x1 + x2) / 2 + mid_x = x1 parts.append( - f' ' ) else: - # PE: from block bottom/top edge, 45° bend to router + # PE: Router → 45° diagonal → vertical to block if is_top: - x1 = bx + blk_w / 2 + offset_x - y1 = by + blk_h - x2 = px - y2 = py - r_size - # 45° bend: go vertical first, then diagonal - mid_y = y2 - abs(x2 - x1) + x1 = bx + blk_w / 2 + offset_x # block center + y1 = by + blk_h # block bottom + x2 = px # router center + y2 = py - r_size # router top + dx = abs(x2 - x1) + # From router: 45° diagonal, then vertical to block + mid_y = y2 - dx if mid_y < y1: - mid_y = (y1 + y2) / 2 + mid_y = y1 parts.append( - f' ' ) else: x1 = bx + blk_w / 2 + offset_x - y1 = by + y1 = by # block top x2 = px - y2 = py + r_size - mid_y = y2 + abs(x2 - x1) + y2 = py + r_size # router bottom + dx = abs(x2 - x1) + mid_y = y2 + dx if mid_y > y1: - mid_y = (y1 + y2) / 2 + mid_y = y1 parts.append( - f' ' ) @@ -694,14 +697,20 @@ def _render_cube_view_svg(view: ViewGraph, spec: dict) -> str: rpx, rpy = mm2px(rx, ry) tgx, tgy = _pe_hbm_targets[pe_id] r_edge_y = rpy + r_size if rpy < hbm_y else rpy - r_size - # 45° L-bend: vertical from router, then diagonal to HBM port - mid_y = tgy - abs(tgx - rpx) if rpy < hbm_y else tgy + abs(tgx - rpx) + # From router: 45° diagonal toward HBM port, then vertical to port + dx = abs(tgx - rpx) if rpy < hbm_y: - mid_y = max(mid_y, (r_edge_y + tgy) / 2) + # Top half: router bottom → 45° diagonal → vertical down to HBM top + mid_y = r_edge_y + dx + if mid_y > tgy: + mid_y = tgy else: - mid_y = min(mid_y, (r_edge_y + tgy) / 2) + # Bottom half: router top → 45° diagonal → vertical up to HBM bottom + mid_y = r_edge_y - dx + if mid_y < tgy: + mid_y = tgy parts.append( - f' ' ) @@ -796,42 +805,51 @@ def _render_cube_view_svg(view: ViewGraph, spec: dict) -> str: f'{conn}' ) - # Connector line: port → router (45° L-bend) + # Connector line: router → UCIe port (diagonal from router, then straight) rpx, rpy = mm2px(crx, cry) if direction == "N": - x1, y1 = lx, cy_box + ch - x2, y2 = rpx, rpy - r_size - mid_y = y2 - abs(x2 - x1) - mid_y = max(mid_y, (y1 + y2) / 2) + # Router top → 45° diagonal → vertical to UCIe port + x2, y2 = rpx, rpy - r_size # router top + x1, y1 = lx, cy_box + ch # port bottom + dx = abs(x1 - x2) + mid_y = y2 - dx + if mid_y < y1: + mid_y = y1 parts.append( - f' ' ) elif direction == "S": - x1, y1 = lx, cy_box x2, y2 = rpx, rpy + r_size - mid_y = y2 + abs(x2 - x1) - mid_y = min(mid_y, (y1 + y2) / 2) + x1, y1 = lx, cy_box + dx = abs(x1 - x2) + mid_y = y2 + dx + if mid_y > y1: + mid_y = y1 parts.append( - f' ' ) elif direction == "W": - x1, y1 = cx + cw, cy_box + ch / 2 x2, y2 = rpx - r_size, rpy - mid_x = x2 - abs(y2 - y1) - mid_x = max(mid_x, (x1 + x2) / 2) + x1, y1 = cx + cw, cy_box + ch / 2 + dy = abs(y1 - y2) + mid_x = x2 - dy + if mid_x < x1: + mid_x = x1 parts.append( - f' ' ) elif direction == "E": - x1, y1 = cx, cy_box + ch / 2 x2, y2 = rpx + r_size, rpy - mid_x = x2 + abs(y2 - y1) - mid_x = min(mid_x, (x1 + x2) / 2) + x1, y1 = cx, cy_box + ch / 2 + dy = abs(y1 - y2) + mid_x = x2 + dy + if mid_x > x1: + mid_x = x1 parts.append( - f' ' )