intel / intel-graphics-compiler

Other
597 stars 155 forks source link

Failure to find external SPIRV-LLVM-Translator include #232

Closed tgurr closed 2 years ago

tgurr commented 2 years ago

When relying on CMake/pkg-config SPIRV-LLVM-Translator isn't found at all:

CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find SPIRVLLVMTranslator (missing: SPIRVLLVMTranslator_Library
  SPIRVLLVMTranslator_INCLUDE_DIR) (Required is at least version "13")
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  IGC/cmake/modules/FindSPIRVLLVMTranslator.cmake:52 (find_package_handle_standard_args)
  IGC/cmake/igc_spirv.cmake:59 (find_package)
  IGC/CMakeLists.txt:1267 (include)

When trying to manually pass relevant CMake options like:

-DSPIRVLLVMTranslator_INCLUDE_DIR:PATH=/usr/x86_64-pc-linux-gnu/lib/llvm/13/include
-DSPIRVLLVMTranslator_Library:PATH=/usr/x86_64-pc-linux-gnu/lib/llvm/13/lib
-DSPIRVLLVMTranslator_Tool:PATH=/usr/x86_64-pc-linux-gnu/lib/llvm/13/bin

igc fails to build with:

/var/tmp/paludis/build/dev-util-intel-graphics-compiler-1.0.10395/work/intel-graphics-compiler-1.0.10395/IGC/VectorCompiler/lib/Driver/SPIRVWrapper.cpp:21:10: fatal error: LLVMSPIRVLib.h: No such file or directory
   21 | #include "LLVMSPIRVLib.h"
      |          ^~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [IGC/VectorCompiler/lib/Driver/CMakeFiles/VCDriver.dir/build.make:93: IGC/VectorCompiler/lib/Driver/CMakeFiles/VCDriver.dir/SPIRVWrapper.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs...

CMakeCache.txt from build directory:

//No help, variable specified on the command line.
SPIRVLLVMTranslator_INCLUDE_DIR:PATH=/usr/x86_64-pc-linux-gnu/lib/llvm/13/include

Additional information:

$ ls -la /usr/x86_64-pc-linux-gnu/lib/llvm/13/include/LLVMSPIRVLib/
insgesamt 32
drwxr-xr-x 2 root root 4096  2. Mär 14:08 .
drwxr-xr-x 9 root root 4096 14. Feb 08:49 ..
-rw-r--r-- 1 root root 1534  2. Mär 14:07 LLVMSPIRVExtensions.inc
-rw-r--r-- 1 root root 9269  2. Mär 14:07 LLVMSPIRVLib.h
-rw-r--r-- 1 root root 7879  2. Mär 14:07 LLVMSPIRVOpts.h
$ PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/x86_64-pc-linux-gnu/lib/llvm/13/lib/pkgconfig pkg-config --cflags LLVMSPIRVLib
-I/usr/x86_64-pc-linux-gnu/lib/llvm/13/include
$ cat /usr/x86_64-pc-linux-gnu/lib/llvm/13/lib/pkgconfig/LLVMSPIRVLib.pc 
prefix=/usr/x86_64-pc-linux-gnu/lib/llvm/13
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include

Name: LLVMSPIRVLib
Description: LLVM/SPIR-V bi-directional translator
Version: 13.0.0.0
URL: https://github.com/KhronosGroup/SPIRV-LLVM-Translator

Libs: -L${libdir} -lLLVMSPIRVLib
Cflags: -I${includedir}
tgurr commented 2 years ago

The following appears to at least work around the issue (for me):

CMake Options:

-DSPIRVLLVMTranslator_INCLUDE_DIR:PATH=/usr/$(exhost --target)/lib/llvm/13/include
-DSPIRVLLVMTranslator_Library:PATH=/usr/$(exhost --target)/lib/llvm/13/lib/libLLVMSPIRVLib.a

Code changes:

sed \
    -e "s:LLVMSPIRVLib.h:LLVMSPIRVLib/LLVMSPIRVLib.h:g" 
    -i "${CMAKE_SOURCE}"/IGC/VectorCompiler/lib/Driver/SPIRVWrapper.cpp
tgurr commented 2 years ago

Further testing showed that passing the following CMake options

-DSPIRVLLVMTranslator_INCLUDE_DIR:PATH=/usr/$(exhost --target)/lib/llvm/13/include/LLVMSPIRVLib
-DSPIRVLLVMTranslator_Library:PATH=/usr/$(exhost --target)/lib/llvm/13/lib/libLLVMSPIRVLib.a

also seem to be enough.

While it's unfortunate it doesn't work out of the box with plain pkg-config (even when trying to pass the additional search location /usr/x86_64-pc-linux-gnu/lib/llvm/13/lib/pkgconfig as stated above I'm closing the issue as with the correct CMake options it's possible to build without any further changes. The thing which was not obvious and caused the most problems is that SPIRVLLVMTranslator_Library expects the library itself and not a search path like usually seen, that look me a lot of time to figure out as the error messages weren't quite obvious.