Using Git, we can clone the Git repository containing Caffe2 source code and all the submodules it requires:
$ git clone --recursive https://github.com/pytorch/pytorch.git && cd pytorch
$ git submodule update --init
Notice how the Caffe2 source code now exists in a subdirectory inside the PyTorch source repository. This is because of Facebook's cohabitation plan for these two popular DL frameworks as it endeavors to merge the best features of both frameworks over a period of time.
Caffe2 uses CMake as its build system. CMake enables Caffe2 to be easily built for a wide variety of compilers and operating systems.
To build Caffe2 source code using CMake, we first create a build directory and invoke CMake from within it:
$ mkdir build
$ cd build
$ cmake ..
CMake checks available compilers, operating systems, libraries, and packages, and figures out which Caffe2 features to enable and compilation options to use. These options can be seen listed in the CMakeLists.txt file present at the root directory. Options are listed in the form of option(USE_FOOBAR "Use Foobar library" OFF). You can enable or disable those options by setting them to ON or OFF in CMakeLists.txt.
These options can also be configured when invoking CMake. For example, if your Intel CPU has support for AVX/AVX2/FMA, and you would wish to use those features to speed up Caffe2 operations, then enable the USE_NATIVE_ARCH option as follows:
$ cmake -DUSE_NATIVE_ARCH=ON ..