How to check the flow of execution(programs , functions invocations)

username: Kittu28
cooked: <p>The following command is present in ModelLoader.md</p>
<p>${GLOW_PATH}/build/bin/image-classifier ${GLOW_PATH}/tests/images/imagenet/cat_285.png -image-mode=0to1 -m resnet18.onnx -model-input-name=data -cpu</p>
<p>and it gives the following output when run:</p>
<p>Model: resnet18.onnx<br>
File: ${GLOW_PATH}/tests/images/imagenet/cat_285.png   Label-K1: 285 (probability: 16.4305)</p>
<p>Please excuse me if its a trivial one …So my question is  , Is there any way to see the flow of execution of that command like what all programs are being executed in which order something like that…?</p>

username: jfix
cooked: <p>Hi <a class="mention" href="/u/kittu28">@Kittu28</a>, are you asking about understanding all of the different components a model travels through from entering the <code>image-classifier</code> until a result is produced and printed? I’m not sure there’s a super solid way other than adding breakpoints and stepping into the program as it executes. I can give you a high level overview of what’s happening if that is of use.</p>

username: Kittu28
cooked: <p>Yes please give me a high level overview of what’s happening.<br>
and also how can I add the breakpoints in the code? I don’t know which all programs are being executed.</p>

username: jfix
cooked: <p>RE: the breakpoint, you could just add a break to main and then follow the flow on down into function calls.</p>
<p>The overall flow looks like:</p>
<ul>
<li>Load the model. This can be e.g. ONNX, Caffe2, etc. This will iterate over a protobuf for the model and create one or more Glow Nodes for every op in the model.</li>
<li>Optimize the Node IR (GraphOptimizer.cpp)</li>
<li>Quantize/add profiling nodes, and/or convert to fp16, if requested</li>
<li>Optimize Node IR some more</li>
<li>If requested by the backend, lower to other Nodes, e.g. take an LSTM and lower it to constituent nodes such as Mul, Add, Sigmoid, Tanh, etc. (Lower.cpp)</li>
<li>Optimize Node IR some more</li>
<li>Either load into the backend’s API here at Node IR level, or lower to Glow Instruction level (IRGen.cpp)
<ul>
<li>If using Instruction IR, perform Instruction-level optimizations (IROptimizer.cpp)</li>
</ul>
</li>
<li>Backend produces some binary at this point as a [Backend]CompiledFunction object</li>
<li>Host Runtime (HostManager.cpp) now takes that CompiledFunction object and deploys to a device if needed (Provisioner.cpp)</li>
<li>For image-classifier, then images are loaded in and converted/normalized if needed, and then passed in as input tensors to the CompiledFunction to run. Results are returned and processed in image-classifier to determine the most likely label, and that’s printed.</li>
</ul>
<p>It may be useful to take a look at our documentation on our IR:</p><aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/pytorch/glow/blob/master/docs/IR.md" target="_blank" rel="noopener nofollow ugc">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/glow/blob/master/docs/IR.md" target="_blank" rel="noopener nofollow ugc">pytorch/glow/blob/master/docs/IR.md</a></h4>
<pre><code class="lang-md">## Design of the Glow Intermediate Representation

### Introduction

This document describes the motivation behind the Glow intermediate
representation (IR) and some implementation details.

Glow is a retargetable compiler that supports a number of different backends.
This means that the first few layers of the compiler are target-independent, but
as you get closer to the different backends things start to diverge.  The first
two levels of IR are shared between all targets. Different backends may have
additional layers of IR.

### High-level IR

The high-level IR is a dataflow node-based graph representation that is similar
to a graph that you may find inside Caffe or in ONNX format. When we load a
neural network model from some file we construct this graph with a direct
translation of one operator to one or more nodes. The high-level IR is a simple
graph that allows basic transformations such as replacing all uses of some node
</code></pre>

  This file has been truncated. <a href="https://github.com/pytorch/glow/blob/master/docs/IR.md" target="_blank" rel="noopener nofollow ugc">show original</a>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>


username: Kittu28
cooked: <p>I have deleted  <strong>lib</strong> folder from glow and executed  the following command.</p>
<p><code>${GLOW_PATH}/build/bin/image-classifier ${GLOW_PATH}/tests/images/imagenet/cat_285.png -image-mode=0to1 -m resnet18.onnx -model-input-name=data -cpu</code></p>
<p>BUT still i’m getting the expected output , even though there are no .cpp files present because i deleted <strong>lib</strong> folder and run the command. What did i miss here? or Anything wrong with the system of mine or this is  something related to GLOW only…?</p>

username: jfix
cooked: <p>I don’t understand what you’re expecting to see when you delete the lib folder. Glow is C++, so it’s compiled into a binary. If you compile the <code>image-classifier</code> binary and then delete the cpp files it was compiled from the binary will still run.</p>

username: Kittu28
cooked: <p>If i want to run the code by changing any .cpp file(say partitionutils.cpp) how can i do it…? Do i need to re build it? how can i do it…can you please tell it …</p>

username: jfix
cooked: <p>Yes you need to rebuild. For example if you built previously by <code>ninja image-classifier</code>, and then you make changes to a <code>.cpp</code> or <code>.h</code> file, then you need to rerun <code>ninja image-classifier</code> before your command. This is how compiled languages like C++ work.</p>

username: Kittu28
cooked: <p>Yes…! It worked …Thank you very much…!!</p>