Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when running pass 'Adapt OCL types for SPIR-V' on module 'builtins.link.spirv64-mesa3d-.bc' #55121

Closed
illwieckz opened this issue Apr 26, 2022 · 13 comments
Labels
backend:SPIR-V crash Prefer [crash-on-valid] or [crash-on-invalid] opaque-pointers OpenCL SPIR-V SPIR-V language support

Comments

@illwieckz
Copy link
Contributor

illwieckz commented Apr 26, 2022

I was compiling libclc from commit 5bd8735, llvm-spirv was also built using recent commit KhronosGroup/SPIRV-LLVM-Translator@55d1de8 .

llvm-spirv: include/llvm/IR/Type.h:384: llvm::Type *llvm::Type::getNonOpaquePointerElementType() const: Assertion `NumContainedTys && "Attempting to get element type of opaque pointer"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: llvm-spirv --spirv-max-version=1.1 -o spirv64-mesa3d-.spv builtins.link.spirv64-mesa3d-.bc
1.	Running pass 'Adapt OCL types for SPIR-V' on module 'builtins.link.spirv64-mesa3d-.bc'.
 #0 0x000000000102b6ba llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) llvm-project/llvm/lib/Support/Unix/Signals.inc:565:11
 #1 0x000000000102b86b PrintStackTraceSignalHandler(void*) llvm-project/llvm/lib/Support/Unix/Signals.inc:632:1
 #2 0x0000000001029f06 llvm::sys::RunSignalHandlers() llvm-project/llvm/lib/Support/Signals.cpp:103:5
 #3 0x000000000102bfa5 SignalHandler(int) llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
 #4 0x00007fe00f595520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x00007fe00f5e9828 __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007fe00f5e9828 __pthread_kill_internal ./nptl/pthread_kill.c:80:10
 #7 0x00007fe00f5e9828 pthread_kill ./nptl/pthread_kill.c:91:10
 #8 0x00007fe00f595476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #9 0x00007fe00f57b7b7 abort ./stdlib/abort.c:81:7
#10 0x00007fe00f57b6db get_sysdep_segment_value ./intl/loadmsgcat.c:509:8
#11 0x00007fe00f57b6db _nl_load_domain ./intl/loadmsgcat.c:970:34
#12 0x00007fe00f58ce26 (/lib/x86_64-linux-gnu/libc.so.6+0x39e26)
#13 0x000000000045f0b7 llvm::Type::getNonOpaquePointerElementType() const llvm-project/llvm/include/llvm/IR/Type.h:0:5
#14 0x0000000000507395 llvm::Type::getPointerElementType() const (llvm-spirv+0x507395)
#15 0x000000000052ea9d SPIRV::isPointerToOpaqueStructType(llvm::Type*) (llvm-spirv+0x52ea9d)
#16 0x00000000006e380d SPIRV::OCLTypeToSPIRVBase::adaptFunctionArguments(llvm::Function*) (llvm-spirv+0x6e380d)
#17 0x00000000006e3293 SPIRV::OCLTypeToSPIRVBase::runOCLTypeToSPIRV(llvm::Module&) (llvm-spirv+0x6e3293)
#18 0x00000000006e30d1 SPIRV::OCLTypeToSPIRVLegacy::runOnModule(llvm::Module&) (llvm-spirv+0x6e30d1)
#19 0x0000000000e1c6e9 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1545:23
#20 0x0000000000e1c25d llvm::legacy::PassManagerImpl::run(llvm::Module&) llvm-project/llvm/lib/IR/LegacyPassManager.cpp:535:16
#21 0x0000000000e20f61 llvm::legacy::PassManager::run(llvm::Module&) llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1672:3
#22 0x0000000000581832 llvm::writeSpirv(llvm::Module*, SPIRV::TranslatorOpts const&, std::ostream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) (llvm-spirv+0x581832)
#23 0x000000000042a69d convertLLVMToSPIRV(SPIRV::TranslatorOpts const&) llvm-spirv.cpp:0:0
#24 0x0000000000428212 main (llvm-spirv+0x428212)
#25 0x00007fe00f57cfd0 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#26 0x00007fe00f57d07d call_init ./csu/../csu/libc-start.c:128:20
#27 0x00007fe00f57d07d __libc_start_main ./csu/../csu/libc-start.c:379:5
#28 0x0000000000424ea5 _start (llvm-spirv+0x424ea5)
@EugeneZelenko EugeneZelenko added mlir:spirv crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Apr 26, 2022
@llvmbot
Copy link
Member

llvmbot commented Apr 26, 2022

@llvm/issue-subscribers-mlir-spirv

@joker-eph
Copy link
Collaborator

Not MLIR related as far as I can tell

@illwieckz
Copy link
Contributor Author

Purging build directories of llvm, clang, lib-clc and llvm-spriv and installation directory fixed it, it may be a cmake issue where it doesn't rebuild everything that is needed to be rebuilt on new commits. I won't investigate this more.

@illwieckz
Copy link
Contributor Author

illwieckz commented May 10, 2022

It appeared the bug disappearing on my end was not caused by building from scratch but by building older LLVM commit to workaround the compat-breaking changes of LLVM turning on opaque pointer by default that broke Mesa, see #54970. So it can be tagged opaque-pointers.

I assume it's now an llvm-spirv issue, see:

The error is now printed this way:

llvm-spirv: include/llvm/IR/Type.h:384: llvm::Type *llvm::Type::getNonOpaquePointerElementType() const: Assertion `NumContainedTys && "Attempting to get element type of opaque pointer"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: bin/llvm-spirv --spirv-max-version=1.1 -o spirv64-mesa3d-.spv builtins.link.spirv64-mesa3d-.bc
1.	Running pass 'Adapt OCL types for SPIR-V' on module 'builtins.link.spirv64-mesa3d-.bc'.
Build libclc: [ 99%] Built target opt.spirv-mesa3d-.bc
Build libclc: [ 99%] Built target prepare-clspv--.bc
Build libclc: [ 99%] Built target prepare-clspv64--.bc
 #0 0x00007f74b67c97e2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) llvm-project/llvm/lib/Support/Unix/Signals.inc:565:22
 #1 0x00007f74b67c98a9 PrintStackTraceSignalHandler(void*) llvm-project/llvm/lib/Support/Unix/Signals.inc:632:1
 #2 0x00007f74b67c7454 llvm::sys::RunSignalHandlers() llvm-project/llvm/lib/Support/Signals.cpp:103:20
 #3 0x00007f74b67c9113 SignalHandler(int) llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
 #4 0x00007f74b5011520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x00007f74b5065828 __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007f74b5065828 __pthread_kill_internal ./nptl/pthread_kill.c:80:10
 #7 0x00007f74b5065828 pthread_kill ./nptl/pthread_kill.c:91:10
 #8 0x00007f74b5011476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #9 0x00007f74b4ff77b7 abort ./stdlib/abort.c:81:7
#10 0x00007f74b4ff76db get_sysdep_segment_value ./intl/loadmsgcat.c:509:8
#11 0x00007f74b4ff76db _nl_load_domain ./intl/loadmsgcat.c:970:34
#12 0x00007f74b5008e26 (/lib/x86_64-linux-gnu/libc.so.6+0x39e26)
#13 0x000055f6364f4e97 llvm::Type::getNonOpaquePointerElementType() const (bin/llvm-spirv+0x10be97)
#14 0x000055f636594c65 llvm::Type::getPointerElementType() const (bin/llvm-spirv+0x1abc65)
#15 0x000055f6365b91bd SPIRV::isPointerToOpaqueStructType(llvm::Type*) (bin/llvm-spirv+0x1d01bd)
#16 0x000055f63675e93d SPIRV::OCLTypeToSPIRVBase::adaptFunctionArguments(llvm::Function*) (bin/llvm-spirv+0x37593d)
#17 0x000055f63675e3c3 SPIRV::OCLTypeToSPIRVBase::runOCLTypeToSPIRV(llvm::Module&) (bin/llvm-spirv+0x3753c3)
#18 0x000055f63675e201 SPIRV::OCLTypeToSPIRVLegacy::runOnModule(llvm::Module&) (bin/llvm-spirv+0x375201)
#19 0x00007f74b6abc94d (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1545:20
#20 0x00007f74b6ab767a llvm::legacy::PassManagerImpl::run(llvm::Module&) llvm-project/llvm/lib/IR/LegacyPassManager.cpp:535:13
#21 0x00007f74b6abd25f llvm::legacy::PassManager::run(llvm::Module&) llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1673:1
#22 0x000055f63660aba2 llvm::writeSpirv(llvm::Module*, SPIRV::TranslatorOpts const&, std::ostream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) (bin/llvm-spirv+0x221ba2)
#23 0x000055f6364c1db5 convertLLVMToSPIRV(SPIRV::TranslatorOpts const&) llvm-spirv.cpp:0:0
#24 0x000055f6364bf942 main (bin/llvm-spirv+0xd6942)
#25 0x00007f74b4ff8fd0 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#26 0x00007f74b4ff907d call_init ./csu/../csu/libc-start.c:128:20
#27 0x00007f74b4ff907d __libc_start_main ./csu/../csu/libc-start.c:379:5
#28 0x000055f6364bc5e5 _start (bin/llvm-spirv+0xd35e5)

@illwieckz
Copy link
Contributor Author

I reopen the issue because libclc cannot be built with llvm from the same repository using the same commit (through llvm-spirv).

Said otherwise, libclc cannot be built with llvm-spirv built with llvm from the same repository and commit as libclc.

Also llvm-spirv now requires clang 15 to be built, so it needs this repository and this branch.

A workaround or a fix is needed so libclc becomes buildable again, either by implementing a compatibility layer in llvm before llvm-spirv becomes opaque pointer compatible, either by making llvm-spirv opaque pointer compatible (see KhronosGroup/SPIRV-LLVM-Translator#1444 ).

It looks like one can do this:

  • build old llvm and clang after 15 branch started but before opaque pointers were turned on by default
  • build llvm-spirv with this old llvm and clang
  • rebuild llvm on main branch
  • build mesa clover with this llvm

but I don't think it's an acceptable workaround to actually need to build two different llvm revisions to build latest libclc from the same repository.

@llvmbot
Copy link
Member

llvmbot commented May 24, 2022

@llvm/issue-subscribers-opencl

@AnastasiaStulova
Copy link
Contributor

Do you know on which source file in libclc this failure occurs? My guess is that it will likely be something specific to images or other OpenCL specific types?

@jcranmer-intel
Copy link
Contributor

#15 0x000055f6365b91bd SPIRV::isPointerToOpaqueStructType(llvm::Type*) (bin/llvm-spirv+0x1d01bd)
#16 0x000055f63675e93d SPIRV::OCLTypeToSPIRVBase::adaptFunctionArguments(llvm::Function*) (bin/llvm-spirv+0x37593d)
#17 0x000055f63675e3c3 SPIRV::OCLTypeToSPIRVBase::runOCLTypeToSPIRV(llvm::Module&) (bin/llvm-spirv+0x3753c3)

This specific stack trace is I believe fixed by KhronosGroup/SPIRV-LLVM-Translator#1499, not that it actually finishes the conversion process for SPIR-V emission with opaque pointers (there is another PR I'm working on which should make much more code work, although "much more" is itself a far cry from "all").

What you can probably do to mitigate the damage until the translator is fixed is to compile libclc with opaque pointers disabled.

@michalpaszkowski michalpaszkowski added the SPIR-V SPIR-V language support label Oct 10, 2022
@nikic
Copy link
Contributor

nikic commented Apr 4, 2023

This issue can probably be closed now?

@illwieckz
Copy link
Contributor Author

illwieckz commented Apr 4, 2023

I'll try to reproduce the issue in the coming days to see if it's fixed.

@jcranmer-intel
Copy link
Contributor

At this point, the SPIR-V translator should be capable of handling everything as opaque pointers, save for some of the fancier extensions (e.g., Intel's function pointer extensions) that I'm pretty sure libclc doesn't use.

The SPIR-V backend is I think not yet supporting opaque pointers, but I don't think libclc is even configurable to use the native SPIR-V backend instead of the translator.

@illwieckz
Copy link
Contributor Author

I'm not able anymore to compile amdcn libclc targets with either llvm 17-git, 16.1.0 and 16.0.0 (I haven't tried older git references) because the build of a dependency of those target fails to build: #62018

So I cannot verify if that error is fixed or not.

@illwieckz
Copy link
Contributor Author

I fixed the build error preventing to build libclc (see #62018 for the build error and D150871 for the fix), so I'm able to build this again.

I don't experience this bug anymore. Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:SPIR-V crash Prefer [crash-on-valid] or [crash-on-invalid] opaque-pointers OpenCL SPIR-V SPIR-V language support
Projects
None yet
Development

No branches or pull requests

9 participants