Map high-level (graph) IR to low-level IR


I started looking into Glow compiler this week.

What is the recommended way to dump the dataflow graph for, say, the LeNet example here in dot format?

I see in Glow IR documentation:

“The compiler has a debug method for dumping a graphical representation of the graph into a dotty file. The method is called ‘dumpDAG’. The images above were generated with this method. The textual representation of the graph is less informative and it looks like this…”

However, I’m not sure I see a cmdline option to dump such a representation. Is that right? Do I need to hack it? I see that a -dump-llvm-ir option is available to dump the LLVM-IR of the jitted code.

My objective is to understand (visually) the mapping of the high-level constructs captured by the high-level IR to the linear algebra primitives with which the low-level IR is comprised.


1 Like

Made some progress here. Documenting for posterity.

In the context of the LeNet example here, described in C++, adding the following will dump the network DAG:


The dumped DAG is the one that’s shown in the link above. Run the following to generate the image:

dot -Tpng -O

To dump the low-level IR for the compilation unit — a function at a time as I understand (is that right?) — add the following:

    // Compile for inference
    EE.compile(CompilationMode::Infer, F);

Alternately, to dump the training graph and the IR DAG for the training network, add the following:

    // Set up training of the network
    EE.getConfig().learningRate = 0.1;
    EE.getConfig().momentum = 0;
    EE.getConfig().batchSize = minibatchSize;

    Function *TF = glow::differentiate(F, EE.getConfig());
    // Compile for training
    EE.compile(CompilationMode::Train, TF);


1 Like

To add on the answer, if you run something that use the loader (Loader.cpp), you can use the command line option -dumpGraphDAG=<> to dump the graph using the .dot format.

Can we get the dumpDAG output for the python model too like in C++?