How to output the Low-level IR instructions to a file in Glow?

(Vyronas) #1

I wish to generate the low-level IR and put it into a file for a specific test such as mnist.
I found the IRGen.cpp but there seems no function can export or save the low-level IR.
Is there any chance for me to do so?

The low-level IR may look like:

declare {
  %input = weight float<8 x 28 x 28 x 1>, broadcast, 0.0
  %filter = weight float<16 x 5 x 5 x 1>, xavier, 25.0
  %filter0 = weight float<16>, broadcast, 0.100
  %weights = weight float<10 x 144>, xavier, 144.0
  %bias = weight float<10>, broadcast, 0.100
  %selected = weight index<8 x 1>
  ...
  %result = weight float<8 x 10>
}

program {
  %allo = alloc float<8 x 28 x 28 x 16>
  %conv = convolution [5 1 2 16] @out %allo, @in %input, @in %filter3, @in %bias0
  %allo0 = alloc float<8 x 28 x 28 x 16>
  %relu = relu @out %allo0, @in %allo
  %allo1 = alloc index<8 x 9 x 9 x 16 x 2>
  %allo2 = alloc float<8 x 9 x 9 x 16>
  %pool = pool max [3 3 0] @out %allo2, @in %allo0, @inout %allo1
  ...
  %deal6 = dealloc @out %allo6
  %deal7 = dealloc @out %allo7
  %deal8 = dealloc @out %allo8
  %deal9 = dealloc @out %allo9
}

Thank you so much!

(Jordan Fix) #2

You can use the command line option -dump-ir, which will dump the low-level IR after all optimizations have been applied.

(Vyronas) #3

Should I use this command line while using cmake to compile?

(Vyronas) #4

Should I use this command line while using cmake to compile?

(Jordan Fix) #5

No. It’s built into the IR optimizer as a command line option when running different binaries. For example you can add it to the command line when running the image-classifier if you’re running mnist.

(Vyronas) #7

I got it. Thank you so much!

(Ritesh Gupta) #8

Hi, @Vyronas I also need dump Low level optimized IR to a file. Can you help in this regard? I’ve tried -dump-ir, but it is not generating any IR.