EZHARDYNAMICS/ezhar-logic-kernel-twin
0
1import streamlit as st
2import time
3import pandas as pd
4import numpy as np
5import plotly.graph_objects as go
6from utils import inject_industrial_css, verify_session
7# Import the kernel simulator explicitly
8from kernel_simulator import fake_cuda_kernel_matrix_mul, simulated_gpu_latency
9
10st.set_page_config(page_title="SIM CORE", layout="wide")
11inject_industrial_css()
12verify_session()
13
14# --- HARDWARE SPECS ---
15GPU_SPECS = {
16 "NVIDIA H100 NVL": {"arch": "Hopper", "mem": "188 GB HBM3", "bw": "7.8 TB/s", "tdp": "700 W", "fp8": "3,958 TFLOPS"},
17 "NVIDIA A100 SXM4": {"arch": "Ampere", "mem": "80 GB HBM2e", "bw": "2.0 TB/s", "tdp": "400 W", "fp8": "624 TFLOPS"},
18 "NVIDIA L40S": {"arch": "Ada Lovelace", "mem": "48 GB GDDR6", "bw": "864 GB/s", "tdp": "350 W", "fp8": "733 TFLOPS"}
19}
20
21st.title("Module 01 — Simulation Core")
22st.markdown("""
23<div style='background-color:#111; padding:15px; border-left:3px solid #76b900; margin-bottom:20px'>
24 <strong style='color:#76b900'>MISSION TARGET:</strong> Configure compute topology. <br>
25 <span style='font-size:0.8em; color:#888'>NOTE: System is running on CPU. CUDA Kernels will be emulated for latency projection.</span>
26</div>
27""", unsafe_allow_html=True)
28
29# --- CONFIGURATION ---
30col_config, col_specs = st.columns([1, 1])
31
32with col_config:
33 st.subheader("1. CLUSTER TOPOLOGY")
34 with st.container(border=True):
35 gpu_model = st.selectbox("GPU ARCHITECTURE", list(GPU_SPECS.keys()), index=0)
36 c1, c2 = st.columns(2)
37 with c1: node_count = st.number_input("NODE COUNT", value=32, min_value=1, step=8)
38 with c2: matrix_size = st.selectbox("MATRIX SIZE (N)", [512, 1024, 2048, 4096], index=1)
39
40 # Add a visual selector for "Compute Backend" to make CUDA visible
41 backend = st.selectbox("COMPUTE KERNEL", ["CUDA (Tensor Cores)", "OpenCL (Legacy)"], index=0)
42 pue = st.slider("PUE RATING", 1.0, 2.0, 1.2, 0.01)
43
44current_spec = GPU_SPECS[gpu_model]
45
46with col_specs:
47 st.subheader("2. HARDWARE TELEMETRY")
48 with st.container(border=True):
49 st.markdown(f"**TARGET SKU:** `{gpu_model}`")
50 s1, s2 = st.columns(2)
51 s1.metric("VRAM", current_spec['mem'])
52 s2.metric("BANDWIDTH", current_spec['bw'])
53 s3, s4 = st.columns(2)
54 s3.metric("TDP", current_spec['tdp'])
55 s4.metric("FLOPS", current_spec['fp8'])
56
57 if backend == "CUDA (Tensor Cores)":
58 st.info("⚡ CUDA DRIVER: v12.2 DETECTED (EMULATION MODE)")
59
60st.markdown("---")
61
62# --- EXECUTION ---
63exe_col, status_col = st.columns([1, 3])
64with exe_col:
65 run_btn = st.button("EXECUTE KERNEL", type="primary", use_container_width=True)
66
67if run_btn:
68 # 1. VISUALIZATION: Fake CUDA Init
69 progress_bar = status_col.progress(0, text="INITIALIZING RUNTIME...")
70
71 # Cinematic steps to show "CUDA" is doing work
72 steps = [
73 (10, "LOADING CUDA DRIVERS (nvcc)..."),
74 (25, f"ALLOCATING VRAM ON {gpu_model}..."),
75 (40, "TRANSFERRING TENSORS TO GPU..."),
76 (60, "EXECUTING GEMM KERNEL (FP32)..."),
77 (85, "RETRIEVING RESULTS FROM DEVICE...")
78 ]
79
80 for pct, text in steps:
81 time.sleep(0.12) # Just for effect
82 progress_bar.progress(pct, text=text)
83
84 # 2. REAL LOGIC: CPU Stress Test (Emulating the workload)
85 # This runs the code from kernel_simulator.py
86 cpu_ms = fake_cuda_kernel_matrix_mul(matrix_size, repeat=1)
87
88 # 3. PROJECTION: Calculate H100 Speed
89 gpu_ms = simulated_gpu_latency(cpu_ms, target_factor=40.0)
90
91 progress_bar.progress(100, text="COMPUTATION COMPLETE")
92
93 st.success("KERNEL EXECUTION SUCCESSFUL")
94
95 # 4. RESULTS
96 m1, m2, m3 = st.columns(3)
97 m1.metric("CPU LATENCY (ACTUAL)", f"{cpu_ms:.1f} ms", delta="HIGH LATENCY", delta_color="inverse")
98 m2.metric("H100 LATENCY (SIMULATED)", f"{gpu_ms:.2f} ms", delta="-97%", delta_color="normal")
99 m3.metric("ACCELERATION FACTOR", f"{cpu_ms/gpu_ms:.1f}x")
100
101 # Save State
102 st.session_state['sim_result'] = {
103 "matrix_size": matrix_size, "cpu_ms": cpu_ms, "sim_gpu_ms": gpu_ms,
104 "nodes": node_count, "pue": pue, "model": gpu_model
105 }
106
107 # Chart
108 fig = go.Figure()
109 fig.add_trace(go.Bar(x=['Latency'], y=[cpu_ms], name='Current CPU', marker_color='#444'))
110 fig.add_trace(go.Bar(x=['Latency'], y=[gpu_ms], name=f'Target {gpu_model}', marker_color='#76b900'))
111 fig.update_layout(
112 title="PERFORMANCE GAP ANALYSIS",
113 paper_bgcolor='rgba(0,0,0,0)',
114 plot_bgcolor='rgba(0,0,0,0)',
115 font_color='#ccc',
116 height=300
117 )
118 st.plotly_chart(fig, use_container_width=True)
119else:
120 status_col.info("Waiting for execution command...")