So I dug a bit into it, it seems to me that the problem is in this section of aten/src/ATen/CMakeLists.txt, which by the way hasn’t evolved between 1.9.1 and current master:
if(BUILD_LITE_INTERPRETER)
set(all_cpu_cpp ${generated_cpp} ${core_generated_cpp} ${cpu_kernel_cpp})
append_filelist("jit_core_sources" all_cpu_cpp)
append_filelist("aten_cpu_source_non_codegen_list" all_cpu_cpp)
append_filelist("aten_native_source_non_codegen_list" all_cpu_cpp)
list(APPEND all_cpu_cpp ${Aten_TH_AVX_extra_src})
else()
set(
all_cpu_cpp ${base_cpp} ${ATen_CORE_SRCS} ${native_cpp}
${native_ao_sparse_cpp} ${native_sparse_cpp}
${native_quantized_cpp} ${native_mkl_cpp} ${native_mkldnn_cpp}
${native_utils_cpp} ${native_xnnpack} ${generated_cpp} ${core_generated_cpp}
${ATen_CPU_SRCS} ${ATen_QUANTIZED_SRCS} ${ATen_NNAPI_SRCS} ${cpu_kernel_cpp}
)
endif()
It seems that ATen_NNAPI_SRCS files are not included in the build when building the light interpreter. (They are actually built, I can find the .o files, but not linked into the output library)
We tried rebuild pytorch with this patch
diff --git a/aten/src/ATen/CMakeLists.txt b/aten/src/ATen/CMakeLists.txt
index baf9666f11..19f9a78443 100644
--- a/aten/src/ATen/CMakeLists.txt
+++ b/aten/src/ATen/CMakeLists.txt
@@ -130,7 +130,7 @@ add_subdirectory(quantized)
add_subdirectory(nnapi)
if(BUILD_LITE_INTERPRETER)
- set(all_cpu_cpp ${generated_cpp} ${core_generated_cpp} ${cpu_kernel_cpp})
+ set(all_cpu_cpp ${generated_cpp} ${core_generated_cpp} ${ATen_NNAPI_SRCS} ${cpu_kernel_cpp})
append_filelist("jit_core_sources" all_cpu_cpp)
append_filelist("aten_cpu_source_non_codegen_list" all_cpu_cpp)
append_filelist("aten_native_source_non_codegen_list" all_cpu_cpp)
diff --git a/scripts/build_android.sh b/scripts/build_android.sh
index daad46e8fb..211f5bb429 100755
--- a/scripts/build_android.sh
+++ b/scripts/build_android.sh
@@ -147,7 +147,11 @@ if [ "${ANDROID_DEBUG_SYMBOLS:-}" == '1' ]; then
fi
if [ -n "${USE_VULKAN}" ]; then
- CMAKE_ARGS+=("-DUSE_VULKAN=ON")
+ CMAKE_ARGS+=("-DUSE_VULKAN=${USE_VULKAN}")
+fi
+
+if [ -n "${USE_NNAPI}" ]; then
+ CMAKE_ARGS+=("-DUSE_NNAPI=${USE_NNAPI}")
fi
# Use-specified CMake arguments go last to allow overridding defaults
diff --git a/aten/src/ATen/CMakeLists.txt b/aten/src/ATen/CMakeLists.txt
index baf9666f11..19f9a78443 100644
--- a/aten/src/ATen/CMakeLists.txt
+++ b/aten/src/ATen/CMakeLists.txt
@@ -130,7 +130,7 @@ add_subdirectory(quantized)
add_subdirectory(nnapi)
if(BUILD_LITE_INTERPRETER)
- set(all_cpu_cpp ${generated_cpp} ${core_generated_cpp} ${cpu_kernel_cpp})
+ set(all_cpu_cpp ${generated_cpp} ${core_generated_cpp} ${ATen_NNAPI_SRCS} ${cpu_kernel_cpp})
append_filelist("jit_core_sources" all_cpu_cpp)
append_filelist("aten_cpu_source_non_codegen_list" all_cpu_cpp)
append_filelist("aten_native_source_non_codegen_list" all_cpu_cpp)
diff --git a/scripts/build_android.sh b/scripts/build_android.sh
index 4dcb00becb..211f5bb429 100755
--- a/scripts/build_android.sh
+++ b/scripts/build_android.sh
@@ -150,6 +150,10 @@ if [ -n "${USE_VULKAN}" ]; then
CMAKE_ARGS+=("-DUSE_VULKAN=${USE_VULKAN}")
fi
+if [ -n "${USE_NNAPI}" ]; then
+ CMAKE_ARGS+=("-DUSE_NNAPI=${USE_NNAPI}")
+fi
+
# Use-specified CMake arguments go last to allow overridding defaults
CMAKE_ARGS+=($@)
And it works!!!. It requires launching build_android.sh with extra arguments USE_VULKAN=OFF USE_NNAPI=ON (unless one wants to activate Vulkan).
Note that ATen_NNAPI_SRCS is only defined when USE_NNAPI is on, so it makes sense to add the content of ATen_NNAPI_SRCS also in the lite scenario, because it will only increase the size of the resulting library if one explicitly requires NNAPI.