Add openmp library from llvm - #27073
Conversation
|
Thanks a lot for looking into this. I'm looking forward to this for supporting openmp with clang-repl in the browser ! |
|
@anutosh491 tests are resolved. But I haven't tried it on my app yet. |
|
hi, @JAicewizard have you taken a look yet? |
|
@sbc100 can you help to review? |
|
We should probably add this the ChangeLog too. |
|
Interested to know which release would/could this be a part of ? |
|
All changes always go into the next release. In this case that next release is going to be 6.0.3. |
|
Thanks for getting this finished! It was quite a bit of work to get it working initially, but getting merged was a longer process than anticipated. I'm happy someone got finishing it and getting this merged! |
|
Also noticed that the final squashed commit doesn't have me as co-autho, probably because of how github works. Would it be possible to add credits on the changelog? |
|
Oh sorry about that, yes we can add you to AUTHORS (And the release notes) for sure. Would you mind send a PR adding your name to AUTHORS? |
|
So is this from LLVM 21.1.8 or 22.1.8? (The README says 21.1.8, but I'm just making sure, because the current latest version is 22.1.8) And do we expect to update OpenMP with other LLVM libraries (comiler-rt, libc, libcxx, libcxxabi, and libunwind) going forward? |
|
To answer the second question, yes we should update each time there is an LLVM stable release. |
|
I'm pretty sure this version of openmp was imported from the |
|
Yeah I took it from the latest HEAD of the emscripten fork for llvm. |
This is neither |
|
No idea. Ask the maintainers on what procedure to follow. |
|
IIRC there are no local patches, so you should be able to just run the update_openmp.py script to update our local copy to emscripten-libs-22. |
|
@duerrbaby We don't have any local patches on top of the tot? |
|
IIRC we only have one test so far: test_openmp_max_threads (but becuase its in test_core.py can be run in many different modes I guess). |
|
I did land one change to openmp. Doing run of |
|
@duerrbaby @sbc100 @kripken Thank you for working through this. I haven't had a chance to try this, but prior to this PR i was compiling openmp manually and linking it to my module. There was still one gap that still exists between what i need and what is upstream in llvm. I am curious if there is any insight from the emscripten/binaryen maintainers . Its related to how openmp invoked microtasks. __kmp_invoke_microtask You will notice that specifically for WebAssembly, a change was made to make sure each function pointers has an explicit cast to avoid a runtime error (The code has since been shifted since it was originally added) For my version of openmp i have to apply a patch that expands this all the way to
// we really only need the case with 1 argument, because CLANG always build
// a struct of pointers to shared variables referenced in the outlined function
int __kmp_invoke_microtask(microtask_t pkfn, int gtid, int tid, int argc,
void *p_argv[]To me this smells like some underlying issue. It also appear that a lot of "__kmp_invoke_microtask" implementations are actually in assembly instead of c++. Maybe that would be a better approach for WebAssembly? |
|
It seems like the limit on the number of args in a microtask is hardcoded into llvm and not really specific to WebAssembly. I think you might be better of opening an issue upstream in LLVM where this code lives. Sadly swtiching to assembly I don't think will help with the WebAssembly build because we still have the issue call_indirect must have the correct signature. That comment on __kmp_invoke_microtask does seem very strange. If the 1 argument case is all that is needed, why do that allow up to 15 args? And why are you seeing up to 25? These are all really question for upstream I think and not specific to emscripten or related to binaryen I believe. |
|
Yea I can try to bring it up there. I started here because it seems strange that when running under Webassembly/emscripten toolchain I hit the >15 path but on a native build I don't see that. Sort of why I had a suspicion on the optimizer. I suppose I can test this assumption by just not optimizing |
|
Did you try a native build an one of the architectures that doesn't implement __kmp_invoke_microtask in asm? i.e. that actually uses that switch statement? |
|
@sbc100 Thanks! Turns out that this is specific to how the non asm version of __kmp_invoke_microtask works. I was able to confirm that with my native binary the args do exceed 15 but the x86-64 assembly implementation handles it fine. I am going to submit a PR in llvm side, to add a test or two to show constraint and increase the headroom. That will leave it to the maintainers if they want to remove the hard constraint at all with more in depth signature changes |
This updates (?) OpenMP from 1823581ecb to LLVM 22.1.8: https://github.com/llvm/llvm-project/releases/tag/llvmorg-22.1.8 Because #27073 added OpenMP from then-LLVM-tot 1823581ecb, this is effectively not updating but downgrading to make this in sync with our other LLVM libraries. All `./test/runner *.test_openmp_max_threads` pass, except for `strict.test_openmp_max_threads`, which also fails in the main branch. Additional changes: - Apply the fix from #27289: 8f254a0 - Remove `kmp_invoke_microtask.cpp` from build: b104d06 This file was added in llvm/llvm-project#176151 and didn't exist in LLVM 22.1.8 release.
Original PR here: #25937
Imports the openmp library from LLVM and enables it using the standard -fopenmp flag.
When updating openmp, it needs to be compiled. This is not strictly necessary, but we need to invoke cmake in order to generate the headers. When compiling openmp, we need to make use of cmake as well, as the build system is quite long and complicated. I am sure it can be done another way using ninja, and I encourage others to implement this, but I do not have the capacity right now to make this happen.
Fixes: #13892, #17637