Awesome
coda
CODA: Burst Compiler Static Code Analysis
CODA is a static code analysis tool for the new burst compiler in Unity. It works by parsing the assembly language code output by the BurstCompiler Inspector, running the code through llvm-mca (with some sanitizations since llvm-mca cannot directly parse the code generated by the Burst Inspector). The output will show a graphical timeline of each instruction and how long it would take to run on the selected CPU (see limitations below), a profile report which can associate the timeline with your original C# burst job code (if you have enhanced disassembly turned on) and the detailed report produced by llvm-mca. If you've used llvm-mca or Intel's IACA tool before, you should feel right at home.
Bug reports and PRs are welcome!
Note: This is a personal hackathon project written in 12 hours. Here there be dragons. Windows ONLY for now.
Static analysis tools are best used to analyze a kernel with no branches, calls or other conditionals. To support this, I've added a begin and end marker function call which will show up in the assembly output by the burst inspector and can be used to feed the correct instruction block to llvm-mca for analysis.
Since this is a quickly hacked together static analysis tool, there are a number of limitations:
- Loops will only be analyzed as if they ran a single time (static analysis doesn't "see" jump instructions)
- Conditional branches are currently ignored and the contents are not analyzed
- Calls are not analyzed and are currently ignored, counted as executing in zero cycles
- Static analysis of code with optimizations turned on is not currently supported due to the difficulty of mapping optimized assembly back to original C# source lines
- It's recommended to turn off safety checks in the generated assembly to make the output more clear.
Installing
For now, the way to install this tool is to clone the project and copy the project contents to your Unity project assets folder under Assets/TapVoxel/Coda
The tool currently makes some assumptions about this path, so use exactly the path above.
Once copied to your project, you can run it by accessing the menu item Window / TapVoxel / Coda / Show Coda Manager
Running an analysis
- Start the Burst Inspector and select your burst job in the left-hand side. The recommended options are:
- Enhanced Disassembly ON
- Safety Checks OFF
- Optimizations OFF
- Fast Math ON
- Click
Refresh Disassembly
- Click
Copy to Clipboard
- Start the Coda Manager if you haven't already
- Chose which CPU you'd like to run the simulation on
- Click
Paste Assembly Code and Analyze
At this point, the timeline should be populated and you should be able to click on the Show profile analysis
and Show detailed analysis
buttons.
Screenshots
Future
I'd like to get this running on Mac and Linux. To do so, llvm-mca needs to be available on each platform and the tool needs to be modified to run llvm-mca from the path. Otherwise the code is mostly just plain old (rusty) C# and should be reasonably portable.