Repository: pytorch
Issue: Linker errors when linking statically (avx perfkernels) [Caffe2]
Labels: caffe2

## 🐛 Bug

I've been trying to build the caffe2 v1.1.0 release and link it statically with our application, but I'm getting a lot of undefined symbols related to avx functions.

## To Reproduce

I've built caffe2 142c973f4179e768164cd578951489e89021b29c using the following flags:
```bash
$ cd pytorch
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_INSTALL_PREFIX=/home/giachero/runtimes/caffe2-v1.1.0-avx -DBUILD_PYTHON=OFF -DUSE_CUDA=OFF -DUSE_NATIVE_ARCH=ON -DUSE_GFLAGS=OFF -DUSE_GLOG=OFF -DUSE_GLOO=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TEST=OFF -DBUILD_BINARY=OFF -DUSE_LMDB=OFF -DUSE_LEVELDB=OFF -DUSE_MPI=OFF -DUSE_OPENMP=OFF -DUSE_OPENCV=OFF -DBUILD_ATEN_MOBILE=ON -DUSE_NNPACK=OFF -DCAFFE2_DISABLE_NUMA=1 -DUSE_QNNPACK=OFF
```
Minimal application code:
```c++
#include <caffe2/core/init.h>

int main(int argc, char *argv[])
{
    caffe2::GlobalInit();
    return 0;
}
```
Build flags:
```bash
$ g++ main.cpp -I /home/giachero/runtimes/caffe2-v1.1.0-avx/include/ -L /home/giachero/runtimes/caffe2-v1.1.0-avx/lib/ -Wl,--whole-archive -lcaffe2 -Wl,--no-whole-archive -lcaffe2_protos -lcpuinfo -lc10 -lclog -lonnx -lprotobuf -lonnx_proto -lonnxifi_loader -lm -lpthread -ldl -o test
```
Output:
```
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(embedding_lookup.cc.o): In function `caffe2::EmbeddingLookup_int32_t_float_float_false(long, long, long, long, float const*, int const*, int const*, float const*, float const*, bool, float*)':
embedding_lookup.cc:(.text+0x2caa): undefined reference to `caffe2::EmbeddingLookup_int32_t_float_float_false__avx2_fma(long, long, long, long, float const*, int const*, int const*, float const*, float const*, bool, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(embedding_lookup.cc.o): In function `caffe2::EmbeddingLookup_int64_t_float_float_false(long, long, long, long, float const*, long const*, int const*, float const*, float const*, bool, float*)':
embedding_lookup.cc:(.text+0x2e3a): undefined reference to `caffe2::EmbeddingLookup_int64_t_float_float_false__avx2_fma(long, long, long, long, float const*, long const*, int const*, float const*, float const*, bool, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(embedding_lookup.cc.o): In function `caffe2::EmbeddingLookup_int32_t_half_float_false(long, long, long, long, c10::Half const*, int const*, int const*, float const*, float const*, bool, float*)':
embedding_lookup.cc:(.text+0x2fca): undefined reference to `caffe2::EmbeddingLookup_int32_t_half_float_false__avx2_fma(long, long, long, long, c10::Half const*, int const*, int const*, float const*, float const*, bool, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(embedding_lookup.cc.o): In function `caffe2::EmbeddingLookup_int64_t_half_float_false(long, long, long, long, c10::Half const*, long const*, int const*, float const*, float const*, bool, float*)':
embedding_lookup.cc:(.text+0x315a): undefined reference to `caffe2::EmbeddingLookup_int64_t_half_float_false__avx2_fma(long, long, long, long, c10::Half const*, long const*, int const*, float const*, float const*, bool, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(embedding_lookup.cc.o): In function `caffe2::EmbeddingLookup_int32_t_uint8_t_float_false(long, long, long, long, unsigned char const*, int const*, int const*, float const*, float const*, bool, float*)':
embedding_lookup.cc:(.text+0x32ec): undefined reference to `caffe2::EmbeddingLookup_int32_t_uint8_t_float_false__avx2_fma(long, long, long, long, unsigned char const*, int const*, int const*, float const*, float const*, bool, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(embedding_lookup.cc.o): In function `caffe2::EmbeddingLookup_int64_t_uint8_t_float_false(long, long, long, long, unsigned char const*, long const*, int const*, float const*, float const*, bool, float*)':
embedding_lookup.cc:(.text+0x347c): undefined reference to `caffe2::EmbeddingLookup_int64_t_uint8_t_float_false__avx2_fma(long, long, long, long, unsigned char const*, long const*, int const*, float const*, float const*, bool, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(embedding_lookup.cc.o): In function `caffe2::EmbeddingLookup_int32_t_float_float_true(long, long, long, long, float const*, int const*, int const*, float const*, float const*, bool, float*)':
embedding_lookup.cc:(.text+0x360a): undefined reference to `caffe2::EmbeddingLookup_int32_t_float_float_true__avx2_fma(long, long, long, long, float const*, int const*, int const*, float const*, float const*, bool, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(embedding_lookup.cc.o): In function `caffe2::EmbeddingLookup_int64_t_float_float_true(long, long, long, long, float const*, long const*, int const*, float const*, float const*, bool, float*)':
embedding_lookup.cc:(.text+0x379a): undefined reference to `caffe2::EmbeddingLookup_int64_t_float_float_true__avx2_fma(long, long, long, long, float const*, long const*, int const*, float const*, float const*, bool, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(embedding_lookup.cc.o): In function `caffe2::EmbeddingLookup_int32_t_half_float_true(long, long, long, long, c10::Half const*, int const*, int const*, float const*, float const*, bool, float*)':
embedding_lookup.cc:(.text+0x392a): undefined reference to `caffe2::EmbeddingLookup_int32_t_half_float_true__avx2_fma(long, long, long, long, c10::Half const*, int const*, int const*, float const*, float const*, bool, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(embedding_lookup.cc.o): In function `caffe2::EmbeddingLookup_int64_t_half_float_true(long, long, long, long, c10::Half const*, long const*, int const*, float const*, float const*, bool, float*)':
embedding_lookup.cc:(.text+0x3aba): undefined reference to `caffe2::EmbeddingLookup_int64_t_half_float_true__avx2_fma(long, long, long, long, c10::Half const*, long const*, int const*, float const*, float const*, bool, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(embedding_lookup.cc.o): In function `caffe2::EmbeddingLookup_int32_t_uint8_t_float_true(long, long, long, long, unsigned char const*, int const*, int const*, float const*, float const*, bool, float*)':
embedding_lookup.cc:(.text+0x3c4c): undefined reference to `caffe2::EmbeddingLookup_int32_t_uint8_t_float_true__avx2_fma(long, long, long, long, unsigned char const*, int const*, int const*, float const*, float const*, bool, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(embedding_lookup.cc.o): In function `caffe2::EmbeddingLookup_int64_t_uint8_t_float_true(long, long, long, long, unsigned char const*, long const*, int const*, float const*, float const*, bool, float*)':
embedding_lookup.cc:(.text+0x3ddc): undefined reference to `caffe2::EmbeddingLookup_int64_t_uint8_t_float_true__avx2_fma(long, long, long, long, unsigned char const*, long const*, int const*, float const*, float const*, bool, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(fused_8bit_rowwise_embedding_lookup.cc.o): In function `caffe2::Fused8BitRowwiseEmbeddingLookup_int64_t_uint8_t_float(long, long, long, long, unsigned char const*, long const*, int const*, float const*, bool, float*)':
fused_8bit_rowwise_embedding_lookup.cc:(.text+0x858): undefined reference to `caffe2::Fused8BitRowwiseEmbeddingLookup_int64_t_uint8_t_float_false__avx2_fma(long, long, long, long, unsigned char const*, long const*, int const*, float const*, bool, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(fused_8bit_rowwise_embedding_lookup.cc.o): In function `caffe2::Fused8BitRowwiseEmbeddingLookup_int32_t_uint8_t_float(long, long, long, long, unsigned char const*, int const*, int const*, float const*, bool, float*)':
fused_8bit_rowwise_embedding_lookup.cc:(.text+0x958): undefined reference to `caffe2::Fused8BitRowwiseEmbeddingLookup_int32_t_uint8_t_float_false__avx2_fma(long, long, long, long, unsigned char const*, int const*, int const*, float const*, bool, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(typed_axpy.cc.o): In function `void caffe2::TypedAxpy<c10::Half, float>(int, float, c10::Half const*, float*)':
typed_axpy.cc:(.text+0x10d): undefined reference to `caffe2::TypedAxpyHalffloat__avx2_fma(int, float, c10::Half const*, float*)'
typed_axpy.cc:(.text+0x131): undefined reference to `caffe2::TypedAxpyHalffloat__avx_f16c(int, float, c10::Half const*, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(typed_axpy.cc.o): In function `void caffe2::TypedAxpy<unsigned char, float>(int, float, unsigned char const*, float*)':
typed_axpy.cc:(.text+0x221): undefined reference to `caffe2::TypedAxpy_uint8_float__avx2_fma(int, float, unsigned char const*, float*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(adagrad.cc.o): In function `caffe2::adagrad_update(int, float const*, float const*, float const*, float*, float*, float, float, float)':
adagrad.cc:(.text+0x621): undefined reference to `caffe2::adagrad_update__avx_f16c(int, float const*, float const*, float const*, float*, float*, float, float, float)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(adagrad.cc.o): In function `caffe2::adagrad_update_prefetch(int, float const*, float const*, float const*, float const*, float const*, float*, float*, float*, float*, float, float)':
adagrad.cc:(.text+0x789): undefined reference to `caffe2::adagrad_update_prefetch__avx_f16c(int, float const*, float const*, float const*, float const*, float const*, float*, float*, float*, float*, float, float)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(adagrad.cc.o): In function `caffe2::adagrad_fp16_update_prefetch(int, c10::Half const*, c10::Half const*, float const*, c10::Half const*, c10::Half const*, c10::Half*, c10::Half*, c10::Half*, c10::Half*, float, float)':
adagrad.cc:(.text+0xac9): undefined reference to `caffe2::adagrad_fp16_update_prefetch__avx_f16c(int, c10::Half const*, c10::Half const*, float const*, c10::Half const*, c10::Half const*, c10::Half*, c10::Half*, c10::Half*, c10::Half*, float, float)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(adagrad.cc.o): In function `caffe2::rowwise_adagrad_update(int, float*, float*, float const*, float*, float*, float, float)':
adagrad.cc:(.text+0xd36): undefined reference to `caffe2::rowwise_adagrad_update__avx_f16c(int, float*, float*, float const*, float*, float*, float, float)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(adagrad.cc.o): In function `int caffe2::sparse_adagrad<int>(int, int, unsigned long, float const*, float const*, float const*, int const*, float*, float*, float, float)':
adagrad.cc:(.text+0xfd6): undefined reference to `caffe2::sparse_adagrad_int32_t__avx_f16c(int, int, unsigned long, float const*, float const*, float const*, int const*, float*, float*, float, float)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(adagrad.cc.o): In function `int caffe2::sparse_adagrad<long>(int, int, unsigned long, float const*, float const*, float const*, long const*, float*, float*, float, float)':
adagrad.cc:(.text+0x1276): undefined reference to `caffe2::sparse_adagrad_int64_t__avx_f16c(int, int, unsigned long, float const*, float const*, float const*, long const*, float*, float*, float, float)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(math_cpu_base.cc.o): In function `caffe2::math::quantize_and_compress(float const*, unsigned char*, unsigned long, unsigned long, bool, float const*)':
math_cpu_base.cc:(.text+0x31d): undefined reference to `caffe2::math::quantize_and_compress__avx2(float const*, unsigned char*, unsigned long, unsigned long, bool, float const*)'
/home/giachero/runtimes/caffe2-v1.1.0-avx/lib//libcaffe2.a(math_cpu_base.cc.o): In function `caffe2::math::decompress_and_dequantize(unsigned char const*, float*, unsigned long)':
math_cpu_base.cc:(.text+0x455): undefined reference to `caffe2::math::decompress_and_dequantize__avx2(unsigned char const*, float*, unsigned long)'
collect2: error: ld returned 1 exit status
```

## Environment

 - Caffe2 version: 142c973f4179e768164cd578951489e89021b29c (v1.1.0)
 - OS: Ubuntu 18.04 x86_64
 - Build command you used (if compiling from source): cmake .. -DCMAKE_INSTALL_PREFIX=/home/giachero/runtimes/caffe2-v1.1.0-avx -DBUILD_PYTHON=OFF -DUSE_CUDA=OFF -DUSE_NATIVE_ARCH=ON -DUSE_GFLAGS=OFF -DUSE_GLOG=OFF -DUSE_GLOO=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TEST=OFF -DBUILD_BINARY=OFF -DUSE_LMDB=OFF -DUSE_LEVELDB=OFF -DUSE_MPI=OFF -DUSE_OPENMP=OFF -DUSE_OPENCV=OFF -DBUILD_ATEN_MOBILE=ON -DUSE_NNPACK=OFF -DCAFFE2_DISABLE_NUMA=1 -DUSE_QNNPACK=OFF