New Package: intel-graphics-compiler

This commit is contained in:
KF-Art 2022-11-09 15:14:57 -05:00
parent 93e551dbe9
commit 4b29f70498
6 changed files with 202 additions and 0 deletions

View file

@ -0,0 +1 @@
intel-graphics-compiler

View file

@ -0,0 +1 @@
intel-graphics-compiler

View file

@ -0,0 +1,51 @@
From 12332c1ee8e92238c919ad7c2aa36119259cb622 Mon Sep 17 00:00:00 2001
From: Artem Gindinson <artem.gindinson@intel.com>
Date: Thu, 30 Jun 2022 10:22:31 +0000
Subject: [PATCH] Avoid duplicate entries into !opencl.kernels metadata with
LLVM 14
The LLVM 14 version of the SPIR-V Translator (and, consequently, OpenCL Clang)
introduces the kernel entry point wrappers functionality (see commit KhronosGroup/SPIRV-LLVM-Translator@85815e7).
As IGC's SPIR-V Reader collects root nodes for kernel argument metadata into
the `!opencl.kernels` module metadata, it treats SPIR-V entry point wrappers as
separate kernels despite that they are mapped onto the same LLVM function.
Consequently, each LLVM IR kernel function recieves a "duplicate" set of kernel
argument metadata, which breaks our kernel argument analysis passes upon a
switch to LLVM 14.
Do not update the module metadata upon encountering previously seen LLVM
functions.
This fixes https://github.com/intel/intel-graphics-compiler/issues/245.
---
IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp b/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp
index 708d96edd97..33441cf620c 100644
--- a/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp
+++ b/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp
@@ -58,6 +58,7 @@ THE SOFTWARE.
#include <llvm/Support/ScaledNumber.h>
#include <llvm/IR/IntrinsicInst.h>
#include <llvm/Analysis/CFG.h>
+#include <llvm/ADT/SmallSet.h>
#include "libSPIRV/SPIRVDebugInfoExt.h"
#include "llvmWrapper/Transforms/Utils/Cloning.h"
#include "common/LLVMWarningsPop.hpp"
@@ -4706,11 +4707,15 @@ SPIRVToLLVM::transKernelMetadata()
transCapsIntoMetadata(MD);
NamedMDNode *KernelMDs = M->getOrInsertNamedMetadata(SPIR_MD_KERNELS);
+ SmallSet<Function*, 16> HandledLLVMKernels;
for (unsigned I = 0, E = BM->getNumFunctions(); I != E; ++I)
{
SPIRVFunction *BF = BM->getFunction(I);
Function *F = static_cast<Function *>(getTranslatedValue(BF));
IGC_ASSERT_MESSAGE(F, "Invalid translated function");
+ if (HandledLLVMKernels.count(F))
+ continue;
+ HandledLLVMKernels.insert(F);
// __attribute__((annotate("some_user_annotation"))) are passed via
// UserSemantic decoration on functions.

View file

@ -0,0 +1,14 @@
--- a/IGC/cmake/igc_find_liblldELF.cmake
+++ b/IGC/cmake/igc_find_liblldELF.cmake
@@ -136,6 +136,11 @@ elseif(IGC_BUILD__LLVM_PREBUILDS)
${LLD_ELF_LLVM_DEPS}
lldCommon)
+ if(LLVM_ENABLE_ZLIB)
+ find_package(ZLIB)
+ target_link_libraries(lldELF INTERFACE ZLIB::ZLIB)
+ endif()
+
find_path(
LLD_INCLUDE_DIR
NAMES "Driver.h"

View file

@ -0,0 +1,76 @@
From 6a13fa903f380e17378286a7cd43995b0ae162ad Mon Sep 17 00:00:00 2001
From: Artem Gindinson <artem.gindinson@intel.com>
Date: Thu, 7 Jul 2022 08:49:48 +0000
Subject: [PATCH] Rework kernel metadata handling in SPIR-V Reader
After the introduction of kernel entry point wrappers within
KhronosGroup/SPIRV-LLVM-Translator@85815e7, initial approach to avoiding kernel
metadata duplication within our internal SPIR-V consumer has been to skip
metadata generation whenever we encounter the entry point kernel (we would
assume that all necessary metadata had already been assigned to the LLVM
function upon encountering the "actual" SPIR-V kernel). For more details on the
initial approach, see intel/intel-graphics-compiler@12332c1.
The change, however, did not take into account that all SPIR-V information
regarding the kernel execution mode was being stored exclusively for the entry
point wrapper kernel. Therefore, by skipping the SPIR-V entry point wrappers we
end up losing certain metadata entries, e.g. "required WG size".
Assume that the entry point wrappers contain fuller information and generate
LLVM metadata based on these SPIR-V functions instead. This fixes kernel
attributes' lowering with LLVM 14.
An alternative SPIR-V Reader solution would imply copying over all SPIR-V
information from entry point wrappers to the actual kernel body, and then
dropping entry point wrappers from the `SPIRVModule`'s/`SPIRVToLLVM`'s
function collections.
---
IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp b/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp
index 33441cf620c..29d098d7337 100644
--- a/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp
+++ b/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp
@@ -58,7 +58,6 @@ THE SOFTWARE.
#include <llvm/Support/ScaledNumber.h>
#include <llvm/IR/IntrinsicInst.h>
#include <llvm/Analysis/CFG.h>
-#include <llvm/ADT/SmallSet.h>
#include "libSPIRV/SPIRVDebugInfoExt.h"
#include "llvmWrapper/Transforms/Utils/Cloning.h"
#include "common/LLVMWarningsPop.hpp"
@@ -4707,15 +4706,11 @@ SPIRVToLLVM::transKernelMetadata()
transCapsIntoMetadata(MD);
NamedMDNode *KernelMDs = M->getOrInsertNamedMetadata(SPIR_MD_KERNELS);
- SmallSet<Function*, 16> HandledLLVMKernels;
for (unsigned I = 0, E = BM->getNumFunctions(); I != E; ++I)
{
SPIRVFunction *BF = BM->getFunction(I);
Function *F = static_cast<Function *>(getTranslatedValue(BF));
IGC_ASSERT_MESSAGE(F, "Invalid translated function");
- if (HandledLLVMKernels.count(F))
- continue;
- HandledLLVMKernels.insert(F);
// __attribute__((annotate("some_user_annotation"))) are passed via
// UserSemantic decoration on functions.
@@ -4727,6 +4722,17 @@ SPIRVToLLVM::transKernelMetadata()
if (F->getCallingConv() != CallingConv::SPIR_KERNEL || F->isDeclaration())
continue;
+ // Kernel entry point wrappers and SPIR-V functions with actual kernel
+ // body resolve to the same LLVM functions. Only generate metadata upon
+ // encountering entry point wrappers, as SPIR-V stores all execution
+ // mode information at the entry point wrapper site.
+ // TODO: Instead, consider copying all SPIR-V function information from
+ // entry point wrappers to the actual SPIR-V funtions, and then
+ // erasing entry point wrappers as such from the SPIRVModule/
+ // SPIRVToLLVM classes. Preferably, such a rework should be done in the
+ // Khronos SPIR-V Translator and then downstreamed.
+ if (!isOpenCLKernel(BF))
+ continue;
std::vector<llvm::Metadata*> KernelMD;
KernelMD.push_back(ValueAsMetadata::get(F));

View file

@ -0,0 +1,59 @@
# Template file for 'intel-graphics-compiler'
pkgname=intel-graphics-compiler
version=1.0.12260.1
revision=1
wrksrc=${pkgname}-igc-${version}
build_style=cmake
configure_args="-DIGC_OPTION__LLVM_PREFERRED_VERSION='12.0.1' \
-DIGC_OPTION__LINK_KHRONOS_SPIRV_TRANSLATOR=ON \
-DIGC_OPTION__CLANG_MODE=Prebuilds \
-DIGC_OPTION__LLD_MODE=Prebuilds \
-DIGC_OPTION__LLVM_MODE=Prebuilds \
-DIGC_OPTION__USE_PREINSTALLED_SPIRV_HEADERS=ON \
-DIGC_OPTION__SPIRV_TOOLS_MODE=Sources \
-DIGC_OPTION__SPIRV_TRANSLATOR_MODE=Prebuilds \
-DIGC_OPTION__VC_INTRINSICS_MODE=Prebuilds \
-DINSTALL_GENX_IR=ON \
-Wno-dev"
repository="cereus-extra"
makedepends="git clang lld-devel llvm python3-devel libunwind-devel SPIRV-Headers clang-tools-extra libxml2-devel zlib-devel SPIRV-LLVM-Translator-devel SPIRV-Tools-devel vc-intrinsics protobuf-devel libprotoc-devel intel-opencl-clang bison flex"
depends="libllvm12 ncurses SPIRV-Tools zlib"
short_desc="Intel Graphics Compiler for OpenCL"
maintainer="KF-Art <https://github.com/KF-Art>"
license="MIT"
homepage="https://github.com/intel/intel-graphics-compiler"
changelog="${homepage}/releases/tag/igc-${version}"
distfiles="${homepage}/archive/igc-${version}.tar.gz"
_spirv_url="https://github.com/KhronosGroup"
checksum=5079e8a01fc64c167ca6f96d0087513406664b9e8692d56479f7c69c19253d5d
post_extract() {
# Clone extra required build dependencies
# As for now, the compiler does not detect the prebuilt SPIRV-Tools and Headers.
if [ -d ../SPIRV-* ]; then
rm -rf ../SPIRV-*
fi
for repo in Tools Headers; do
git -C ../ clone ${_spirv_url}/SPIRV-${repo}.git
done
}
post_install() {
vlicense LICENSE.md
vlicense ${DESTDIR}/usr/lib/igc/NOTICES.txt
# Remove SPIRV builddir
rm -rf ../SPIRV*
}
intel-graphics-compiler-devel_package() {
depends="${sourcepkg}>=${version}_${revision}"
short_desc+=" - development files"
pkg_install() {
vmove usr/include
vmove usr/lib/pkgconfig
vmove usr/lib/*.so
}
}