618 Commits

Author SHA1 Message Date
Alex Duran
7ed0aa2652
[OFFLOAD][L0] Remove leftover global constructor (#182611) (#182665)
fixes #182611
2026-02-21 18:09:46 +01:00
Joseph Huber
70b5a1d050
[flang-rt] Add support for formatted I/O on the GPU (#182580)
Summary:
Expands on the previous support to enable formatted output, characters,
and checking basic iostat. We intentionally do not handle cases where
the descriptor is non-null as this is a non-trivial class that cannot
easily be shepherded across the wire.
2026-02-20 14:43:06 -06:00
Joseph Huber
5f5d27d7d3
[libc] Support array tags in the RPC dispatch helpers (#181395)
Summary:
This PR adds support for tagging a pointer as an array when marshaling
between the CPU and GPU.
2026-02-20 09:35:47 -06:00
Joseph Huber
21b3461440
[flang-rt] Implement basic support for I/O from OpenMP GPU Offloading (#181039)
Summary:
This PR provides the minimal support for Fortran I/O coming from a GPU
in OpenMP offloading. We use the same support the `libc` uses for its
printing through the RPC server. The helper functions `rpc::dispatch`
and `rpc::invoke` help make this mostly automatic.

Becaus Fortran I/O is not reentrant, the vast majority of complexity
comes from needing to stitch together calls from the GPU until they can
be executed all at once. This is needed not only because of the
limitations of recursive I/O, but without this the output would all be
interleaved because of the GPU's lock-step execution.

As such, the return values from the intermediate functions are
meaningless, all returning true. The final value is correct however. For
cookies we create a context pointer on the server to chain these
together.

Works on both my AMD and NVIDIA GPUs.
```fortran
program hello_gpu
  implicit none

  !$omp target teams num_teams(1)
  !$omp parallel num_threads(2)
    ! Print strings
    print *, "Hello from GPU"
  !$omp end parallel
  !$omp end target teams

end program hello_gpu
```
```console
> flang hello.f90 -O2 -fopenmp --offload-arch=gfx1030 
> ./a.out 
 Hello from GPU
 Hello from GPU
> flang hello.f90 -O2 -fopenmp --offload-arch=sm_89  
> ./a.out 
 Hello from GPU
 Hello from GPU
```
2026-02-20 07:56:59 -06:00
Nick Sarnie
78ff5b55fd
[offload][lit] Enable/disable tests on Level Zero when using DeviceRTL (#182128)
Since we can now build the DeviceRTL with SPIR-V, redo the
`XFAIL/UNSUPPORTED` specifications for the tests we see passing/failing
on the Level Zero backend with the DeviceRTL being used.

The tests marked `UNSUPPORTED` hang or sporadically fail and those are
tracked in https://github.com/llvm/llvm-project/issues/182119.

This change will allow us to enable CI testing with the DeviceRTL.

Here are the full test results with this change applied, running only
the `spirv64-intel` `check-offload` tests:

```
Total Discovered Tests: 453
  Unsupported      : 206 (45.47%)
  Passed           : 141 (31.13%)
  Expectedly Failed: 106 (23.40%)
```

31% is not a bad start.

---------

Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
2026-02-18 21:53:19 +00:00
Jan Patrick Lehr
e1e0e86e60
[Offload] Always check/consume Error (#182008)
This fixes an issue introduced in
https://github.com/llvm/llvm-project/pull/172226 where an llvm::Error is
not checked in the "good" code path.
2026-02-18 13:46:21 +01:00
Joseph Huber
6282a7b993 [Offload] Fix missing end to string in .td file 2026-02-17 15:32:17 -06:00
fineg74
1c6d774baa
[OFFLOAD] Extend olMemRegister API to handle cases when a memory block may have been mapped outside of liboffload. (#172226)
This PR adds extends liboffload olMemRegister API to handle a case when
a memory block may have been mapped before calling olMemRegister to
support some use cases in libomptarget
2026-02-17 20:53:00 +00:00
Joseph Huber
d62cd1b89d
[Offload] Add argument to 'olInit' for global configuration options (#181872)
Summary:
This PR adds a pointer argument to the initialization routine to be used
for global options. Right now this is used to allow the user to
constrain which backends they wish to use.

If a null argument is passed, the same behavior as before is observed.
This is epxected to be extensible by forcing the user to encode the size
of the struct. So, old executables will encode which fields they have
access to.

We use a macro helper to get this struct rather than a runtime call so
that the current state of the size is baked into the executable rather
than something looked up by the runtime. Otherwise it would just return
the size that the (potentially newer) runtime would see
2026-02-17 14:04:00 -06:00
Nick Sarnie
5317575dd5
Reapply x2 "[Offload][lit] Link against SPIR-V DeviceRTL if present" (#181429)
The change to `llvm-zorg` to start building the DeviceRTL for SPIR-V on
our builder finally got taken by the infra, so we can merge this now.

---------

Co-authored-by: Joseph Huber <huberjn@outlook.com>
2026-02-17 15:18:03 +00:00
Michael Kruse
0e1cc6138e
[Offload][test] Use just-compiled lld and llvm-symbolizer (#181793)
In a bootstrapping build with LLVM_ENABLE_PROJECTS=lld, the lld
executable will be found in LLVM's bin/ directory. But `check-offload`
will currently ignore it because the JIT plugin will look for `lld` in
`$PATH`. Similarly, the sanitizer tests require llvm-symbolizer during
execution to FileCheck the expected stack trace.

Add the llvm tools directory to `$PATH` so tests can use lld and
llvm-symbolizer in it. It should be prefered over a system-installed
lld/llvm-symbolizer.

Fixes the JIT and sanitizer tests of
[openmp-offload-amdgpu-clang-flang](https://lab.llvm.org/staging/#/builders/105).
2026-02-17 13:08:26 +00:00
Joseph Huber
d85576d368
[libc] Replace RPC 'close()' mechanism with RAII handler (#181690)
Summary:
Closing ports was previously done manually, This makes the protocol more
error prone as unclosed ports will leak and eventually the locks will
run out. I believe the original fear was that the RAII portion would
negatively impact code generation but I have not noticed anything
significant.
2026-02-16 15:14:30 -06:00
Alex Duran
e0182ebd40
[OFFLOAD] Fix issue where host plugin is added twice to the plugin list (#181346) 2026-02-13 12:08:04 +01:00
fineg74
b58a31d3ce
[OFFLOAD] Add support for host offloading device (#177307)
The purpose of this PR is to add support of host as an offloading device
to liboffload. Both OpenMP and sycl support offloading to a host as
their normal workflow and therefore would require such capability from
liboffload library.
2026-02-13 10:27:52 +01:00
Joseph Huber
846e61c0fb [libc] Small change to accept lambda types in rpc::dispatch
Summary:
This change allows lambdas to be used in the RPC dispatching functions.
Just requires an extra function trait to convert a lambda with no
captures into a function pointer. Also rearranged where the `Port` lives
because it looks better no that we may use  a lambda and it's more
consistent with the dispatch usage (putting the client at the start).
2026-02-12 09:18:56 -06:00
Hansang Bae
0deb1b6e05
[Offload] Try to load Level Zero loader with version suffix (#180042)
The default Level Zero loader `libze_loader.so` may not be available on
systems that don't have Level Zero development package. Level Zero
loaders with major version suffix are searched in that case.
2026-02-11 15:13:26 -06:00
Joseph Huber
6d6feb7655
[libc] Add RPC helpers for dispatching functions to the host (#179085)
Summary:
The RPC interface is useful for forwarding functions. This PR adds
helper functions for doing a completely bare forwarding of a function
from the client to the server. This is intended to facilitate
heterogenous libraries that implement host functions on the GPU (like
MPI or Fortran).
2026-02-11 08:13:52 -06:00
Alex Duran
8b9fd4803c
[OFFLOAD] Support host plugin on Windows (#180401)
Changes to make host plugin compile on Windows:
* Change IO code to be portable
* Adjust Makefiles

Allow plugin to work partially when libffi support is not found
dynamically (compilation works fine even on Windows because of the
wrapper support).
2026-02-11 08:54:47 +01:00
Nick Sarnie
6c0ff8d12f
Revert "Reapply [Offload][lit] Link against SPIR-V DeviceRTL if present" (#180743)
Reverts llvm/llvm-project#180231
2026-02-10 14:22:40 +00:00
Alex Duran
e17226e20b
[OFFLOAD] Implement excluding filters for debugging (#180538)
Allow a to define a set of Types that are not shown by default when
doing default debug loggin (e.g., LIBOMPTARGET_DEBUG=All).

Users can enable output of those types of messages by explicitly adding
them to LIBOMPTARGET_DEBUG.

Used to implement: #180545

---------

Co-authored-by: Michael Klemm <michael.klemm@amd.com>
2026-02-10 10:01:52 +01:00
Nick Sarnie
7fcc12c3be
Reapply [Offload][lit] Link against SPIR-V DeviceRTL if present (#180231)
I'll merge this at the same time as some llvm-zorg changes that start
building the DeviceRTL.

We only see one new test passing because everything still fails because
of the issue described in
https://github.com/llvm/llvm-project/pull/178980

Once a fix for that issue is merged we will see many new passes.
2026-02-09 16:52:33 +00:00
Robert Imschweiler
33e3384aa8
[offload] Adapt tests to new PluginInterface quoting [NFC] (#180505)
4096cb6017
removed the quotes around PluginInterface
2026-02-09 07:47:04 -06:00
Nick Sarnie
6844af142e
Revert "[Offload][lit] Link against SPIR-V DeviceRTL if present" (#180211)
Reverts https://github.com/llvm/llvm-project/pull/180030

Need to make changes to buildbot first
2026-02-06 15:05:16 +00:00
Joseph Huber
2f00977fea
[Offload] Make the RPC callbacks private to each running server (#178901)
Summary:
The static object mixes callbacks from different plugins because ever
since we moved to the object library target these are actually shared.
Just make it a member of the base class and make it a pointer set just
to do some basic deduplication.
2026-02-06 08:28:57 -06:00
Alex Duran
4096cb6017
[OFFLOAD] Fix TARGET_NAME in plugins common code (#180151)
Unlike other names is set between quotes which prevents our debug macros
to properly match it.
2026-02-06 14:12:04 +01:00
Nick Sarnie
b985974e75
[Offload][lit] Link against SPIR-V DeviceRTL if present (#180030)
Right now if we run `check-offload` for SPIR-V the DeviceRTL isn't used
because we pass `-nogpulib`.

Don't pass that, but also don't pass `--libomptarget-spirv-bc-path` yet
because the DeviceRTL is brand new so we don't want to error if it's not
present.

Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
2026-02-05 22:11:50 +00:00
Yury Plyakhin
ecd1767edb
[offload] Fix DeviceImage to handle OffloadBinary::create returning vector (#180003)
OffloadBinary::create() now returns
`Expected<SmallVector<unique_ptr<OffloadBinary>>>`
instead of a single unique_ptr, to support multiple entries in version 2
format.

Updated DeviceImageTy constructor to extract the first binary from the
returned
vector, with empty check. In this context, only one image per
OffloadBinary is expected.
2026-02-05 12:41:03 -06:00
Joseph Huber
39b328c6f7
[OpenMP] Enable XFAIL OpenMP tests that pass now (#179344)
Summary:
These have been fixed, should be updated
2026-02-03 07:32:24 -06:00
Joseph Huber
c23c6b1940
[Offload] Only issue a warning for building offload on the GPU and return (#179240)
Summary:
Right now this will fail because the GPU architectures will attempt to
build all of `offload` with the GPU, which obviously won't work. In the
future we will proably have some utility library that we will route
through this, but for now just silently return. This is useful because
the documentation states to use this, but it doesn't work right now.
```
-DLLVM_ENABLE_RUNTIMES=offload;openmp
-DLLVM_RUNTIME_TARGETS=default;amdgcn-amd-amdhsa
```

This PR makes this work.
2026-02-02 09:37:57 -06:00
Joseph Huber
1a86c146ae
[Offload] Add a function to register an RPC Server callback (#178774)
Summary:
We provide an RPC server to manage calls initiated by the device to run
on the host. This is very useful for the built-in handling we have,
however there are cases where we would want to extend this
functionality.

Cases like Fortran or MPI would be useful, but we cannot put references
to these in the core offloading runtime. This way, we can provide this
as a library interface that registers custom handlers for whatever code
people want.
2026-01-30 08:03:13 -06:00
Joseph Huber
830236204e
[Offload] Provide a cache file for building OpenMP w/ Flang offloading (#178472)
Summary:
This build is more annoying, enables everything required for this
version of the runtime.
2026-01-29 12:35:42 -06:00
Akash Banerjee
7c07cb6542
[MLIR][OpenMP] Fix recursive mapper emission. (#178453)
Recursive types can cause re-entrant mapper emission. The mapper
function is created by OpenMPIRBuilder before the callbacks run, so it
may already exist in the LLVM module even though it is not yet
registered in the ModuleTranslation mapping table. Reuse and register it
to break the recursion. Added offloading test.
2026-01-29 16:38:33 +00:00
puneeth_aditya_5656
ed4aab07ec
[Offload][AMDGPU] Fix olQueryQueue uninitialized output parameter (#178464)
## Summary
- Fix uninitialized output parameter in `olQueryQueue_impl` when
`Queue->AsyncInfo->Queue` is null
- Set `IsQueueWorkCompleted` to `true` when no underlying queue exists
(no pending work)
- Resolves test failure on AMDGPU for
`olQueryQueueTest.SuccessEmptyAsyncQueueCheckResult`

Fixes #178462.

## Test plan
- [x] Fixed
`OffloadAPI/queue.unittests/olQueryQueueTest/SuccessEmptyAsyncQueueCheckResult/AMDGPU_AMD_Radeon_RX_7700_XT_0`
test
- [ ] CI tests pass

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Joseph Huber <huberjn@outlook.com>
2026-01-28 20:49:19 -06:00
Akash Banerjee
c856c3d045
[MLIR][OpenMP] Fix mapper being attached to partial maps. (#178247)
Fix OpenMP mapper lowering by attaching user-defined/default mappers
only to the base parent entry, not combined/segment entries. This
prevents mapper calls with partial sizes. Added relevant tests.
2026-01-28 18:35:03 +00:00
Sladyn
3ddddf7a49
Use reportFatalUsageError in llvm-omp-kernel-replay (#178371)
All error cases in this tool are usage errors (bad user input, missing
files, malformed JSON) rather than internal LLVM bugs, so
`reportFatalUsageError` is the appropriate replacement.
2026-01-28 09:12:03 +00:00
Abhinav Gaba
339f779570
Reland "[OpenMP][Mappers] Fix ref-count tracking for maps inserted by mappers. (#177059)" (#177673)
This reverts commit 5a457837dd988aa01c65820848381a5b99a74c0a.

Includes the test fix from
https://github.com/llvm/llvm-project/pull/177659.

The test had to be updated to exclude a scenario that was failing
with/without the change (involving mapping a struct with a byref member
with a mapper).

-----
**Original PR's description:**

This is a fix for https://github.com/llvm/llvm-project/issues/61636.

Ravi had this implemented downstream before he retired. This PR is a
chery-pick of that.

The test is taken from @jdoerfert's WIP change in

527bf4b129.

The change partially undoes the changes done in
0caf736d7e1d16d1059553fc28dbac31f0b9f788, so @alexey-bataev might need
to take a look.
2026-01-27 15:31:16 -08:00
Hansang Bae
4aaf7ed74b
[Offload] Allow specifying debug level with all debug type (#178213)
This change allows users to specify debug level with `all` debug type.
The effect of `all:<num>` is equivalent to `<num>`.
2026-01-27 16:02:14 -06:00
Akash Banerjee
21b0fdf8ec
[Flan][OpenMP] Implement TODO support for compatible defaultmap types for implicit mappers (#177389)
Make implicit default mapper generation respect defaultmap categories so
unrelated defaultmap clauses no longer suppress mappers for derived
types.
Added related tests.
2026-01-27 14:45:40 +00:00
Abhinav Gaba
c366348ed9
[Clang][OpenMP] Codegen for use_device_ptr(fb_nullify). (4/4) (#173931)
Depends on #173930.

The `FB_NULLIFY` map-type bit is set in addition to `RETURN_PARAM`, for
`use_device_ptr(fb_nullify:p)`.
2026-01-23 12:36:54 -08:00
Abhinav Gaba
5a457837dd
Revert "[OpenMP][Mappers] Fix ref-count tracking for maps inserted by mappers. (#177059)" (#177623)
Reverts llvm/llvm-project#177059 and llvm/llvm-project#177491.

The new test may have an issue.
2026-01-23 12:02:44 -08:00
Abhinav Gaba
7d5622f791
[NFC][OpenMP] Mark new mapper test as XFAIL on intelgpu. (#177491)
Other tests in the directory already do this. The new test was added in
#177059.
2026-01-22 15:33:40 -08:00
Abhinav Gaba
a7b57cf7bb
[OpenMP][Mappers] Fix ref-count tracking for maps inserted by mappers. (#177059)
This is a fix for https://github.com/llvm/llvm-project/issues/61636.

Ravi had this implemented downstream before he retired. This PR is a
chery-pick of that.

The test is taken from @jdoerfert's WIP change in

527bf4b129.

The change partially undoes the changes done in
0caf736d7e1d16d1059553fc28dbac31f0b9f788, so @alexey-bataev might need
to take a look.

---------

Co-authored-by: Ravi Narayanaswamy <ravi.narayanaswamy@intel.com>
Co-authored-by: Johannes Doerfert <johannes@jdoerfert.de>
2026-01-22 15:10:00 -08:00
Alex Duran
ba3548c8b2
[OpenMP][Offload] Remove old DP macro (#177156)
Old usages have been updated so we can remove it now
2026-01-21 15:13:13 +01:00
Abid Qadeer
7a74e7fba3
[flang][OpenMP] Fix mapping of constant arrays. (#176763)
The compiler skips mapping of named constants (parameters) to OpenMP
target regions under the assumption that constants don't need to be
mapped. This assumption is not valid when array is accessed inside with
dynamic index. The problem can be seen with the following code:

```
module fir_lowering_check
  implicit none

    integer, parameter :: dp = selected_real_kind(15, 307)
    real(dp), parameter :: arrays(2) = (/ 0.0, 0.0 /)

contains

subroutine test(hold)

        integer, intent(in) :: hold
        integer :: z
        real(dp) :: temp

        !$omp target teams distribute parallel do
            do z = 1, 2
                  temp = arrays(hold)
            end do
        !$omp end target teams distribute parallel do

    end subroutine test
end module fir_lowering_check

program main
  use fir_lowering_check

  implicit none
    integer :: hold
    hold = 1
    call test(hold)
    print *, "Finished"

end program main
```

It fails with the following error
`'hlfir.designate' op using value defined outside the region`

The fix is to allow mapping of constant arrays and map them as `to`.
2026-01-21 13:40:01 +00:00
Abhinav Gaba
aeed73728e
[NFC][OpenMP][Offload] Add tests for use_device_ptr(fb_preserve/nullify). (3/4) (#173930)
Depends on #170578.

The fallback modifiers are currently part of OpenMP 6.1. 4/8 of the
tests check for the current bad output, with FIXME comments.

3 of these "bad" tests will be fixed with the 4th PR in this stack with
the `fb_nullify` codegen changes.

4th bad test will need a follow-up fix to privatization of byref
`use_device_ptr` operands.

Dependent PR: #173931.
2026-01-20 16:23:47 -08:00
Hansang Bae
85d64d1201
[Offload] Cast to void * in the debug message (#177019)
There are a few places where data types based on character array or
string are printed in the debug message while they do not represent
strings. Such expressions should be casted to `void *` unless they
represent actual strings. Change also includes casting from integral
type to pointer type when appropriate.
2026-01-20 15:44:08 -06:00
fineg74
51e2c82023
[OFFLOAD] Add a check before calling dataExchange (#176853)
Per documentation the call to dataExchange API (move memory block
between different devices) is permitted only if isDataExchangable() call
returned true. While almost all platforms support memory transfer
between different devices, in the case when the transfer is attempted
between devices belonging to different platforms if they are present on
the same machine which can lead to unexpected results. This PR adds a
check if dataExchange can be called and if not uses a workaround by
initiating memory transfer through host.
2026-01-20 11:37:35 -08:00
fineg74
848d736e64
[OFFLOAD] Add asynchronous queue query API for libomptarget migration (#172231)
Add liboffload asynchronous queue query API for libomptarget migration

This PR adds liboffload asynchronous queue query API that needed to make
libomptarget to use liboffload
2026-01-20 10:53:32 -08:00
Nick Sarnie
75cc3cd1e8
[offload][lit] XFAIL failing non-contiguous update tests on Intel (#176955)
The new tests added in https://github.com/llvm/llvm-project/pull/169623
are [failing](https://lab.llvm.org/buildbot/#/builders/225/builds/544)
on the Intel GPU runner, so XFAIL them as with the other tests.

Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2026-01-20 16:39:25 +00:00
Amit Tiwari
ae1ee0d377
[Offload][Tests] Non-contiguous_update_to_tests (#169623)
PR #144635 enabled non-contiguous updates for both `update from` and
`update to` clauses, but tests for `update to` were missing. This PR
adds those missing tests to ensure coverage.
2026-01-20 12:03:39 +05:30