Skip to content

Reland of #108413: [Offload] Introduce offload-tblgen and initial new API implementation #118503

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

Merged
merged 27 commits into from
Dec 3, 2024

Conversation

callumfare
Copy link
Contributor

This is another attempt to reland the changes from #108413

The previous two attempts introduced regressions and were reverted. This PR has been more thoroughly tested with various configurations so shouldn't cause any problems this time. If anyone is aware of any likely remaining problems then please let me know.

The changes are identical other than the fixes contained in the last 5 commits.


New API

Previous discussions at the LLVM/Offload meeting have brought up the need for a new API for exposing the functionality of the plugins. This change introduces a very small subset of a new API, which is primarily for testing the offload tooling and demonstrating how a new API can fit into the existing code base without being too disruptive. Exact designs for these entry points and future additions can be worked out over time.

The new API does however introduce the bare minimum functionality to implement device discovery for Unified Runtime and SYCL. This means that the urinfo and sycl-ls tools can be used on top of Offload. A (rough) implementation of a Unified Runtime adapter (aka plugin) for Offload is available here. Our intention is to maintain this and use it to implement and test Offload API changes with SYCL.

Demoing the new API

# From the runtime build directory
$ ninja LibomptUnitTests
$ OFFLOAD_TRACE=1 ./offload/unittests/OffloadAPI/offload.unittests 

Open questions and future work

  • Only some of the available device info is exposed, and not all the possible device queries needed for SYCL are implemented by the plugins. A sensible next step would be to refactor and extend the existing device info queries in the plugins. The existing info queries are all strings, but the new API introduces the ability to return any arbitrary type.
  • It may be sensible at some point for the plugins to implement the new API directly, and the higher level code on top of it could be made generic, but this is more of a long-term possibility.

@callumfare
Copy link
Contributor Author

Hi @jhuber6, sorry for the spam from the various attempts to get this in. I was caught out by the lack of testing and was relying on my single local configuration for testing. I've now tested release and debug builds, the check-offload target (including the new offload-tblgen tests), the offload unit tests on all plugins (which aren't run by any check targets right now), header generation, and the install target.

If there's anything else that is likely to go wrong let me know, otherwise I'd appreciate another review and we can hopefully finally land this properly

Copy link
Contributor

@jhuber6 jhuber6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, OpenMP testing is notoriously bad

@frasercrmck frasercrmck merged commit 8da4903 into llvm:main Dec 3, 2024
7 checks passed
@jplehr
Copy link
Contributor

jplehr commented Dec 3, 2024

If you have a chance, can you check https://lab.llvm.org/staging/#/builders/131/builds/9701 ?
Two of our bots turned red with this landed. Unfortunately they are not in production (yet).

Edit: Link to other bot that turned red w/ this patch: https://lab.llvm.org/staging/#/builders/105/builds/10537

@jplehr
Copy link
Contributor

jplehr commented Dec 3, 2024

I think both build with LLVM_ENABLE_SHARED or whatever the CMake variable is called

9.370 [88/25/3417] Linking CXX executable /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/offload-tblgen
FAILED: /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/offload-tblgen 
: && /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/clang++ --target=x86_64-unknown-linux-gnu -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -Wl,--color-diagnostics    -Wl,--gc-sections offload/tools/offload-tblgen/CMakeFiles/offload-tblgen.dir/APIGen.cpp.o offload/tools/offload-tblgen/CMakeFiles/offload-tblgen.dir/EntryPointGen.cpp.o offload/tools/offload-tblgen/CMakeFiles/offload-tblgen.dir/FuncsGen.cpp.o offload/tools/offload-tblgen/CMakeFiles/offload-tblgen.dir/offload-tblgen.cpp.o offload/tools/offload-tblgen/CMakeFiles/offload-tblgen.dir/PrintGen.cpp.o -o /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/offload-tblgen  -Wl,-rpath,"\$ORIGIN/../lib:/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./lib:/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/lib"  /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/lib/libLLVMTableGen.so.20.0git  -Wl,-rpath-link,/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/lib && :
ld.lld: error: undefined symbol: llvm::raw_ostream::write(char const*, unsigned long)
>>> referenced by APIGen.cpp
>>>               offload/tools/offload-tblgen/CMakeFiles/offload-tblgen.dir/APIGen.cpp.o:(EmitOffloadAPI(llvm::RecordKeeper const&, llvm::raw_ostream&))
>>> referenced by APIGen.cpp
>>>               offload/tools/offload-tblgen/CMakeFiles/offload-tblgen.dir/APIGen.cpp.o:(EmitOffloadAPI(llvm::RecordKeeper const&, llvm::raw_ostream&))
>>> referenced by APIGen.cpp
>>>               offload/tools/offload-tblgen/CMakeFiles/offload-tblgen.dir/APIGen.cpp.o:(EmitOffloadAPI(llvm::RecordKeeper const&, llvm::raw_ostream&))
>>> referenced 123 more times

jplehr pushed a commit that referenced this pull request Dec 5, 2024
…I implementation (#118614)

Reland #118503. Added a fix for builds with `-DBUILD_SHARED_LIBS=ON`
(see last commit). Otherwise the changes are identical.

---


### New API

Previous discussions at the LLVM/Offload meeting have brought up the
need for a new API for exposing the functionality of the plugins. This
change introduces a very small subset of a new API, which is primarily
for testing the offload tooling and demonstrating how a new API can fit
into the existing code base without being too disruptive. Exact designs
for these entry points and future additions can be worked out over time.

The new API does however introduce the bare minimum functionality to
implement device discovery for Unified Runtime and SYCL. This means that
the `urinfo` and `sycl-ls` tools can be used on top of Offload. A
(rough) implementation of a Unified Runtime adapter (aka plugin) for
Offload is available
[here](https://github.com/callumfare/unified-runtime/tree/offload_adapter).
Our intention is to maintain this and use it to implement and test
Offload API changes with SYCL.

### Demoing the new API

```sh
# From the runtime build directory
$ ninja LibomptUnitTests
$ OFFLOAD_TRACE=1 ./offload/unittests/OffloadAPI/offload.unittests 
```


### Open questions and future work
* Only some of the available device info is exposed, and not all the
possible device queries needed for SYCL are implemented by the plugins.
A sensible next step would be to refactor and extend the existing device
info queries in the plugins. The existing info queries are all strings,
but the new API introduces the ability to return any arbitrary type.
* It may be sensible at some point for the plugins to implement the new
API directly, and the higher level code on top of it could be made
generic, but this is more of a long-term possibility.
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Dec 5, 2024
breaks build OMPT related?
ld.lld: error: undefined symbol: llvm::omp::target::ompt::enableDeviceTracing(int)
b877a533a6d1 (HEAD -> amd-staging) Revert "Reland llvm#118503: [Offload] Introduce offload-tblgen and initial new API implementation (llvm#118614)"

Change-Id: I1f4cb8e06ca625c2a539348d897e5436d314fc0a
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Dec 7, 2024
…w API implementation (llvm#118614)

Reland llvm#118503. Added a fix for builds with `-DBUILD_SHARED_LIBS=ON`
(see last commit). Otherwise the changes are identical.

Disables until OMPT adapts to this.

Previous discussions at the LLVM/Offload meeting have brought up the
need for a new API for exposing the functionality of the plugins. This
change introduces a very small subset of a new API, which is primarily
for testing the offload tooling and demonstrating how a new API can fit
into the existing code base without being too disruptive. Exact designs
for these entry points and future additions can be worked out over time.

The new API does however introduce the bare minimum functionality to
implement device discovery for Unified Runtime and SYCL. This means that
the `urinfo` and `sycl-ls` tools can be used on top of Offload. A
(rough) implementation of a Unified Runtime adapter (aka plugin) for
Offload is available
[here](https://github.com/callumfare/unified-runtime/tree/offload_adapter).
Our intention is to maintain this and use it to implement and test
Offload API changes with SYCL.

```sh
$ ninja LibomptUnitTests
$ OFFLOAD_TRACE=1 ./offload/unittests/OffloadAPI/offload.unittests
```

* Only some of the available device info is exposed, and not all the
possible device queries needed for SYCL are implemented by the plugins.
A sensible next step would be to refactor and extend the existing device
info queries in the plugins. The existing info queries are all strings,
but the new API introduces the ability to return any arbitrary type.
* It may be sensible at some point for the plugins to implement the new
API directly, and the higher level code on top of it could be made
generic, but this is more of a long-term possibility.

Change-Id: I355ac2cc4122d8023a88bc7f427174e16dfa76b9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants