I'm building some jupyter magic tooling as described in #8960. I need to be able to display the control flow graph for CUDA kernels. This PR adds an inspect_cfg method to CUDA kernels that returns the CFG as text in the dot language form. I plan on piping this output to the dot command line tool to display the digraph as an image in Jupyter notebooks. Ex:
digraph f { subgraph "add" { node [fontname="Courier",fontsize=10,shape=Mrecord]; "add" [add:\l\ \ MOV\ R1,\ c\[0x0\]\[0x28\]\ ;\l\ \ S2R\ R0,\ SR_TID.X\ ;\l\ \ S2R\ R3,\ SR_CTAID.X\ ;\l\ \ IMAD\ R0,\ R3,\ c\[0x0\]\[0x0\],\ R0\ ;\l\ \ ISETP.GE.U32.AND\ P0,\ PT,\ R0,\ c\[0x0\]\[0x188\],\ PT\ ;\l\ \ SHF.R.S32.HI\ R2,\ RZ,\ 0x1f,\ R0\ ;\l\ \ ISETP.GE.AND.EX\ P0,\ PT,\ R2,\ c\[0x0\]\[0x18c\],\ PT,\ P0\ ;\l|<exit0>\ \ @P0\ EXIT\ ;\l|<exitpost0>\ \ ISETP.GE.AND\ P0,\ PT,\ R0,\ RZ,\ PT\ ;\l\ \ ULDC.64\ UR4,\ c\[0x0\]\[0x118\]\ ;\l\ \ SEL\ R5,\ RZ,\ c\[0x0\]\[0x1c0\],\ P0\ ;\l\ \ SEL\ R3,\ RZ,\ c\[0x0\]\[0x188\],\ P0\ ;\l\ \ IADD3\ R6,\ P1,\ R0.reuse,\ R5,\ RZ\ ;\l\ \ IADD3\ R0,\ P2,\ R0,\ R3,\ RZ\ ;\l\ \ SEL\ R7,\ RZ,\ c\[0x0\]\[0x1c4\],\ P0\ ;\l\ \ SEL\ R3,\ RZ,\ c\[0x0\]\[0x18c\],\ P0\ ;\l\ \ IMAD.X\ R7,\ R2,\ 0x1,\ R7,\ P1\ ;\l\ \ LEA\ R4,\ P1,\ R0,\ c\[0x0\]\[0x180\],\ 0x2\ ;\l\ \ IMAD.X\ R3,\ R2,\ 0x1,\ R3,\ P2\ ;\l\ \ LEA\ R2,\ P0,\ R6,\ c\[0x0\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