Repository: pytorch
Issue: build failure with NNAPI enabled (Caffe2 path but under pytorch umbrella)
Labels: module: build,caffe2,triaged

I am able to build pytorch on CPU only/Ubuntu18.04/gcc6 regularly with USE_NNAPI=OFF.
However, if I enabled USE_NNAPI=ON by modifying the related CMakeLists.txt all the way down to /caffe2/mobile/contrib/nnapi. 

I got the failure when building the excusable ` ../bin/nnapi_benchmark `. 

All the related build command is: 

`cd /pytorch/build/caffe2

 sudo /usr/bin/c++   -fvisibility-inlines-hidden -D_FORCE_INLINES -D_MWAITXINTRIN_H_INCLUDED -D__STRICT_ANSI__ -fopenmp -DUSE_FBGEMM -O2 -fPIC -Wno-narrowing -Wall -Wextra -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -Wno-unused-but-set-variable -Wno-maybe-uninitialized -DHAVE_AVX_CPU_DEFINITION -DHAVE_AVX2_CPU_DEFINITION -O3    -Wl,-rpath,$ORIGIN -rdynamic -pthread CMakeFiles/nnapi_benchmark.dir/mobile/contrib/nnapi/nnapi_benchmark.cc.o  -o ../bin/nnapi_benchmark -Wl,-rpath,/home/tim/pytorch/build/lib: ../lib/libgtest_main.a -Wl,--no-as-needed,   /home/tim/pytorch/build/lib/libcaffe2.so -Wl,--as-needed ../lib/libprotobuf.a ../lib/libc10.so /usr/lib/x86_64-linux-gnu/libgflags.so.2.2.1 -lpthread /usr/lib/x86_64-linux-gnu/libglog.so ../lib/libgtest.a -pthread  /home/libneruralnetworks.so`

The failure report is: 

```
CMakeFiles/nnapi_benchmark.dir/mobile/contrib/nnapi/nnapi_benchmark.cc.o: In function `caffe2::(anonymous namespace)::benchmark_conv_nnapi(caffe2::Workspace*, int, int, int, int, int, int, int, int, int) [clone .constprop.529]':
nnapi_benchmark.cc:(.text+0xae3): undefined reference to `caffe2::NNApi::run(std::vector<caffe2::Tensor*, std::allocator<caffe2::Tensor*> > const&, std::vector<caffe2::Tensor*, std::allocator<caffe2::Tensor*> >*)'
nnapi_benchmark.cc:(.text+0xaf9): undefined reference to `caffe2::NNApi::run(std::vector<caffe2::Tensor*, std::allocator<caffe2::Tensor*> > const&, std::vector<caffe2::Tensor*, std::allocator<caffe2::Tensor*> >*)'
nnapi_benchmark.cc:(.text+0xb07): undefined reference to `caffe2::NNApi::run(std::vector<caffe2::Tensor*, std::allocator<caffe2::Tensor*> > const&, std::vector<caffe2::Tensor*, std::allocator<caffe2::Tensor*> >*)'
nnapi_benchmark.cc:(.text+0xb2a): undefined reference to `caffe2::NNApi::run(std::vector<caffe2::Tensor*, std::allocator<caffe2::Tensor*> > const&, std::vector<caffe2::Tensor*, std::allocator<caffe2::Tensor*> >*)'
nnapi_benchmark.cc:(.text+0xb82): undefined reference to `caffe2::NNApi::~NNApi()'
nnapi_benchmark.cc:(.text+0xf24): undefined reference to `caffe2::NNApi::~NNApi()'
CMakeFiles/nnapi_benchmark.dir/mobile/contrib/nnapi/nnapi_benchmark.cc.o: In function `caffe2::NNApi::NNApi(caffe2::NetDef const&, caffe2::NetDef const&, caffe2::Workspace*, PreferenceCode)':
nnapi_benchmark.cc:(.text._ZN6caffe25NNApiC2ERKNS_6NetDefES3_PNS_9WorkspaceE14PreferenceCode[_ZN6caffe25NNApiC5ERKNS_6NetDefES3_PNS_9WorkspaceE14PreferenceCode]+0x296): undefined reference to `caffe2::NNApi::loadNNApiLibrary()'

```


However, the `/home/tim/pytorch/build/lib/libcaffe2.so`  should have NNApi implementation. Since
I can see the NNApi symbols in the *so:

```
nm --defined-only /home/tim/pytorch/build/lib/libcaffe2.so | grep NNApi
0000000001487a80 t _ZN6caffe25NNApi10addPoolingERKNS_11OperatorDefE13OperationCodeb
000000000148a430 t _ZN6caffe25NNApi10addSoftmaxERKNS_11OperatorDefE
00000000014862f0 t _ZN6caffe25NNApi15addFloatOperandEf
00000000014864b0 t _ZN6caffe25NNApi15getConvPoolArgsERKNS_14ArgumentHelperERNS0_12ConvPoolArgsE
0000000001486130 t _ZN6caffe25NNApi16addScalarOperandEi
0000000001487420 t _ZN6caffe25NNApi16addTensorOperandERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE11OperandCodeRSt6vectorIjSaIjEEfi
0000000001486120 t _ZN6caffe25NNApi16loadNNApiLibraryEv
000000000148c0f0 t _ZN6caffe25NNApi3runERKSt6vectorIPNS_6TensorESaIS3_EEPS5_
000000000148aab0 t _ZN6caffe25NNApi4initERKSt6vectorIPNS_6TensorESaIS3_EEPS5_
0000000001488560 t _ZN6caffe25NNApi7addConvERKNS_11OperatorDefEb
000000000148a070 t _ZN6caffe25NNApi7addReluERKNS_11OperatorDefE
0000000001487620 t _ZN6caffe25NNApiD1Ev
0000000001487620 t _ZN6caffe25NNApiD2Ev
```



cc @malfet @seemethere @walterddr