Resize implementation in OpenCL

Lewuathe: <p>Hello</p>
<p>I have a specific question about how resize instruction is implemented in the OpenCL backend. A resize instruction is not apparently supported by the OpenCL backend. It is not in the list of <code>isOpSupported</code>.</p>
<p>How is such type of unsupported operation by the OpenCL backend executed? I guess resize is executed in the host environment and the output is exchanged back and force with the device. I’m not sure which part of Glow is responsible for that.</p>
<p>It would be great if someone could give me a pointer to the code I should look into.</p>
<p>Best</p>

jfix: <blockquote>
<p>It is not in the list of <code>isOpSupported</code>.</p>
</blockquote>
<p>It is supported, perhaps you just missed it, it’s listed here:</p>
<aside class="onebox githubblob" data-onebox-src="https://github.com/pytorch/glow/blob/778d44eff16f8dfac25503e0f917531d71bc950b/lib/Backends/OpenCL/OpenCL.cpp#L1931">
  <header class="source">

      <a href="https://github.com/pytorch/glow/blob/778d44eff16f8dfac25503e0f917531d71bc950b/lib/Backends/OpenCL/OpenCL.cpp#L1931" target="_blank" rel="noopener nofollow ugc">github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/glow/blob/778d44eff16f8dfac25503e0f917531d71bc950b/lib/Backends/OpenCL/OpenCL.cpp#L1931" target="_blank" rel="noopener nofollow ugc">pytorch/glow/blob/778d44eff16f8dfac25503e0f917531d71bc950b/lib/Backends/OpenCL/OpenCL.cpp#L1931</a></h4>



    <pre class="onebox"><code class="lang-cpp">
      <ol class="start lines" start="1921" style="counter-reset: li-counter 1920 ;">
          <li>        {ElemKind::FloatTy}, {},</li>
          <li>        {ConvolutionGradNode::GradOfInputNamedInputIdx});</li>
          <li></li>
          <li>  case Kinded::Kind::SoftMaxGradNodeKind:</li>
          <li>    return NI.allInputsAndOutputsHaveSameElemKind(</li>
          <li>               {ElemKind::FloatTy}, {SoftMaxGradNode::SelectedIdx},</li>
          <li>               {SoftMaxGradNode::GradOfInputNamedSelectedIdx}) &amp;&amp;</li>
          <li>           (NI.getInElemTy(SoftMaxGradNode::SelectedIdx) == ElemKind::Int64ITy);</li>
          <li></li>
          <li>  case Kinded::Kind::SaveNodeKind:</li>
          <li class="selected">  case Kinded::Kind::ReshapeNodeKind:</li>
          <li>  case Kinded::Kind::OCLBatchedReduceAddNodeKind:</li>
          <li>  case Kinded::Kind::TraceEventNodeKind:</li>
          <li>    // These work regardless of the underlying type.</li>
          <li>    return true;</li>
          <li></li>
          <li>  default:</li>
          <li>    return false;</li>
          <li>  }</li>
          <li>}</li>
          <li></li>
      </ol>
    </code></pre>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>


Lewuathe: <p>Thank you!<br>
But IIUC, the resize node has <code>ResizeNearestNodeKind</code>. I could find that node kind in the list of OpenCL backend. Does resize node have <code>ReshapeNodeKind</code> instead?</p>

jfix: <p>Oh sorry I misread your original post <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>
<p>You are correct, Resize is not supported on the OpenCL backend. Depending on what frontend you’re using (PyTorch, Caffe2, ONNX, TFLite, etc.) this will behave differently, since some of these frontends only delegate ops into Glow if they’re supported on the target backend, and so it would automatically execute the Resize in the base framework (e.g. PyTorch) and only delegate to Glow the other piece(s) of the model automatically for you.</p>
<p>However assuming it is delegated/loaded into Glow (e.g. if it’s loaded via ONNX), then it will most likely just throw an error during compilation. You would need to do <a href="https://github.com/pytorch/glow/blob/master/docs/Partitioner.md#heterogeneous-partition" rel="noopener nofollow ugc">heterogeneous partitioning</a> in order to partition the Resize node to e.g. the Glow CPU backend to have such execution bounce back and forth between your OpenCL device and the host CPU.</p>

Lewuathe: <p><a class="mention" href="/u/jfix">@jfix</a> Information about the heterogeneous partitioning is so helpful. Thank you so much for the explanation!</p>