This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Add flag for setting debug in the offloading device
ClosedPublic

Authored by jhuber6 on Sep 9 2021, 1:43 PM.

Details

Summary

This patch introduces the flags -fopenmp-target-debug and
-fopenmp-target-debug= to set the value of a global in the device.
This will be used to enable or disable debugging features statically in
the device runtime library.

Diff Detail

Event Timeline

jhuber6 created this revision.Sep 9 2021, 1:43 PM
jhuber6 requested review of this revision.Sep 9 2021, 1:43 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptSep 9 2021, 1:43 PM
jdoerfert added inline comments.Sep 9 2021, 1:50 PM
clang/lib/Frontend/CompilerInvocation.cpp
3902

CUDANumSMs?

Don't check for NVPTX/AMDGCN but only if the new runtime is used, if not emit a warning that the flag is useless and ignored without the new runtime.

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
255

Linkage cannot be private, I think. It might be ok if we put it in the llvm.used global otherwise we should just make it external, which is probably best.

jhuber6 updated this revision to Diff 371737.Sep 9 2021, 3:41 PM

Addressing Comments.

jhuber6 updated this revision to Diff 371740.Sep 9 2021, 3:52 PM

Forgot to format.

jhuber6 updated this revision to Diff 371772.Sep 9 2021, 7:29 PM

Adding global regex to test.

jhuber6 updated this revision to Diff 371914.Sep 10 2021, 6:35 AM

Adding constant to llvm.used. This is most likely easier than dealing with weak external linkage.

This revision is now accepted and ready to land.Sep 10 2021, 2:27 PM
This revision was landed with ongoing or failed builds.Sep 10 2021, 3:19 PM
This revision was automatically updated to reflect the committed changes.
mgorny added a subscriber: mgorny.Sep 13 2021, 12:26 AM

This change causes clang-ast-dump to segfault for me while building clang:

[399/399] ASTNodeAPI.json
FAILED: tools/clang/lib/Tooling/ASTNodeAPI.json /home/mgorny/git/llvm-project/build/tools/clang/lib/Tooling/ASTNodeAPI.json 
cd /home/mgorny/git/llvm-project/build/tools/clang/lib/Tooling && /home/mgorny/git/llvm-project/build/bin/clang-ast-dump --skip-processing=0 -I /home/mgorny/git/llvm-project/build/lib/clang/14.0.0/include -I /home/mgorny/git/llvm-project/llvm/../clang/include -I /home/mgorny/git/llvm-project/build/tools/clang/include -I /home/mgorny/git/llvm-project/build/include -I /home/mgorny/git/llvm-project/llvm/include -I /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include/g++-v11 -I /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include/g++-v11/x86_64-pc-linux-gnu -I /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include/g++-v11/backward -I /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include -I /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include-fixed -I /usr/include --json-output-path /home/mgorny/git/llvm-project/build/tools/clang/lib/Tooling/ASTNodeAPI.json
ninja: build stopped: subcommand failed.
Reading symbols from /home/mgorny/git/llvm-project/build/bin/clang-ast-dump...
[New LWP 230743]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `/home/mgorny/git/llvm-project/build/bin/clang-ast-dump --skip-processing=0 -I /'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007ff222268a87 in llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul, 128ul>::~BumpPtrAllocatorImpl() ()
   from /home/mgorny/git/llvm-project/build/bin/../lib/../lib/libclangLex.so.14git
(gdb) bt
#0  0x00007ff222268a87 in llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul, 128ul>::~BumpPtrAllocatorImpl() ()
   from /home/mgorny/git/llvm-project/build/bin/../lib/../lib/libclangLex.so.14git
#1  0x00007ff2222a1404 in clang::HeaderSearch::~HeaderSearch() ()
   from /home/mgorny/git/llvm-project/build/bin/../lib/../lib/libclangLex.so.14git
#2  0x00007ff2222a1859 in clang::Preprocessor::~Preprocessor() ()
   from /home/mgorny/git/llvm-project/build/bin/../lib/../lib/libclangLex.so.14git
#3  0x00007ff224d3175c in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() ()
   from /home/mgorny/git/llvm-project/build/bin/../lib/libclangFrontend.so.14git
#4  0x00007ff224d4c801 in clang::CompilerInstance::~CompilerInstance() ()
   from /home/mgorny/git/llvm-project/build/bin/../lib/libclangFrontend.so.14git
#5  0x0000556c688f8a95 in main ()

I'm going to try RelWithDebInfo build but I'm afraid I don't have sufficient free space for that.

I'm sorry, it seems to have been caused by ccache. After clearing the cache, I can't reproduce anymore.

I'm sorry, it seems to have been caused by ccache. After clearing the cache, I can't reproduce anymore.

The problem is that clang-ast-dump has incomplete dependences and sometimes picks stuff up from the install folder.
If you delete install it works, ccache might have a similar effect.