Implementation of Convolution

Kittu28: <p>Can you please point out to me the part of Code where the Convolution ,Maxpool etc are implemented ?</p>

aguennecjacq: <p>What you’re asking is basically a rabbit hole in terms of source code.<br>
here is at least the source code of <code>nn.conv</code>:</p><aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/conv.py" target="_blank" rel="noopener nofollow ugc">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/conv.py" target="_blank" rel="noopener nofollow ugc">pytorch/pytorch/blob/master/torch/nn/modules/conv.py</a></h4>
<pre><code class="lang-py"># coding=utf-8
import math
import warnings

import torch
from torch import Tensor
from torch.nn.parameter import Parameter, UninitializedParameter
from .. import functional as F
from .. import init
from .lazy import LazyModuleMixin
from .module import Module
from .utils import _single, _pair, _triple, _reverse_repeat_tuple
from torch._torch_docs import reproducibility_notes

from ..common_types import _size_1_t, _size_2_t, _size_3_t
from typing import Optional, List, Tuple

convolution_notes = \
    {"groups_note": r"""* :attr:`groups` controls the connections between inputs and outputs.
      :attr:`in_channels` and :attr:`out_channels` must both be divisible by
</code></pre>

  This file has been truncated. <a href="https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/conv.py" target="_blank" rel="noopener nofollow ugc">show original</a>

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


Kittu28: <p>Hello , So…Can’t i find any such implementation of Convolution in the GLOW provided Source Code itself…?</p>

aguennecjacq: <p>Ah sorry I didn’t see your question was asked in the <code>glow</code> section <img src="https://discuss.pytorch.org/images/emoji/apple/face_with_hand_over_mouth.png?v=9" title=":face_with_hand_over_mouth:" class="emoji" alt=":face_with_hand_over_mouth:"></p>

Kittu28: <p>In  InterpreterNodes.cpp  i found the code for Interpreter Part of convolution implementation but for CPU part there two different kinds of convolution nodes —CPUConvDKKC8 and Convolution. In the file libjit_cpu_conv.cpp there is some implementation for the convolution. Is that for the two different kind of Convolution nodes? Or what is it …are there any other files where convolution is implemented for CPU …?</p>

jfix: <p>Yeah you’re correct. InterpreterNodes is where the Interpreter kernels are. Then for CPU we have a couple different versions of convolution. We implemented a decently performant convolution <code>CPUConvDKKC8</code> which we found to perform well on x86.</p>

Kittu28: <p>I found the .cpp file where the normal convolutional nodes are changed to CPU specific convolution nodes(CPUConvDKKC8)  but for CPU backend where is the  convolution implementation written…?in which file…? For Interpreter backend i found it in InterpreterNodes.cpp and may i know similarly where can i find it for CPU…?</p>

Kittu28: <p>I got the files for both of the convolution implementations. How can i know which part of the code is calling these files.(like for example libjit_cpu_conv.cpp- for cpu specific implementation)</p>

jfix: <p>Calls are generated to these functions in <a href="https://github.com/pytorch/glow/blob/474d29237e8f9ee4440694a170f4b131d0a9b622/lib/LLVMIRCodeGen/LLVMIRGen.cpp#L2350-L2356" rel="noopener nofollow ugc">LLVMIRGen.cpp</a> for any backend that is LLVM-based, which includes the CPU backend. The backend also has its own specialized version aside from LLVMIRGen.cpp, e.g. <a href="https://github.com/pytorch/glow/blob/474d29237e8f9ee4440694a170f4b131d0a9b622/lib/Backends/CPU/CPULLVMIRGen.cpp#L110-L117" rel="noopener nofollow ugc">here</a> for the CPU backend.</p>