Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,15 +489,6 @@ def build_extension(self, ext):
cmake_args.append("-DLLVM_EXTERNAL_LIT=" + lit_dir)
cmake_args.extend(thirdparty_cmake_args)

result = subprocess.run(["bash", "./scripts/capture-hw-details.sh"], stdout=subprocess.PIPE,
stderr=subprocess.PIPE, check=True, text=True, env=os.environ.copy())
agama_version = None
for line in result.stdout.splitlines():
if line.startswith("AGAMA_VERSION="):
agama_version = line.split("=", 1)[1].strip()
break
cmake_args.append(f"-DAGAMA_VERSION={agama_version}")

# configuration
cfg = get_build_type()
build_args = ["--config", cfg]
Expand Down
2 changes: 2 additions & 0 deletions third_party/intel/backend/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ def make_llir(cls, src, metadata, options):
@classmethod
@track
def make_spv(cls, src, metadata, options):
driver_version = metadata["target"].arch.get("driver_version")
os.environ["INTEL_XPU_BACKEND_DRIVER_VERSION"] = driver_version
spirv, name = intel.translate_to_spirv(src)
metadata["name"] = name
metadata.setdefault("build_flags", "")
Expand Down
37 changes: 26 additions & 11 deletions third_party/intel/cmake/3122.patch
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
diff --git a/lib/SPIRV/SPIRVWriter.cpp b/lib/SPIRV/SPIRVWriter.cpp
index a124ba48c..3f46b5685 100644
index ec4ec41f..b481609f 100644
--- a/lib/SPIRV/SPIRVWriter.cpp
+++ b/lib/SPIRV/SPIRVWriter.cpp
@@ -397,6 +397,7 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
}
@@ -401,13 +401,23 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
}

+#if 0
if (T->isBFloatTy()) {
BM->getErrorLog().checkError(
BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_bfloat16),
@@ -406,6 +407,7 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
"requires this extension");
return mapType(T, BM->addFloatType(16, FPEncodingBFloat16KHR));
- BM->getErrorLog().checkError(
- BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_bfloat16),
- SPIRVEC_RequiresExtension,
- "SPV_KHR_bfloat16\n"
- "NOTE: LLVM module contains bfloat type, translation of which "
- "requires this extension");
- return mapType(T, BM->addFloatType(16, FPEncodingBFloat16KHR));
+ // Workaround for LTS2 driver.
+ const char *driverVersion = std::getenv("INTEL_XPU_BACKEND_DRIVER_VERSION");
+ if (driverVersion) {
+ int v0 = 0, v1 = 0, v2 = 0, v3 = 0;
+ sscanf(driverVersion, "%d.%d.%d+%d", &v0, &v1, &v2, &v3);
+ std::tuple<int, int, int, int> ver = {v0, v1, v2, v3};
+ std::tuple<int, int, int, int> minVer = {1, 6, 35096, 9};
+ if (ver >= minVer) {
+ BM->getErrorLog().checkError(
+ BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_bfloat16),
+ SPIRVEC_RequiresExtension,
+ "SPV_KHR_bfloat16\n"
+ "NOTE: LLVM module contains bfloat type, translation of which "
+ "requires this extension");
+ return mapType(T, BM->addFloatType(16, FPEncodingBFloat16KHR));
+ }
+ }
}
+#endif

if (T->isFloatingPointTy())
return mapType(T, BM->addFloatType(T->getPrimitiveSizeInBits()));
40 changes: 19 additions & 21 deletions third_party/intel/cmake/FindSPIRVToLLVMTranslator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,27 @@ if (NOT SPIRVToLLVMTranslator_FOUND)
FetchContent_MakeAvailable(spirv-llvm-translator)

# FIXME: Don't apply patch when LTS driver is updated.
if(DEFINED AGAMA_VERSION AND AGAMA_VERSION STREQUAL "1146")
execute_process(
COMMAND git apply --check ${CMAKE_CURRENT_LIST_DIR}/3122.patch
WORKING_DIRECTORY ${spirv-llvm-translator_SOURCE_DIR}
ERROR_QUIET
RESULT_VARIABLE PATCH_RESULT
)
if(PATCH_RESULT EQUAL 0)
execute_process(
COMMAND git apply --check ${CMAKE_CURRENT_LIST_DIR}/3122.patch
WORKING_DIRECTORY ${spirv-llvm-translator_SOURCE_DIR}
ERROR_QUIET
RESULT_VARIABLE PATCH_RESULT
COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/3122.patch
WORKING_DIRECTORY ${spirv-llvm-translator_SOURCE_DIR}
RESULT_VARIABLE PATCH_RESULT
)
if(PATCH_RESULT EQUAL 0)
execute_process(
COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/3122.patch
WORKING_DIRECTORY ${spirv-llvm-translator_SOURCE_DIR}
RESULT_VARIABLE PATCH_RESULT
)
else()
execute_process( # Check if the patch is already applied
COMMAND git apply --reverse --check ${CMAKE_CURRENT_LIST_DIR}/3122.patch
WORKING_DIRECTORY ${spirv-llvm-translator_SOURCE_DIR}
RESULT_VARIABLE PATCH_RESULT
)
endif()
if(NOT PATCH_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to apply 3122.patch to SPIRV-LLVM-Translator")
endif()
else()
execute_process( # Check if the patch is already applied
COMMAND git apply --reverse --check ${CMAKE_CURRENT_LIST_DIR}/3122.patch
WORKING_DIRECTORY ${spirv-llvm-translator_SOURCE_DIR}
RESULT_VARIABLE PATCH_RESULT
)
endif()
if(NOT PATCH_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to apply 3122.patch to SPIRV-LLVM-Translator")
endif()

# FIXME: Don't apply patch when Agama driver is updated to incorporate with the SPV_INTEL_bfloat16_arithmetic extension.
Expand Down
Loading