Troubleshooting LLVM15 Build Failures With Intel Graphics Compiler
Building the Intel Graphics Compiler (IGC) with LLVM15 can sometimes be a challenging task. This article addresses common build failures encountered when following the official build instructions and provides solutions to resolve them. We will delve into specific error messages and configuration options to guide you through a successful build process. This comprehensive guide aims to equip you with the knowledge to tackle LLVM15 build issues effectively.
Understanding the Initial Build Failure
When attempting to build IGC following the instructions provided in the official documentation, you might encounter a CMake error that prevents the project from configuring successfully. This typically manifests as a failure to locate the LLVM package, as indicated by the following error message:
CMake Error at IGC/cmake/igc_llvm.cmake:14 (find_package):
Could not find a package configuration file provided by "LLVM" (requested
version 15.0.7) with any of the following names:
LLVMConfig.cmake
llvm-config.cmake
Add the installation prefix of "LLVM" to CMAKE_PREFIX_PATH or set
"LLVM_DIR" to a directory containing one of the above files. If "LLVM"
provides a separate development package or SDK, be sure it has been
installed.
Call Stack (most recent call first):
IGC/CMakeLists.txt:1394 (include)
-- Configuring incomplete, errors occurred!
Diagnosing the Missing LLVM Package
This error arises because CMake cannot locate the necessary LLVM build files. This can happen if LLVM is not installed in a standard location or if the environment variables required for CMake to find it are not set. The initial cmake
command in the provided script attempts to build IGC against a pre-built LLVM installation. When it fails to find one, this error is thrown. This issue highlights the importance of ensuring that all dependencies, especially LLVM, are correctly installed and accessible during the build process.
Resolving the LLVM Package Issue
To address this, one approach is to instruct IGC to build LLVM from source. This ensures that the correct version of LLVM is used and that all necessary components are available. We can achieve this by setting specific CMake options that point to the LLVM source code and related components. This method provides a self-contained build environment, reducing the reliance on external installations and potential version conflicts. This method is generally more reliable, albeit potentially more time-consuming, as it involves building LLVM from scratch.
Building LLVM from Source: A Deeper Dive
To build LLVM from source, additional CMake options must be provided to guide the build process. These options specify the source directories for LLVM, Clang, LLD, SPIRV-LLVM-Translator, and other related projects. This approach offers greater control over the build environment, ensuring that all components are built in a consistent manner. However, it also requires careful configuration to avoid conflicts and ensure that all dependencies are correctly linked.
The Correct CMake Command for Source Build
The following cmake
command demonstrates the correct way to configure the build when using LLVM source:
cmake -S "${BUILD_FOLDER}/igc" \
-B "${BUILD_FOLDER}/build" \
-DCMAKE_POLICY_DEFAULT_CMP0002="OLD" \
-DCMAKE_POLICY_DEFAULT_CMP0079="NEW" \
-DIGC_OPTION__LLVM_MODE="Source" \
-DIGC_OPTION__LLD_MODE="Source" \
-DIGC_OPTION__CLANG_MODE="Source" \
-DIGC_OPTION__SPIRV_TOOLS_MODE="Source" \
-DIGC_OPTION__SPIRV_TRANSLATOR_MODE="Source" \
-DDEFAULT_IGC_LLVM_SOURCES_DIR:PATH="${BUILD_FOLDER}/llvm-project" \
-DDEFAULT_SPIRV_TRANSLATOR_SOURCE_DIR:PATH="${BUILD_FOLDER}/llvm-project/llvm/projects/llvm-spirv" \
-DIGC_OPTION__CLANG_SOURCES_DIR:PATH="${BUILD_FOLDER}/llvm-project/clang" \
-DIGC_OPTION__LLD_SOURCES_DIR:PATH="${BUILD_FOLDER}/llvm-project/lld" \
-DIGC_OPTION__LLVM_SOURCES_DIR:PATH="${BUILD_FOLDER}/llvm-project" \
-DIGC_OPTION__VC_INTRINSICS_SOURCES_DIR:PATH="${BUILD_FOLDER}/vc-intrinsics" \
-DIGC_OPTION__lld_SOURCES_DIR:PATH="${BUILD_FOLDER}/llvm-project/lld" \
-DSPIRV-Headers_SOURCE_DIR:PATH="${BUILD_FOLDER}/SPIRV-Headers" \
-DSPIRV-Tools_SOURCE_DIR:PATH="${BUILD_FOLDER}/SPIRV-Tools" \
-DCMAKE_BUILD_TYPE=Release \
-Wno-dev
Key CMake Options Explained
Let's break down the critical CMake options used in this command:
-DCMAKE_POLICY_DEFAULT_CMP0002="OLD"
and-DCMAKE_POLICY_DEFAULT_CMP0079="NEW"
: These options manage CMake compatibility policies. Setting these policies ensures that the build process behaves as expected with the specified CMake version. Proper management of CMake policies is crucial for maintaining build consistency across different environments.-DIGC_OPTION__LLVM_MODE="Source"
,-DIGC_OPTION__LLD_MODE="Source"
,-DIGC_OPTION__CLANG_MODE="Source"
,-DIGC_OPTION__SPIRV_TOOLS_MODE="Source"
, and-DIGC_OPTION__SPIRV_TRANSLATOR_MODE="Source"
: These options instruct IGC to build LLVM, LLD, Clang, SPIRV-Tools, and SPIRV-LLVM-Translator from source code. This is the core of building LLVM from source, ensuring that the correct versions of these components are used and built together. Building from source provides the highest level of control and consistency in the build process.-DDEFAULT_IGC_LLVM_SOURCES_DIR:PATH="${BUILD_FOLDER}/llvm-project"
,-DDEFAULT_SPIRV_TRANSLATOR_SOURCE_DIR:PATH="${BUILD_FOLDER}/llvm-project/llvm/projects/llvm-spirv"
,-DIGC_OPTION__CLANG_SOURCES_DIR:PATH="${BUILD_FOLDER}/llvm-project/clang"
,-DIGC_OPTION__LLD_SOURCES_DIR:PATH="${BUILD_FOLDER}/llvm-project/lld"
,-DIGC_OPTION__LLVM_SOURCES_DIR:PATH="${BUILD_FOLDER}/llvm-project"
: These options specify the paths to the source directories for LLVM, SPIRV-LLVM-Translator, Clang, and LLD. Correctly setting these paths is essential for CMake to locate the source code and build the components. Incorrect paths will lead to build failures, as CMake will be unable to find the required source files.-DIGC_OPTION__VC_INTRINSICS_SOURCES_DIR:PATH="${BUILD_FOLDER}/vc-intrinsics"
,-DSPIRV-Headers_SOURCE_DIR:PATH="${BUILD_FOLDER}/SPIRV-Headers"
,-DSPIRV-Tools_SOURCE_DIR:PATH="${BUILD_FOLDER}/SPIRV-Tools"
: These options provide the paths to the source directories for vc-intrinsics, SPIRV-Headers, and SPIRV-Tools. These components are dependencies of IGC, and specifying their source directories ensures that they are correctly included in the build process. Proper handling of dependencies is crucial for a successful build.-DCMAKE_BUILD_TYPE=Release
: This option sets the build type to