@@ -3,6 +3,20 @@ description: Export TT-Lang kernel to TT-Metal C++ kernel code
33argument-hint : <kernel-file>
44---
55
6+ ## Tools Available
7+
8+ ``` bash
9+ run-test.sh /path/to/kernel.py # Run kernel on VM simulator (ONLY way to test)
10+ copy-file.sh /path/to/file.py # Copy a file to the VM
11+ ```
12+
13+ ** Reading VM logs (output is saved, not streamed):**
14+ ``` bash
15+ limactl shell ttsim -- cat /tmp/ttlang_test_output.log # Full log
16+ limactl shell ttsim -- tail -100 /tmp/ttlang_test_output.log # Last 100 lines
17+ limactl shell ttsim -- grep -i " error" /tmp/ttlang_test_output.log
18+ ```
19+
620## Task
721
822Export a TT-Lang kernel to standalone TT-Metal C++ code with a Python entry point using ` ttnn.generic_op ` . The primary goal is a working, correct kernel that can run independently of ttlang.
@@ -361,18 +375,69 @@ cb_wait_front(/*lhs*/0, 1);
361375- Synchronization patterns (barriers, waits, etc.)
362376- Any logic or control flow
363377
364- ### Step 6: Verify the Export Works
378+ ### Step 6: Copy Files to VM and Test
379+
380+ **The VM is the ONLY place to test.** The exported kernel must be copied to the VM and run there.
381+
382+ #### File Structure on VM
383+
384+ When you copy files to the VM, they go to the user's home directory by default.
385+ The kernel paths in `run_kernel.py` must match where files are on the VM.
386+
387+ ```bash
388+ # Copy all files to VM
389+ copy-file.sh my_kernel/run_kernel.py
390+ copy-file.sh my_kernel/kernels/compute.cpp kernels/
391+ copy-file.sh my_kernel/kernels/reader.cpp kernels/
392+ copy-file.sh my_kernel/kernels/writer.cpp kernels/
393+ ```
394+
395+ This creates on the VM:
396+ ```
397+ /home/<user>/
398+ ├── run_kernel.py
399+ └── kernels/
400+ ├── compute.cpp
401+ ├── reader.cpp
402+ └── writer.cpp
403+ ```
404+
405+ #### Update Kernel Paths for VM
406+
407+ The ` kernel_source ` paths in ` run_kernel.py ` must be ** relative to where run_kernel.py is located on the VM** , or use absolute paths:
408+
409+ ``` python
410+ # Option 1: Relative paths (if run_kernel.py is in same dir as kernels/)
411+ reader_kernel = ttnn.KernelDescriptor(
412+ kernel_source = " kernels/reader.cpp" , # Relative to run_kernel.py location
413+ ...
414+ )
415+
416+ # Option 2: Absolute paths on VM
417+ reader_kernel = ttnn.KernelDescriptor(
418+ kernel_source = " /home/user/kernels/reader.cpp" ,
419+ ...
420+ )
421+ ```
422+
423+ #### Run the Test
365424
366425``` bash
367- cd my_kernel/
368- python run_kernel.py
426+ # Run the exported kernel on VM
427+ run-test.sh /path/to/my_kernel/run_kernel.py
428+
429+ # Check results
430+ limactl shell ttsim -- tail -50 /tmp/ttlang_test_output.log
369431```
370432
433+ #### Debugging Failures
434+
371435If it fails, check:
3724361 . CB indices in compute kernel match the CBDescriptor buffer_index values
3734372 . Tensor order in ` ttnn.generic_op([...]) ` matches kernel expectations
3744383 . Grid dimensions match between Python and original TTLang kernel
3754394 . Compile-time args order matches ` get_compile_time_arg_val(N) ` usage
440+ 5 . ** Kernel file paths are correct for the VM filesystem**
376441
377442## Key Data Structures Reference
378443
@@ -421,12 +486,53 @@ runtime_args = [
421486]
422487```
423488
489+ ## Workflow
490+
491+ ### Step A: Verify the TT-Lang Kernel Works First
492+
493+ Before exporting, confirm the original TT-Lang kernel runs correctly:
494+ ``` bash
495+ run-test.sh /path/to/original_kernel.py
496+ limactl shell ttsim -- tail -50 /tmp/ttlang_test_output.log
497+ ```
498+
499+ ** If the TT-Lang kernel doesn't work: STOP.** Ask the user to fix the original kernel first. Do not proceed with export until the source kernel is working.
500+
501+ ### Step B: Extract and Verify Generated C++
502+
503+ The TT-Lang compiler outputs working C++ to ` /tmp/ ` . Extract the three kernel files and verify they work with ` ttnn.generic_op ` before any beautification.
504+
505+ ### Step C: Beautify (Working > Beautiful)
506+
507+ Apply P2 beautification (rename variables, collapse casts, add comments). After each change:
508+ 1 . Copy updated files to VM
509+ 2 . Run test
510+ 3 . If it breaks, ** revert the change** - keep what works
511+
512+ ** A working kernel with ugly variable names is better than a broken kernel with nice names.**
513+
514+ ### Step D: Verify File Locations on VM
515+
516+ Use ` limactl ` to check file structure on VM:
517+ ``` bash
518+ limactl shell ttsim -- ls -la ~ /kernels/ # Check kernel files exist
519+ limactl shell ttsim -- pwd # Confirm working directory
520+ limactl shell ttsim -- cat ~ /kernels/compute.cpp # Verify file contents
521+ ```
522+
523+ This helps you set correct paths in the KernelDescriptor.
524+
424525## Output
425526
426527Write to the output directory:
4275281 . ` kernels/compute.cpp ` - Beautified compute kernel
4285292 . ` kernels/reader.cpp ` - Beautified reader kernel
4295303 . ` kernels/writer.cpp ` - Beautified writer kernel
430- 4 . ` run_kernel.py ` - Working Python entry point
431-
432- Verify the kernel runs correctly before finishing.
531+ 4 . ` run_kernel.py ` - Working Python entry point with correct VM paths
532+
533+ ** You MUST:**
534+ 1 . Verify the original TT-Lang kernel works before starting
535+ 2 . Copy all files to VM using ` copy-file.sh `
536+ 3 . Run ` run-test.sh ` on the exported kernel
537+ 4 . Read the log and confirm it runs correctly
538+ 5 . Only mark complete after successful VM execution
0 commit comments