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

(Soumyaroop Roy) #1

Hi,

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.

-SR

1 Like
(Soumyaroop Roy) #2

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:

    F->dumpDAG("lenet.dot");

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

dot -Tpng -O lenet.dot

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);
    EE.getIR().dumpDAG("lenet_infer_ir.dot");

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);
    TF->dumpDAG("lenet_train.dot");
    EE.getIR().dumpDAG("lenet_train_ir.dot");

-SR

1 Like
(Quentin) #3

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