File size: 6,070 Bytes
e03ae4e
 
e2f4da8
 
e03ae4e
 
 
 
 
 
 
 
 
 
 
e2f4da8
 
 
 
 
 
 
e03ae4e
 
e2f4da8
 
 
ed29027
e03ae4e
 
 
ed29027
e03ae4e
e2f4da8
 
 
e03ae4e
e2f4da8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e03ae4e
 
 
 
 
 
e2f4da8
e03ae4e
 
ed29027
 
 
e03ae4e
e2f4da8
 
e03ae4e
 
ed29027
 
 
e2f4da8
 
ed29027
e2f4da8
 
 
 
ed29027
 
 
e03ae4e
ed29027
 
 
 
 
 
e2f4da8
 
ed29027
e2f4da8
ed29027
 
e03ae4e
 
 
ed29027
 
 
 
 
 
e2f4da8
 
ed29027
e2f4da8
ed29027
e03ae4e
ed29027
 
 
 
 
 
 
 
 
 
 
 
e03ae4e
 
ed29027
e03ae4e
 
ed29027
e03ae4e
ed29027
e03ae4e
e2f4da8
e03ae4e
 
 
 
 
 
 
 
 
ed29027
 
e03ae4e
 
 
 
e2f4da8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
"use client";

import { useState, useEffect } from "react";
import { motion } from "framer-motion";

type NodeStatus = "ACTIVE" | "IDLE" | "OVERLOADED" | "FAILED";

interface GPUNode {
  id: string;
  utilization: number;
  memory: number;
  load: number;
  status: NodeStatus;
}

interface GPUClusterPanelProps {
  sessionId?: string;
  mode?: string;
  gpuPool?: any[]; // Live data from observation
}

export default function GPUClusterPanel({ sessionId, mode, gpuPool }: GPUClusterPanelProps) {
  const [mounted, setMounted] = useState(false);
  const [nodes, setNodes] = useState<GPUNode[]>([
    { id: "GPU-1", utilization: 0, memory: 0, load: 0, status: "IDLE" },
    { id: "GPU-2", utilization: 0, memory: 0, load: 0, status: "IDLE" },
    { id: "GPU-3", utilization: 0, memory: 0, load: 0, status: "IDLE" },
    { id: "GPU-4", utilization: 0, memory: 0, load: 0, status: "IDLE" },
  ]);

  const [avgLoad, setAvgLoad] = useState(0);
  const [jitter, setJitter] = useState(0.45);

  useEffect(() => { setMounted(true); }, []);

  // ── LIVE SYNC FROM OBSERVATION ────────────────────────────
  useEffect(() => {
    if (gpuPool && Array.isArray(gpuPool)) {
      setNodes(gpuPool.slice(0, 4).map((g: any) => {
        const util = (g.memory_used / g.memory_total) * 100;
        let status = g.state.toUpperCase();
        if (status === "ALLOCATED") status = "ACTIVE";
        
        return {
          id: g.id,
          utilization: util,
          memory: util,
          load: (util / 100) * 4.2,
          status: status as NodeStatus
        };
      }));
    } else if (!sessionId || mode !== "cluster") {
      // Fallback to subtle idle simulation if no live data
      const timer = setInterval(() => {
        setJitter(Math.random() * 0.5);
        setNodes(prev => prev.map(n => ({
          ...n,
          utilization: Math.max(0, n.utilization + (Math.random() - 0.5) * 2),
          load: n.utilization * 0.04
        })));
      }, 2000);
      return () => clearInterval(timer);
    }
  }, [gpuPool, sessionId, mode]);

  useEffect(() => {
    const total = nodes.reduce((acc, n) => acc + n.utilization, 0);
    setAvgLoad(total / nodes.length);
  }, [nodes]);

  if (!mounted) return null;

  return (
    <section className="section-block" id="gpu-cluster">
      <div className="section-label">03 // COMPUTE RESOURCES</div>
      <h2 className="section-title">GPU Compute Clusters</h2>
      <p className="section-desc">
        Real-time telemetry from the underlying inference hardware. 
        Note how cluster utilization spikes as the RL model allocates worker jobs.
      </p>

      <div className="cluster-grid">
        {nodes.map((node) => (
          <div key={node.id} className={`card node-card ${node.status.toLowerCase()}`}>
            <div className="card-id">{node.id} // CORE-AX-{node.id.split("-")[1] || "0X"}</div>
            
            <div className="node-status-badge">
              <div className="status-dot" style={{ 
                background: node.status === "ACTIVE" ? "var(--green)" :
                            node.status === "OVERLOADED" ? "var(--red)" : 
                            node.status === "FAILED" ? "#555" : "var(--muted)" 
              }} />
              {node.status}
            </div>

            <div className="metric-bar-wrap" style={{ marginTop: 20 }}>
              <div className="metric-bar-label">
                <span>UTILIZATION</span>
                <span style={{ color: "var(--cyan)" }}>{Math.round(node.utilization)}%</span>
              </div>
              <div className="metric-bar-bg">
                <motion.div 
                  className="metric-bar-fill" 
                  animate={{ width: `${node.utilization}%` }}
                  transition={{ type: "spring", stiffness: 100, damping: 20 }}
                  style={{ background: node.utilization > 90 ? "var(--red)" : "var(--cyan)" } as any}
                />
              </div>
            </div>

            <div className="metric-bar-wrap" style={{ marginTop: 12 }}>
              <div className="metric-bar-label">
                <span>MEMORY USAGE</span>
                <span style={{ color: "var(--green)" }}>{Math.round(node.memory)}%</span>
              </div>
              <div className="metric-bar-bg">
                <motion.div 
                  className="metric-bar-fill" 
                  animate={{ width: `${node.memory}%` }}
                  transition={{ type: "spring", stiffness: 100, damping: 20 }}
                  style={{ background: "var(--green)" } as any}
                />
              </div>
            </div>

            <div className="node-footer-stats">
              <div className="node-stat">
                <span className="label">COMPUTE</span>
                <span className="val">{node.load.toFixed(1)} TFLOPS</span>
              </div>
              <div className="node-stat">
                <span className="label">TEMP</span>
                <span className="val">{Math.round(40 + (node.utilization * 0.4))}Β°C</span>
              </div>
            </div>
          </div>
        ))}
      </div>

      <div className="cluster-footer">
        <div className="cluster-total-load">
          <span className="label">TOTAL CLUSTER LOAD</span>
          <div className="load-meter-bg">
            <motion.div 
              className="load-meter-fill"
              animate={{ width: `${avgLoad}%` }}
              style={{ background: avgLoad > 80 ? "var(--red)" : "var(--cyan)", color: avgLoad > 80 ? "var(--red)" : "var(--cyan)" } as any}
            />
          </div>
          <span className="val">{Math.round(avgLoad)}%</span>
        </div>
        <div className="cluster-telemetry">
          <span>THROUGHPUT: <b>{Math.round(140 - (avgLoad * 0.5))} FPS</b></span>
          <span>LATENCY: <b>{Math.round(12 + (avgLoad * 0.2))}ms</b></span>
          <span>JITTER: <b>{jitter.toFixed(2)}ms</b></span>
        </div>
      </div>
    </section>
  );
}