XNNPACK
XNNPACK copied to clipboard
CMake build error when using XNNPACK_USE_SYSTEM_LIBS=ON
I'm trying to write a Spack package for XNNPACK. Specifically, I'm trying to allow the build to work using the -DXNNPACK_USE_SYSTEM_LIBS=ON flag. The exact command looks like:
$ 'cmake' '-G' 'Ninja' '-DCMAKE_INSTALL_PREFIX:STRING=/home/t-astewart/spack/opt/spack/linux-ubuntu18.04-haswell/gcc-7.5.0/xnnpack-master-weclozv2jr5am4c6ldp5gjemdvwweofg' '-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo' '-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=OFF' '-DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=OFF' '-DCMAKE_INSTALL_RPATH:STRING=/home/t-astewart/spack/opt/spack/linux-ubuntu18.04-haswell/gcc-7.5.0/xnnpack-master-weclozv2jr5am4c6ldp5gjemdvwweofg/lib;/home/t-astewart/spack/opt/spack/linux-ubuntu18.04-haswell/gcc-7.5.0/xnnpack-master-weclozv2jr5am4c6ldp5gjemdvwweofg/lib64;/home/t-astewart/spack/opt/spack/linux-ubuntu18.04-haswell/gcc-7.5.0/cpuinfo-master-v7xymxuy5jo7i3vywztjwjorrrbd6jzo/lib;/home/t-astewart/spack/opt/spack/linux-ubuntu18.04-haswell/gcc-7.5.0/pthreadpool-master-wkwnldyirs6n6hf6jbwgicfvdcfsdh7p/lib' '-DCMAKE_PREFIX_PATH:STRING=/home/t-astewart/spack/opt/spack/linux-ubuntu18.04-haswell/gcc-7.5.0/cmake-3.20.3-lpjhnv4pz77i3mysbgxysdnlevd237wg;/home/t-astewart/spack/opt/spack/linux-ubuntu18.04-haswell/gcc-7.5.0/cpuinfo-master-v7xymxuy5jo7i3vywztjwjorrrbd6jzo;/home/t-astewart/spack/opt/spack/linux-ubuntu18.04-haswell/gcc-7.5.0/fp16-master-2vag2hkk6cushbrfebtwclvxex6oqy5y;/home/t-astewart/spack/opt/spack/linux-ubuntu18.04-haswell/gcc-7.5.0/ninja-1.10.2-jjbyyjxkir52fgtfhdatowkjdbbwr6nm;/home/t-astewart/spack/opt/spack/linux-ubuntu18.04-haswell/gcc-7.5.0/pthreadpool-master-wkwnldyirs6n6hf6jbwgicfvdcfsdh7p' '-DXNNPACK_USE_SYSTEM_LIBS:BOOL=ON' '/tmp/t-astewart/spack-stage/spack-stage-xnnpack-master-weclozv2jr5am4c6ldp5gjemdvwweofg/spack-src'
During CMake configuration, I get thousands of lines of error messages like:
CMake Error at CMakeLists.txt:3416 (ADD_LIBRARY):
ADD_LIBRARY cannot create target "XNNPACK" because another target with the
same name already exists. The existing target is a static library created
in source directory
"/tmp/t-astewart/spack-stage/spack-stage-xnnpack-master-weclozv2jr5am4c6ldp5gjemdvwweofg/spack-src".
See documentation for policy CMP0002 for more details.
See the following build log:
Any idea what could be causing this?
P.S. Would anyone be interested in being listed as the official maintainer of XNNPACK? You don't have to know anything about Spack, it just gives us someone to ping when a user reports build issues or wants to modify the build recipe.
Note: this bug seems to only occur when using XNNPACK_USE_SYSTEM_LIBS=ON.
XNNPACK_USE_SYSTEM_LIBS was introduced in #533. Please check with @cdluminate who introduced it about how it is supposed to be used, as we don't regularly test it, and don't know if it is broken.
@cdluminate any comments on this?
P.S. Love the profile pic
The flag was added for building the Debian package. The CMake flags used for the build can be found here: https://salsa.debian.org/deeplearning-team/xnnpack/-/blob/master/debian/rules#L8-12 I'll test this on the master branch and get back to you.
It is still working on the master branch, as long as the dependency libraries can be correctly found. You may need to make sure the find_library() calls in CMakeLists.txt can really find the system libraries. In my case, if the CMake is invoked without the Debian package building tools, I will have to add HINTS for library searching due to Debian's library directory hierarchy:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2ca06ee..1ba99bb 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6558,7 +6558,7 @@ IF(NOT TARGET clog)
SET_PROPERTY(TARGET clog PROPERTY POSITION_INDEPENDENT_CODE ON)
ELSE()
ADD_LIBRARY(clog STATIC IMPORTED)
- FIND_LIBRARY(CLOG_LIBRARY clog)
+ FIND_LIBRARY(CLOG_LIBRARY clog HINTS /usr/lib/x86_64-linux-gnu/)
IF(NOT CLOG_LIBRARY)
MESSAGE(FATAL_ERROR "Cannot find clog")
ENDIF()
@@ -6580,7 +6580,7 @@ IF(NOT TARGET cpuinfo)
"${CMAKE_BINARY_DIR}/cpuinfo")
ELSE()
ADD_LIBRARY(cpuinfo SHARED IMPORTED)
- FIND_LIBRARY(CPUINFO_LIBRARY cpuinfo)
+ FIND_LIBRARY(CPUINFO_LIBRARY cpuinfo HINTS /usr/lib/x86_64-linux-gnu)
IF(NOT CPUINFO_LIBRARY)
MESSAGE(FATAL_ERROR "Cannot find cpuinfo")
ENDIF()
@@ -6600,7 +6600,7 @@ IF(NOT TARGET pthreadpool)
"${CMAKE_BINARY_DIR}/pthreadpool")
ELSE()
ADD_LIBRARY(pthreadpool SHARED IMPORTED)
- FIND_LIBRARY(PTHREADPOOL_LIBRARY pthreadpool)
+ FIND_LIBRARY(PTHREADPOOL_LIBRARY pthreadpool HINTS /usr/lib/x86_64-linux-gnu)
IF(NOT PTHREADPOOL_LIBRARY)
MESSAGE(FATAL_ERROR "Cannot find pthreadpool")
ENDIF()
Since this may be somewhat distribution-specific, I'm not sure whether to submit a PR.
The flag was added for building the Debian package. The CMake flags used for the build can be found here: https://salsa.debian.org/deeplearning-team/xnnpack/-/blob/master/debian/rules#L8-12 I'll test this on the master branch and get back to you.
Out of curiosity, where does BUILD_SHARED_LIBS come from? I don't see it defined in CMakeLists.txt
The build with XNNPACK_USE_SYSTEM_LIBS seems to be getting further than last time, but I'm still encountering issues with some deps:
FAILED: libfxdiv.a
: && /Users/ajstewart/spack/opt/spack/darwin-monterey-m1/apple-clang-14.0.0/cmake-3.25.0-s4u727vy7efhzxy4y5zvmwbuagumrn6e/bin/cmake -E rm -f libfxdiv.a && /usr/bin/ar qc libfxdiv.a && /usr/bin/ranlib libfxdiv.a && /Users/ajstewart/spack/opt/spack/darwin-monterey-m1/apple-clang-14.0.0/cmake-3.25.0-s4u727vy7efhzxy4y5zvmwbuagumrn6e/bin/cmake -E touch libfxdiv.a && :
ar: no archive members specified
usage: ar -d [-TLsv] archive file ...
ar -m [-TLsv] archive file ...
ar -m [-abiTLsv] position archive file ...
ar -p [-TLsv] archive [file ...]
ar -q [-cTLsv] archive file ...
ar -r [-cuTLsv] archive file ...
ar -r [-abciuTLsv] position archive file ...
ar -t [-TLsv] archive [file ...]
ar -x [-ouTLsv] archive [file ...]
Going to try building all deps as shared libs too.
Interesting. It looks like -DXNNPACK_USE_SYSTEM_LIBS=ON isn't compatible with -DXNNPACK_BUILD_TESTS=ON or -DXNNPACK_BUILD_BENCHMARKS=ON. If I enable all 3, I get the original issue I reported here. If I disable the latter, I get the above issue. So either way, I'm unable to use system libs.
@adamjstewart I encountered this only on macOS when building for Android. I din't encounter this on GNU/Linux.
on GNU/Linux:
/github/home/.uppm/installed/cmake/bin/cmake -E rm -f libfxdiv.a &&
/github/home/.uppm/installed/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar qc libfxdiv.a && /github/home/.uppm/installed/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib libfxdiv.a
/github/home/.uppm/installed/cmake/bin/cmake -E rm -f libfp16.a &&
/github/home/.uppm/installed/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar qc libfp16.a &&
/github/home/.uppm/installed/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib libfp16.a
on macOS:
/Users/runner/.uppm/installed/cmake/bin/cmake -E rm -f libfxdiv.a && /usr/bin/ar qc libfxdiv.a &&
/Users/runner/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ranlib libfxdiv.a &&
/Users/runner/.uppm/installed/cmake/bin/cmake -E touch libfxdiv.a
/Users/runner/.uppm/installed/cmake/bin/cmake -E rm -f libfxdiv.a && /usr/bin/ar qc libfxdiv.a &&
/Users/runner/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ranlib libfxdiv.a &&
/Users/runner/.uppm/installed/cmake/bin/cmake -E touch libfxdiv.a
on GNU/Linux use the llvm-ar, on macOS use the system's ar, the macOS system ar is too old and must specify a member but llvm-ar do not need to specify a member. I think this problem caused by https://github.com/google/XNNPACK/blob/master/CMakeLists.txt#L926