intel / intel-graphics-compiler

Other
606 stars 158 forks source link

Assertion failure loading SPIR-V code #175

Closed maleadt closed 3 years ago

maleadt commented 3 years ago

The following LLVM code:

source_filename = "text"
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-unknown"

define [1 x float] @child() {
top:
  ret [1 x float] undef
}

define void @kernel() {
top:
  %0 = call fastcc [1 x float] @child()
  %extract = extractvalue [1 x float] %0, 0
  ret void
}

... translated to SPIR-V using https://github.com/KhronosGroup/SPIRV-LLVM-Translator:

119734787 65536 393230 16 0 
2 Capability Addresses 
2 Capability Linkage 
2 Capability Kernel 
2 Capability Int64 
5 ExtInstImport 1 "OpenCL.std"
3 MemoryModel 2 2 
3 Source 0 0 
4 Name 7 "child"
3 Name 8 "top"
4 Name 12 "kernel"
3 Name 13 "top"
4 Name 15 "extract"
6 Decorate 7 LinkageAttributes "child" Export 
6 Decorate 12 LinkageAttributes "kernel" Export 
4 TypeInt 2 64 0 
5 Constant 2 3 1 0 
3 TypeFloat 4 32 
4 TypeArray 5 4 3 
3 TypeFunction 6 5 
2 TypeVoid 10 
3 TypeFunction 11 10 
3 Undef 5 9 

5 Function 5 7 0 6 

2 Label 8 
2 ReturnValue 9 

1 FunctionEnd 

5 Function 10 12 0 11 

2 Label 13 
4 FunctionCall 5 14 7 
5 CompositeExtract 4 15 14 0 
1 Return 

1 FunctionEnd

bug.spv.zip

... results in a failed assertion when loading with Level Zero or doing ocloc -device kbl -spirv_input:

../IGC/AdaptorCommon/TypesLegalizationPass.cpp:289: llvm::Value* TypesLegalizationPass::ResolveValue(llvm::Instruction*, llvm::Value*, llvm::SmallVector<unsigned int, 8>&): Assertion `0' failed.
signal (6): Aborted
in expression starting at none:1
gsignal at /usr/lib/libc.so.6 (unknown line)
abort at /usr/lib/libc.so.6 (unknown line)
__assert_fail_base.cold at /usr/lib/libc.so.6 (unknown line)
__assert_fail at /usr/lib/libc.so.6 (unknown line)
ResolveValue at /workspace/srcdir/intel-graphics-compiler/build/../IGC/AdaptorCommon/TypesLegalizationPass.cpp:289
ResolveExtractValue at /workspace/srcdir/intel-graphics-compiler/build/../IGC/AdaptorCommon/TypesLegalizationPass.cpp:309
LegalizeTypes at /workspace/srcdir/intel-graphics-compiler/build/../IGC/AdaptorCommon/TypesLegalizationPass.cpp:168
runOnFunction at /workspace/srcdir/intel-graphics-compiler/build/../IGC/AdaptorCommon/TypesLegalizationPass.cpp:369
runOnFunction at /workspace/srcdir/intel-graphics-compiler/build/IGC/llvm/src/llvm/lib/IR/LegacyPassManager.cpp:1481
runOnModule at /workspace/srcdir/intel-graphics-compiler/build/IGC/llvm/src/llvm/lib/IR/LegacyPassManager.cpp:1517
runOnModule at /workspace/srcdir/intel-graphics-compiler/build/IGC/llvm/src/llvm/lib/IR/LegacyPassManager.cpp:1582
run at /workspace/srcdir/intel-graphics-compiler/build/IGC/llvm/src/llvm/lib/IR/LegacyPassManager.cpp:1694
run at /workspace/srcdir/intel-graphics-compiler/build/IGC/llvm/src/llvm/lib/IR/LegacyPassManager.cpp:1725
ReadSPIRV at /workspace/srcdir/intel-graphics-compiler/build/../IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp:4422
ParseInput at /workspace/srcdir/intel-graphics-compiler/build/../IGC/AdaptorOCL/dllInterfaceCompute.cpp:718
TranslateBuild at /workspace/srcdir/intel-graphics-compiler/build/../IGC/AdaptorOCL/dllInterfaceCompute.cpp:984
Translate at /workspace/srcdir/intel-graphics-compiler/build/../IGC/AdaptorOCL/ocl_igc_interface/impl/igc_ocl_translation_ctx_impl.h:275
TranslateImpl at /workspace/srcdir/intel-graphics-compiler/build/../IGC/AdaptorOCL/ocl_igc_interface/impl/igc_ocl_translation_ctx_impl.cpp:70
Translate<> at /workspace/destdir/include/igc/ocl_igc_interface/igc_ocl_translation_ctx.h:109
translate<IGC::IgcOclTranslationCtx<3> > at /workspace/srcdir/compute-runtime/build/../shared/source/compiler_interface/compiler_interface.inl:77
build at /workspace/srcdir/compute-runtime/build/../shared/source/compiler_interface/compiler_interface.cpp:137
buildFromSpirV at /workspace/srcdir/compute-runtime/build/../level_zero/core/source/module/module_imp.cpp:135
initialize at /workspace/srcdir/compute-runtime/build/../level_zero/core/source/module/module_imp.cpp:360
create at /workspace/srcdir/compute-runtime/build/../level_zero/core/source/module/module_imp.cpp:589
createModule at /workspace/srcdir/compute-runtime/build/../level_zero/core/source/device/device_imp.cpp:216
createModule at /workspace/srcdir/compute-runtime/build/../level_zero/core/source/context/context_imp.cpp:201
zeModuleCreate at /workspace/srcdir/compute-runtime/build/../level_zero/api/core/ze_module.cpp:19

Seems similar to https://github.com/intel/intel-graphics-compiler/issues/159 (cc @aratajew). Tested on https://github.com/intel/intel-graphics-compiler/commit/5ef516712cb51d6fc92e88b28d48bf7548d2f0f6.

aratajew commented 3 years ago

Fixed, please try https://github.com/intel/intel-graphics-compiler/commit/cfc0c744c78bc652e43bea3be905188369d24ead.

maleadt commented 3 years ago

Hm, I'm having troubles compiling that commit:

[09:27:36] ../IGC/VectorCompiler/lib/GenXCodeGen/GenXVectorDecomposer.cpp: In member function ‘bool llvm::VectorDecomposer::determineDecomposition(llvm::Instruction*)’:
[09:27:36] ../IGC/VectorCompiler/lib/GenXCodeGen/GenXVectorDecomposer.cpp:210:28: error: ‘isReadPredefReg’ is not a member of ‘llvm::GenXIntrinsic’
[09:27:36]          if (GenXIntrinsic::isReadPredefReg(NewVal->getOperand(
[09:27:36]                             ^~~~~~~~~~~~~~~

[09:27:47] ../IGC/VectorCompiler/lib/GenXCodeGen/GenXPatternMatch.cpp: In member function ‘bool {anonymous}::MadMatcher::emit()’:
[09:27:47] ../IGC/VectorCompiler/lib/GenXCodeGen/GenXPatternMatch.cpp:1319:35: error: ‘getGenXMulIID’ is not a member of ‘llvm::GenXIntrinsic’
[09:27:47]          auto IID = GenXIntrinsic::getGenXMulIID(S0, S1);
[09:27:47]                                    ^~~~~~~~~~~~~
[09:27:47] ../IGC/VectorCompiler/lib/GenXCodeGen/GenXPatternMatch.cpp:1319:35: note: suggested alternative: ‘getGenXType’
[09:27:47]          auto IID = GenXIntrinsic::getGenXMulIID(S0, S1);
[09:27:47]                                    ^~~~~~~~~~~~~
[09:27:47]                                    getGenXType

etc. Am I missing a dependency bump? I normally wait for releases and use the hashes from there. EDIT: https://github.com/intel/vc-intrinsics/commit/069ced1e8a408d8b602b3b210017603792df6260 does the job.

maleadt commented 3 years ago

The fix works, thanks.