Open ecs-deutschland-gmbh opened 2 years ago
This is really an llvm/clang issue, so perhaps better to file it there.
The issue that we don't support "common" symbols currently (Common symbols are not yet implemented for Wasm
) and I guess OpenMP is using them? I don't think we have any plans to add support for common symbols.
For the immediate error here, "Common symbols are not yet implemented for Wasm", ideally we should figure out why clang is using common symbols for OpenMP and whether that can be changed.
But beyond that, for OpenMP to be actually usable, it will need support for threads too. Since you're using a WASI target, threads for non-Web wasm environments where Workers aren't available is not yet designed; the following issues have some discussion:
WebAssembly/threads#8 WebAssembly/threads#95 WebAssembly/threads#138
Thanks. I did indeed open issue 52714 @llvm-project.
I think, in a first step, after being able to compile something with #pragma openmp, an embedder could use an own approach for libomp imports (kmp_* functions). This would also include creation and management of the worker threads.
Everything else related to atomics should be fine.
However, a big obstacle COULD be if the omp compilation output tries to do something to the stack directly, which of course could be the case for the "more normal" targets, x86 etc.
Regards, S.
I've done something like that before, though it is in very rough POC stage and is blocked on runtime support.
@ecs-commonA you are absolutely right, if 'kmp' symbols are defined OpenMP program should build. The tricky part is defining them to being something meaningful. Normally those are defined by openmp runtime (-DLLVM_ENABLE_RUNTIMES=openmp
in LLVM build) and represent an API to fork off (outlined) worker functions. For running in the browser it should be possible to export a wrapper around WebWorkers to spawn off openmp 'threads' from the fork function, this is already done to compile some threaded code. For standalone it isn't obvious what to do yet.
However, a big obstacle COULD be if the omp compilation output tries to do something to the stack directly, which of course could be the case for the "more normal" targets, x86 etc.
I am not sure that would be a problem. OpenMP data is passed via heap pointers, and ident structures that guide execution are also heap allocated, I think. I think use of common symbols for critical sections is a bigger issue.
Some further pointers. It would be necessary to get some handle on OpenMP data structures - they are produced by Clang, it would be important to have compatible structures it in Wasm. If you are interested in WebWorkers possible gotchas include inability to suspend main thread and lack of explicit join
.
Are you interesting in implementing an OpenMP prototype using WebWorkers (Web/JS usecase)? I can try to help. Standalone might be possible in the future (see issues linked above).
Hi,
has anyone thought about it yet? So far - not even thinking of compiling libomp to wasm - even a minimal example fails in the backend, e.g.:
Can anyone oversee what must be implemented to achieve this?
Thanks, S.