MCPcopy Create free account
hub / github.com/RightNow-AI/autokernel / extract_kernel_body

Function extract_kernel_body

extract.py:262–287  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

260
261
262def 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
290def generate_kernel_file(

Callers 1

generate_kernel_fileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected