Fix Gradio 6 compat: move theme/css to launch(), language cpp
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
"""
|
| 2 |
-
ROCmPort AI
|
| 3 |
Calls the deployed FastAPI backend (Render) and streams agent events.
|
| 4 |
"""
|
| 5 |
|
|
@@ -10,19 +10,19 @@ import json
|
|
| 10 |
BACKEND_URL = "https://rocmport-ai-q2b1.onrender.com"
|
| 11 |
|
| 12 |
AGENT_ICONS = {
|
| 13 |
-
"analyzer": "
|
| 14 |
-
"translator": "
|
| 15 |
-
"optimizer": "
|
| 16 |
-
"tester": "
|
| 17 |
-
"coordinator": "
|
| 18 |
}
|
| 19 |
|
| 20 |
STATUS_ICONS = {
|
| 21 |
-
"waiting": "
|
| 22 |
-
"running": "
|
| 23 |
-
"done": "
|
| 24 |
-
"failed": "
|
| 25 |
-
"retrying": "
|
| 26 |
}
|
| 27 |
|
| 28 |
EXAMPLE_REDUCTION = """\
|
|
@@ -85,7 +85,7 @@ __global__ void matmul(float *A, float *B, float *C, int N) {
|
|
| 85 |
def port_kernel(cuda_code: str, kernel_name: str, simple_mode: bool):
|
| 86 |
"""Generator: streams agent events and yields (log_markdown, hip_code)."""
|
| 87 |
if not cuda_code or len(cuda_code.strip()) < 10:
|
| 88 |
-
yield "
|
| 89 |
return
|
| 90 |
|
| 91 |
kernel_name = kernel_name.strip() or "custom"
|
|
@@ -98,7 +98,7 @@ def port_kernel(cuda_code: str, kernel_name: str, simple_mode: bool):
|
|
| 98 |
"simple_mode": bool(simple_mode),
|
| 99 |
}
|
| 100 |
|
| 101 |
-
log_lines.append("
|
| 102 |
yield "\n\n".join(log_lines), hip_code
|
| 103 |
|
| 104 |
try:
|
|
@@ -126,10 +126,10 @@ def port_kernel(cuda_code: str, kernel_name: str, simple_mode: bool):
|
|
| 126 |
message = event.get("message", "")
|
| 127 |
detail = event.get("detail") or ""
|
| 128 |
|
| 129 |
-
icon = AGENT_ICONS.get(agent, "
|
| 130 |
-
s_icon = STATUS_ICONS.get(status, "
|
| 131 |
|
| 132 |
-
log_lines.append(f"{icon} **{agent.capitalize()}** {s_icon}
|
| 133 |
|
| 134 |
# Extract HIP code from coordinator or translator done events
|
| 135 |
if status == "done" and detail:
|
|
@@ -150,65 +150,61 @@ def port_kernel(cuda_code: str, kernel_name: str, simple_mode: bool):
|
|
| 150 |
|
| 151 |
except httpx.ConnectError:
|
| 152 |
log_lines.append(
|
| 153 |
-
"
|
| 154 |
-
"> The server may be in a cold-start state
|
| 155 |
)
|
| 156 |
yield "\n\n".join(log_lines), hip_code
|
| 157 |
return
|
| 158 |
except httpx.TimeoutException:
|
| 159 |
-
log_lines.append("
|
| 160 |
yield "\n\n".join(log_lines), hip_code
|
| 161 |
return
|
| 162 |
except httpx.HTTPStatusError as exc:
|
| 163 |
-
log_lines.append(f"
|
| 164 |
yield "\n\n".join(log_lines), hip_code
|
| 165 |
return
|
| 166 |
except Exception as exc: # noqa: BLE001
|
| 167 |
-
log_lines.append(f"
|
| 168 |
yield "\n\n".join(log_lines), hip_code
|
| 169 |
return
|
| 170 |
|
| 171 |
if not hip_code:
|
| 172 |
-
log_lines.append("\n
|
| 173 |
else:
|
| 174 |
-
log_lines.append("\n
|
| 175 |
|
| 176 |
yield "\n\n".join(log_lines), hip_code
|
| 177 |
|
| 178 |
|
| 179 |
-
#
|
| 180 |
|
| 181 |
CSS = """
|
| 182 |
.panel-header { font-weight: 600; font-size: 1rem; margin-bottom: 4px; }
|
| 183 |
footer { display: none !important; }
|
| 184 |
"""
|
| 185 |
|
| 186 |
-
with gr.Blocks(
|
| 187 |
-
title="ROCmPort AI — CUDA → ROCm Migration",
|
| 188 |
-
theme=gr.themes.Default(primary_hue="orange"),
|
| 189 |
-
css=CSS,
|
| 190 |
-
) as demo:
|
| 191 |
|
| 192 |
gr.Markdown(
|
| 193 |
-
"""#
|
| 194 |
-
### Agentic CUDA
|
| 195 |
|
| 196 |
> **Backend API**: [rocmport-ai-q2b1.onrender.com](https://rocmport-ai-q2b1.onrender.com) |
|
| 197 |
> **GitHub**: [tazwaryayyyy/ROCmPort-AI](https://github.com/tazwaryayyyy/ROCmPort-AI)
|
| 198 |
|
| 199 |
-
`hipify-clang` translates CUDA API calls mechanically
|
| 200 |
-
warp-level reduction silently skips lanes 32
|
| 201 |
The code compiles, the output is wrong, no errors. **ROCmPort AI catches this before execution.**
|
| 202 |
"""
|
| 203 |
)
|
| 204 |
|
| 205 |
with gr.Row():
|
| 206 |
-
#
|
| 207 |
with gr.Column(scale=1):
|
| 208 |
-
gr.Markdown("###
|
| 209 |
cuda_input = gr.Code(
|
| 210 |
label="CUDA Kernel Code",
|
| 211 |
-
language="
|
| 212 |
lines=22,
|
| 213 |
value=EXAMPLE_REDUCTION,
|
| 214 |
)
|
|
@@ -225,8 +221,8 @@ The code compiles, the output is wrong, no errors. **ROCmPort AI catches this be
|
|
| 225 |
scale=1,
|
| 226 |
)
|
| 227 |
with gr.Row():
|
| 228 |
-
port_btn = gr.Button("
|
| 229 |
-
clear_btn = gr.Button("
|
| 230 |
|
| 231 |
gr.Examples(
|
| 232 |
examples=[
|
|
@@ -238,16 +234,16 @@ The code compiles, the output is wrong, no errors. **ROCmPort AI catches this be
|
|
| 238 |
label="Demo Kernels (pre-loaded with intentional AMD bugs)",
|
| 239 |
)
|
| 240 |
|
| 241 |
-
#
|
| 242 |
with gr.Column(scale=1):
|
| 243 |
-
gr.Markdown("###
|
| 244 |
log_output = gr.Markdown(
|
| 245 |
value="*Agent steps will appear here once you click **Port to ROCm**.*",
|
| 246 |
label="Agent Pipeline Log",
|
| 247 |
)
|
| 248 |
hip_output = gr.Code(
|
| 249 |
label="Translated & Optimized HIP Code",
|
| 250 |
-
language="
|
| 251 |
lines=18,
|
| 252 |
)
|
| 253 |
|
|
@@ -258,16 +254,16 @@ The code compiles, the output is wrong, no errors. **ROCmPort AI catches this be
|
|
| 258 |
|
| 259 |
| Agent | Role |
|
| 260 |
|-------|------|
|
| 261 |
-
|
|
| 262 |
-
|
|
| 263 |
-
|
|
| 264 |
-
|
|
| 265 |
-
|
|
| 266 |
|
| 267 |
### The key bug: warp-size assumption
|
| 268 |
|
| 269 |
```c
|
| 270 |
-
// NVIDIA (warpSize = 32)
|
| 271 |
if (tid < 32) { vsmem[tid] += vsmem[tid + 32]; ... }
|
| 272 |
|
| 273 |
// AMD-correct (wavefront = 64)
|
|
@@ -281,16 +277,16 @@ if (tid < 64) {
|
|
| 281 |
|
| 282 |
| Kernel | Result |
|
| 283 |
|--------|--------|
|
| 284 |
-
| matrix_multiply 512
|
| 285 |
| vector_add 32 M elements | ~3 918 GB/s (~74 % of MI300X peak) |
|
| 286 |
| reduction 16 M elements | correctness PASS after wavefront-64 fix |
|
| 287 |
|
| 288 |
-
> Source: `docs/benchmark_runs/`
|
| 289 |
> Results vary with kernel complexity; these figures are not guaranteed on every input.
|
| 290 |
"""
|
| 291 |
)
|
| 292 |
|
| 293 |
-
#
|
| 294 |
port_btn.click(
|
| 295 |
fn=port_kernel,
|
| 296 |
inputs=[cuda_input, kernel_name, simple_mode],
|
|
@@ -303,4 +299,4 @@ if (tid < 64) {
|
|
| 303 |
)
|
| 304 |
|
| 305 |
if __name__ == "__main__":
|
| 306 |
-
demo.launch()
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ROCmPort AI ΓÇö Gradio Space entry point
|
| 3 |
Calls the deployed FastAPI backend (Render) and streams agent events.
|
| 4 |
"""
|
| 5 |
|
|
|
|
| 10 |
BACKEND_URL = "https://rocmport-ai-q2b1.onrender.com"
|
| 11 |
|
| 12 |
AGENT_ICONS = {
|
| 13 |
+
"analyzer": "🔍",
|
| 14 |
+
"translator": "🔄",
|
| 15 |
+
"optimizer": "ΓÜí",
|
| 16 |
+
"tester": "🧪",
|
| 17 |
+
"coordinator": "🎯",
|
| 18 |
}
|
| 19 |
|
| 20 |
STATUS_ICONS = {
|
| 21 |
+
"waiting": "⏳",
|
| 22 |
+
"running": "🔄",
|
| 23 |
+
"done": "✅",
|
| 24 |
+
"failed": "❌",
|
| 25 |
+
"retrying": "🔁",
|
| 26 |
}
|
| 27 |
|
| 28 |
EXAMPLE_REDUCTION = """\
|
|
|
|
| 85 |
def port_kernel(cuda_code: str, kernel_name: str, simple_mode: bool):
|
| 86 |
"""Generator: streams agent events and yields (log_markdown, hip_code)."""
|
| 87 |
if not cuda_code or len(cuda_code.strip()) < 10:
|
| 88 |
+
yield "❌ Please provide CUDA kernel code (at least 10 characters).", ""
|
| 89 |
return
|
| 90 |
|
| 91 |
kernel_name = kernel_name.strip() or "custom"
|
|
|
|
| 98 |
"simple_mode": bool(simple_mode),
|
| 99 |
}
|
| 100 |
|
| 101 |
+
log_lines.append("🚀 **Connecting to ROCmPort AI backend…**")
|
| 102 |
yield "\n\n".join(log_lines), hip_code
|
| 103 |
|
| 104 |
try:
|
|
|
|
| 126 |
message = event.get("message", "")
|
| 127 |
detail = event.get("detail") or ""
|
| 128 |
|
| 129 |
+
icon = AGENT_ICONS.get(agent, "🤖")
|
| 130 |
+
s_icon = STATUS_ICONS.get(status, "ΓÇó")
|
| 131 |
|
| 132 |
+
log_lines.append(f"{icon} **{agent.capitalize()}** {s_icon} ΓÇö {message}")
|
| 133 |
|
| 134 |
# Extract HIP code from coordinator or translator done events
|
| 135 |
if status == "done" and detail:
|
|
|
|
| 150 |
|
| 151 |
except httpx.ConnectError:
|
| 152 |
log_lines.append(
|
| 153 |
+
"❌ **Could not connect to backend.**\n\n"
|
| 154 |
+
"> The server may be in a cold-start state ΓÇö please wait ~30 s and retry."
|
| 155 |
)
|
| 156 |
yield "\n\n".join(log_lines), hip_code
|
| 157 |
return
|
| 158 |
except httpx.TimeoutException:
|
| 159 |
+
log_lines.append("⏱️ **Request timed out.** The pipeline may still be running — try again shortly.")
|
| 160 |
yield "\n\n".join(log_lines), hip_code
|
| 161 |
return
|
| 162 |
except httpx.HTTPStatusError as exc:
|
| 163 |
+
log_lines.append(f"❌ **HTTP {exc.response.status_code}**: {exc.response.text[:300]}")
|
| 164 |
yield "\n\n".join(log_lines), hip_code
|
| 165 |
return
|
| 166 |
except Exception as exc: # noqa: BLE001
|
| 167 |
+
log_lines.append(f"❌ **Unexpected error**: {exc}")
|
| 168 |
yield "\n\n".join(log_lines), hip_code
|
| 169 |
return
|
| 170 |
|
| 171 |
if not hip_code:
|
| 172 |
+
log_lines.append("\n⚠️ Pipeline finished but no HIP code was extracted. Check agent logs above.")
|
| 173 |
else:
|
| 174 |
+
log_lines.append("\n✅ **Migration complete.** HIP code is shown on the right →")
|
| 175 |
|
| 176 |
yield "\n\n".join(log_lines), hip_code
|
| 177 |
|
| 178 |
|
| 179 |
+
# ΓöÇΓöÇ UI ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö��ΓöÇΓöÇΓöÇΓöÇ
|
| 180 |
|
| 181 |
CSS = """
|
| 182 |
.panel-header { font-weight: 600; font-size: 1rem; margin-bottom: 4px; }
|
| 183 |
footer { display: none !important; }
|
| 184 |
"""
|
| 185 |
|
| 186 |
+
with gr.Blocks(title="ROCmPort AI — CUDA to ROCm Migration") as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
gr.Markdown(
|
| 189 |
+
"""# ΓÜí ROCmPort AI
|
| 190 |
+
### Agentic CUDA → ROCm/HIP migration with wavefront-64 bug detection
|
| 191 |
|
| 192 |
> **Backend API**: [rocmport-ai-q2b1.onrender.com](https://rocmport-ai-q2b1.onrender.com) |
|
| 193 |
> **GitHub**: [tazwaryayyyy/ROCmPort-AI](https://github.com/tazwaryayyyy/ROCmPort-AI)
|
| 194 |
|
| 195 |
+
`hipify-clang` translates CUDA API calls mechanically ΓÇö it **cannot** detect that `if (tid < 32)` in a
|
| 196 |
+
warp-level reduction silently skips lanes 32ΓÇô63 on AMD wavefront-64.
|
| 197 |
The code compiles, the output is wrong, no errors. **ROCmPort AI catches this before execution.**
|
| 198 |
"""
|
| 199 |
)
|
| 200 |
|
| 201 |
with gr.Row():
|
| 202 |
+
# ΓöÇΓöÇ Left: input ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
|
| 203 |
with gr.Column(scale=1):
|
| 204 |
+
gr.Markdown("### 📥 Input", elem_classes="panel-header")
|
| 205 |
cuda_input = gr.Code(
|
| 206 |
label="CUDA Kernel Code",
|
| 207 |
+
language="cpp",
|
| 208 |
lines=22,
|
| 209 |
value=EXAMPLE_REDUCTION,
|
| 210 |
)
|
|
|
|
| 221 |
scale=1,
|
| 222 |
)
|
| 223 |
with gr.Row():
|
| 224 |
+
port_btn = gr.Button("ΓÜí Port to ROCm", variant="primary", scale=3)
|
| 225 |
+
clear_btn = gr.Button("🗑 Clear", scale=1)
|
| 226 |
|
| 227 |
gr.Examples(
|
| 228 |
examples=[
|
|
|
|
| 234 |
label="Demo Kernels (pre-loaded with intentional AMD bugs)",
|
| 235 |
)
|
| 236 |
|
| 237 |
+
# ΓöÇΓöÇ Right: output ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
|
| 238 |
with gr.Column(scale=1):
|
| 239 |
+
gr.Markdown("### 📤 Output", elem_classes="panel-header")
|
| 240 |
log_output = gr.Markdown(
|
| 241 |
value="*Agent steps will appear here once you click **Port to ROCm**.*",
|
| 242 |
label="Agent Pipeline Log",
|
| 243 |
)
|
| 244 |
hip_output = gr.Code(
|
| 245 |
label="Translated & Optimized HIP Code",
|
| 246 |
+
language="cpp",
|
| 247 |
lines=18,
|
| 248 |
)
|
| 249 |
|
|
|
|
| 254 |
|
| 255 |
| Agent | Role |
|
| 256 |
|-------|------|
|
| 257 |
+
| 🔍 **Analyzer** | Scans CUDA for AMD-specific risks: wavefront size, ballot/shuffle idioms, shared-memory layout |
|
| 258 |
+
| 🔄 **Translator** | Runs `hipify` then applies LLM-guided fixes for bugs `hipify` cannot detect |
|
| 259 |
+
| 🧪 **Tester** | Verifies compilation with `hipcc` and checks output correctness |
|
| 260 |
+
| ΓÜí **Optimizer** | Proposes MI300X-specific optimisations; re-tested against baseline |
|
| 261 |
+
| 🎯 **Coordinator** | Orchestrates the loop; retries up to 3× if the optimised output regresses |
|
| 262 |
|
| 263 |
### The key bug: warp-size assumption
|
| 264 |
|
| 265 |
```c
|
| 266 |
+
// NVIDIA (warpSize = 32) ΓÇö silently WRONG on AMD
|
| 267 |
if (tid < 32) { vsmem[tid] += vsmem[tid + 32]; ... }
|
| 268 |
|
| 269 |
// AMD-correct (wavefront = 64)
|
|
|
|
| 277 |
|
| 278 |
| Kernel | Result |
|
| 279 |
|--------|--------|
|
| 280 |
+
| matrix_multiply 512×512 | 2.91× speedup over baseline HIP |
|
| 281 |
| vector_add 32 M elements | ~3 918 GB/s (~74 % of MI300X peak) |
|
| 282 |
| reduction 16 M elements | correctness PASS after wavefront-64 fix |
|
| 283 |
|
| 284 |
+
> Source: `docs/benchmark_runs/` ΓÇö real `rocprof` CSV output, May 2026.
|
| 285 |
> Results vary with kernel complexity; these figures are not guaranteed on every input.
|
| 286 |
"""
|
| 287 |
)
|
| 288 |
|
| 289 |
+
# ΓöÇΓöÇ Event wiring ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
|
| 290 |
port_btn.click(
|
| 291 |
fn=port_kernel,
|
| 292 |
inputs=[cuda_input, kernel_name, simple_mode],
|
|
|
|
| 299 |
)
|
| 300 |
|
| 301 |
if __name__ == "__main__":
|
| 302 |
+
demo.launch(theme=gr.themes.Default(primary_hue="orange"), css=CSS)
|