Extract the Triton kernel code from a starter file, stripping the original module docstring and KERNEL_TYPE declaration (which we replace in the template header). Returns everything from the first 'import' statement onward.
(starter_code: str)
| 260 | |
| 261 | |
| 262 | def extract_kernel_body(starter_code: str) -> str: |
| 263 | """ |
| 264 | Extract the Triton kernel code from a starter file, stripping the |
| 265 | original module docstring and KERNEL_TYPE declaration (which we replace |
| 266 | in the template header). |
| 267 | |
| 268 | Returns everything from the first 'import' statement onward. |
| 269 | """ |
| 270 | lines = starter_code.split("\n") |
| 271 | |
| 272 | # Find the first import line |
| 273 | import_idx = None |
| 274 | for i, line in enumerate(lines): |
| 275 | stripped = line.strip() |
| 276 | if stripped.startswith("import ") or stripped.startswith("from "): |
| 277 | import_idx = i |
| 278 | break |
| 279 | |
| 280 | if import_idx is not None: |
| 281 | return "\n".join(lines[import_idx:]) |
| 282 | else: |
| 283 | # Fallback: return everything after KERNEL_TYPE line |
| 284 | for i, line in enumerate(lines): |
| 285 | if line.strip().startswith("KERNEL_TYPE"): |
| 286 | return "\n".join(lines[i + 1:]) |
| 287 | return starter_code |
| 288 | |
| 289 | |
| 290 | def generate_kernel_file( |
no outgoing calls
no test coverage detected