Skip to content

Commit fea14d7

Browse files
Change SPV_KHR_bfloat16 workaround patch to work for different drivers
Signed-off-by: Whitney Tsang <[email protected]>
1 parent 5c4ddd5 commit fea14d7

File tree

3 files changed

+37
-41
lines changed

3 files changed

+37
-41
lines changed

setup.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -489,15 +489,6 @@ def build_extension(self, ext):
489489
cmake_args.append("-DLLVM_EXTERNAL_LIT=" + lit_dir)
490490
cmake_args.extend(thirdparty_cmake_args)
491491

492-
result = subprocess.run(["bash", "./scripts/capture-hw-details.sh"], stdout=subprocess.PIPE,
493-
stderr=subprocess.PIPE, check=True, text=True, env=os.environ.copy())
494-
agama_version = None
495-
for line in result.stdout.splitlines():
496-
if line.startswith("AGAMA_VERSION="):
497-
agama_version = line.split("=", 1)[1].strip()
498-
break
499-
cmake_args.append(f"-DAGAMA_VERSION={agama_version}")
500-
501492
# configuration
502493
cfg = get_build_type()
503494
build_args = ["--config", cfg]

third_party/intel/cmake/3122.patch

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
diff --git a/lib/SPIRV/SPIRVWriter.cpp b/lib/SPIRV/SPIRVWriter.cpp
2-
index a124ba48c..3f46b5685 100644
2+
index ec4ec41f..9cad08d8 100644
33
--- a/lib/SPIRV/SPIRVWriter.cpp
44
+++ b/lib/SPIRV/SPIRVWriter.cpp
5-
@@ -397,6 +397,7 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
6-
}
5+
@@ -401,13 +401,15 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
76
}
87

9-
+#if 0
108
if (T->isBFloatTy()) {
11-
BM->getErrorLog().checkError(
12-
BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_bfloat16),
13-
@@ -406,6 +407,7 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
14-
"requires this extension");
15-
return mapType(T, BM->addFloatType(16, FPEncodingBFloat16KHR));
9+
- BM->getErrorLog().checkError(
10+
- BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_bfloat16),
11+
- SPIRVEC_RequiresExtension,
12+
- "SPV_KHR_bfloat16\n"
13+
- "NOTE: LLVM module contains bfloat type, translation of which "
14+
- "requires this extension");
15+
- return mapType(T, BM->addFloatType(16, FPEncodingBFloat16KHR));
16+
+ if (BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_bfloat16)) {
17+
+ BM->getErrorLog().checkError(
18+
+ BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_bfloat16),
19+
+ SPIRVEC_RequiresExtension,
20+
+ "SPV_KHR_bfloat16\n"
21+
+ "NOTE: LLVM module contains bfloat type, translation of which "
22+
+ "requires this extension");
23+
+ return mapType(T, BM->addFloatType(16, FPEncodingBFloat16KHR));
24+
+ }
1625
}
17-
+#endif
1826

1927
if (T->isFloatingPointTy())
20-
return mapType(T, BM->addFloatType(T->getPrimitiveSizeInBits()));

third_party/intel/cmake/FindSPIRVToLLVMTranslator.cmake

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,27 @@ if (NOT SPIRVToLLVMTranslator_FOUND)
2727
FetchContent_MakeAvailable(spirv-llvm-translator)
2828

2929
# FIXME: Don't apply patch when LTS driver is updated.
30-
if(DEFINED AGAMA_VERSION AND AGAMA_VERSION STREQUAL "1146")
30+
execute_process(
31+
COMMAND git apply --check ${CMAKE_CURRENT_LIST_DIR}/3122.patch
32+
WORKING_DIRECTORY ${spirv-llvm-translator_SOURCE_DIR}
33+
ERROR_QUIET
34+
RESULT_VARIABLE PATCH_RESULT
35+
)
36+
if(PATCH_RESULT EQUAL 0)
3137
execute_process(
32-
COMMAND git apply --check ${CMAKE_CURRENT_LIST_DIR}/3122.patch
33-
WORKING_DIRECTORY ${spirv-llvm-translator_SOURCE_DIR}
34-
ERROR_QUIET
35-
RESULT_VARIABLE PATCH_RESULT
38+
COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/3122.patch
39+
WORKING_DIRECTORY ${spirv-llvm-translator_SOURCE_DIR}
40+
RESULT_VARIABLE PATCH_RESULT
3641
)
37-
if(PATCH_RESULT EQUAL 0)
38-
execute_process(
39-
COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/3122.patch
40-
WORKING_DIRECTORY ${spirv-llvm-translator_SOURCE_DIR}
41-
RESULT_VARIABLE PATCH_RESULT
42-
)
43-
else()
44-
execute_process( # Check if the patch is already applied
45-
COMMAND git apply --reverse --check ${CMAKE_CURRENT_LIST_DIR}/3122.patch
46-
WORKING_DIRECTORY ${spirv-llvm-translator_SOURCE_DIR}
47-
RESULT_VARIABLE PATCH_RESULT
48-
)
49-
endif()
50-
if(NOT PATCH_RESULT EQUAL 0)
51-
message(FATAL_ERROR "Failed to apply 3122.patch to SPIRV-LLVM-Translator")
52-
endif()
42+
else()
43+
execute_process( # Check if the patch is already applied
44+
COMMAND git apply --reverse --check ${CMAKE_CURRENT_LIST_DIR}/3122.patch
45+
WORKING_DIRECTORY ${spirv-llvm-translator_SOURCE_DIR}
46+
RESULT_VARIABLE PATCH_RESULT
47+
)
48+
endif()
49+
if(NOT PATCH_RESULT EQUAL 0)
50+
message(FATAL_ERROR "Failed to apply 3122.patch to SPIRV-LLVM-Translator")
5351
endif()
5452

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

0 commit comments

Comments
 (0)