Source Code: F.conv2d() Definition Location

username: ghee-air-moe
cooked: <p>I keep trying to find WHERE F.conv2d() is defined, like where all of it is ACTUALLY written out logically. Does anyone know where it hides?</p>
<p>Under torch/nn/modules/conv.py line 339 calls F.conv2d() but as I go to torch/nn/functional.py to where it supposed to be defined all i get are comments about it at line 48.</p>

username: ptrblck
cooked: <p>The call is eventually calling into <a href="https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/Convolution.cpp">Convolution.cpp</a>, where some checks are applied to further dispatch the call to the proper backend (MKL, cudnn, native implementation etc.).</p>

username: ghee-air-moe
cooked: <p>Thanks! It’s close, but only shows a call to some other function…<em>sigh</em>… I suppose it’s the secret sauce.</p>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/pytorch/pytorch/blob/1465970a343e61f2f2b104859ca7f5d7e03f5d02/aten/src/ATen/native/Convolution.cpp#L539" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/pytorch/blob/1465970a343e61f2f2b104859ca7f5d7e03f5d02/aten/src/ATen/native/Convolution.cpp#L539" target="_blank" rel="nofollow noopener">pytorch/pytorch/blob/1465970a343e61f2f2b104859ca7f5d7e03f5d02/aten/src/ATen/native/Convolution.cpp#L539</a></h4>
<pre class="onebox"><code class="lang-cpp"><ol class="start lines" start="529" style="counter-reset: li-counter 528 ;">
<li>}</li>
<li>
</li><li>
</li><li>at::Tensor conv1d(</li>
<li>    const Tensor&amp; input, const Tensor&amp; weight, const Tensor&amp; bias,</li>
<li>    IntArrayRef stride, IntArrayRef padding, IntArrayRef dilation, int64_t groups) {</li>
<li>  return at::convolution(input, weight, bias, stride, padding, dilation,</li>
<li>                         false, {0}, groups);</li>
<li>}</li>
<li>
</li><li class="selected">at::Tensor conv2d(</li>
<li>    const Tensor&amp; input, const Tensor&amp; weight, const Tensor&amp; bias,</li>
<li>    IntArrayRef stride, IntArrayRef padding, IntArrayRef dilation, int64_t groups) {</li>
<li>  return at::convolution(input, weight, bias, stride, padding, dilation,</li>
<li>                         false, {{0, 0}}, groups);</li>
<li>}</li>
<li>
</li><li>at::Tensor conv3d(</li>
<li>    const Tensor&amp; input, const Tensor&amp; weight, const Tensor&amp; bias,</li>
<li>    IntArrayRef stride, IntArrayRef padding, IntArrayRef dilation, int64_t groups) {</li>
<li>  return at::convolution(input, weight, bias, stride, padding, dilation,</li>
</ol></code></pre>


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


username: ptrblck
cooked: <p>The native implementation are not closed source and the CPU version can be found <a href="https://github.com/pytorch/pytorch/blob/e9902358df14dc4809e4f50b12088a5200a1862d/aten/src/ATen/native/ConvolutionMM2d.cpp">here</a>, while the CUDA version is <a href="https://github.com/pytorch/pytorch/blob/a5f01846c2bae0d78a5c0cd74ced20a07b8ef961/aten/src/THCUNN/generic/SpatialConvolutionMM.cu">here</a>.</p>

username: ghee-air-moe
cooked: <p>Ptrblck, you’re awesome! Thank you for your dedication!</p>

username: LearnedLately
cooked: <p><a class="mention" href="/u/ptrblck">@ptrblck</a> Is aten/src/THCUNN/generic/SpatialConvolutionMM.cu still the CUDA convolution implementation that pytorch uses? When I clone the pytorch repository with <code>git clone --recursive https://github.com/pytorch/pytorch</code> that file isn’t even included.</p>

username: ptrblck
cooked: <p>You can find the current implementation <a href="https://github.com/pytorch/pytorch/blob/a18cfb790d0998aa7939c01174fb2f40237897eb/aten/src/ATen/native/cuda/ConvolutionMM2d.cu">here</a> as it was moved to the <code>ATen</code> namespace.</p>