Spaces:
Running
on
T4
Running
on
T4
File size: 2,757 Bytes
b050f40 f296a59 b050f40 b21a295 b050f40 e830b9f b050f40 50764c0 b050f40 |
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 |
import os, tempfile, time
import gradio as gr
from tool.testv3 import run_autotune_pipeline
# ---------- Core callback ----------
def generate_kernel(text_input, n_iters, progress=gr.Progress()):
"""
text_input : string from textbox (NL description or base CUDA code)
file_input : gr.File upload object (or None)
Returns : (kernel_code_str, downloadable_file_path)
"""
progress((0, n_iters), desc="Initializing...")
# 1) Select input source
if not text_input.strip():
return "⚠️ Please paste a description or baseline CUDA code.", "", None
td = tempfile.mkdtemp(prefix="auto_")
src_path = os.path.join(td, f"input_{int(time.time())}.txt")
with open(src_path, "w") as f:
f.write(text_input)
best_code = ""
for info in run_autotune_pipeline(src_path, n_iters):
# 1) update progress bar (if iteration known)
if info["event"] == "iteration_end" and info["iteration"] is not None:
# print(f"Iteration {info['iteration']} / {n_iters}: {info['message']}")
progress((info["iteration"], n_iters), desc=info["message"])
# 3) kernel output only when we get new code
if info["code"]:
best_code = info["code"]
# last yield enables the download button
return best_code
# ---------- Gradio UI ----------
with gr.Blocks(title="KernelPilot", theme=gr.themes.Soft(text_size="lg", font=[
"system-ui",
"-apple-system",
"BlinkMacSystemFont",
"Segoe UI",
"Roboto",
"Helvetica Neue",
"Arial",
"Noto Sans",
"sans-serif"
])) as demo:
gr.Markdown(
"""# 🚀 KernelPilot
Enter a natural‑language description,
then click **Generate** to obtain the kernel function."""
)
with gr.Row():
txt_input = gr.Textbox(
label="📝 Input",
lines=10,
placeholder="Describe the kernel",
scale=3
)
level = gr.Number(
label="Optimization Level",
minimum=1,
maximum=5,
value=2,
step=1,
scale=1
)
gen_btn = gr.Button("⚡ Generate")
kernel_output = gr.Code(
label="🎯 Tuned CUDA Kernel",
language="cpp"
)
gen_btn.click(
fn=generate_kernel,
inputs=[txt_input, level],
outputs=[kernel_output],
queue=True, # keeps requests queued
show_progress=True, # show progress bar
show_progress_on=kernel_output # update log box with progress
)
if __name__ == "__main__":
demo.queue(default_concurrency_limit=1, max_size=50)
demo.launch(server_name="0.0.0.0", server_port=7860) |