311 Commits
Author SHA1 Message Date
Jan Patrick Lehr 380c581b72 [Offload] Fix warn-unused function (#208642)
Unblock the `-Werror` build in pre-merge by adding a few
[[maybe_unused]] here and there.
2026-07-10 10:14:13 +02:00
Łukasz Plewa dd824164c8 [offload] Add olMemPrefetch to liboffload (#206752)
Adds olMemPrefetch and the OL_MEM_MIGRATION_FLAG_* enum, wired through a
new dataPrefetchImpl on the plugin interface with Level Zero and CUDA
implementations. Backends without prefetch support inherit the default
no-op.

Prefetch is a hint that migrates a USM allocation between the host and a
device so subsequent accesses on the target side are faster.

Assisted-by: Claude
2026-07-09 18:08:54 +02:00
Matt Arsenault d776ee4d4c offload: Use amdgpu triple name in plugin build (#208455)
The PGO tests expect the produced filename to match the triple.
The tool pulls the triple name from the binary's triple name, and the
RUN lines expect it to match the triple the build was configured with.
2026-07-09 17:34:20 +02:00
Matt Arsenault 24a5231188 AMDGPU: Introduce amdgpu triple arch (#206480)
Move towards using the triple for representing incompatible
ISA changes. Use the subarch field to represent the various
incompatible cases. Previously we pretended a single triple arch
was universally compatible, and only distinguished by function
level subtargets. Move towards using distinct triples to enable
more sophisticated toolchain handling in the future, like proper
runtime library linking.

Introduce a new subarch per unique ISA, but also introduce
"major subarches" which are compatible by a set of covered
minor ISA versions. These map to the existing generic targets.
There are a few placeholder subarch entries, which currently
have missing backing generic arches for codegen.

This should be the preferred triple arch name going forward,
but is treated as an alias of amdgcn. This does not yet change
clang to emit the new triples.

Part of #154925
2026-07-09 13:43:41 +02:00
Giorgi GvaliaandGiorgi Gvalia 16b8129cd7 [offload] Add the ability to record and replay IR bitcode modules (#207278)
This PR allows the user to use JIT with kernel record & replay by
expanding the latter to also work with IR bitcode images.

- Add a new field to `DeviceImageTy` for storing the IR image.
- Expand `RecordReplayTy::FileTy` to also include IR bitcode and
associate it with the file extension `.bc`
- Add the `--load-bitcode` command line option to
`llvm-omp-kernel-replay` tool.

---------

Co-authored-by: Giorgi Gvalia <gvalia1@llnl.gov>
2026-07-08 09:53:13 -07:00
Wenju He 3ce39bb78b [offload] Fix duplicate __llvm_write_custom_profile on Windows PGO builds (#207366)
MSVC/clang-cl lack __attribute__((weak)), so GlobalHandler.cpp provided
a strong stub for __llvm_write_custom_profile. When clang_rt.profile is
linked (e.g. instrumented/PGO builds) lld-link rejects the duplicate
strong symbol.

Replace the stub + CMake workaround with the /alternatename linker
pragma, which is the standard Windows weak-symbol equivalent used by
compiler-rt itself. The linker picks compiler-rt's strong definition
when present.

Fix the guard: use _WIN32 && !__MINGW32__ (not _MSC_VER) so the stub and
/alternatename pragma apply to plain clang-on-Windows too, while MinGW
(which supports __attribute__((weak)) natively) continues to use the
real weak declaration.

Also fix the stub signature from 8 to 10 parameters to match the header.

Assisted-by: Claude
2026-07-06 18:42:41 +08:00
Markus Böck 6ae9fe5e28 [cmake][NFC] Use EXTRA_INCLUDES in tablegen commands (#207514)
Not only is it more declarative than using the `-I` directory, it
additionally adds the given directory to the
`tablegen_compile_commands.yml` which allows the LSP and IDE tooling to
also be aware of the extra include directories used to compile that
TableGen file
2026-07-04 14:29:57 +00:00
Wenju He 5302608fec [Offload] Guard __llvm_write_custom_profile null check on non-Windows (#207170)
On Windows __llvm_write_custom_profile is defined as a strong stub (MSVC
lacks proper weak symbol support) by 09a51b2818, so its address is a
compile-time constant that is never null. The `if
(!__llvm_write_custom_profile)` check therefore triggers
-Wpointer-bool-conversion, which is fatal under -Werror.

Assisted-by: Claude
2026-07-03 07:00:31 +08:00
Yaxun (Sam) Liu ab95a8e7bb [PGO][AMDGPU] Add uniformity-aware offload profile format and instrumentation (#190708)
Add the producer-side format and instrumentation pieces that layer on
top
of the basic HIP offload PGO support.

This extends the raw/indexed profile format with wave size and uniform
counters, teaches llvm-profdata to read and merge them, adds the AMDGPU
sampling runtime, and emits block.uniformity.profile metadata during
PGO instrumentation.
2026-06-29 08:30:45 -07:00
Mirko BrkušaninandClaude noreply@anthropic.com 1636530528 [AMDGPU] Add more generic targets (#205363)
gfx11-7-generic = 0x062
gfx13-generic = 0x063

Co-Authored-By: Claude noreply@anthropic.com
2026-06-29 14:07:32 +02:00
Joseph Huber 5e68849740 [Offload][AMDGPU] Flush RPC server on abnormal queue exit (#206150)
Summary:
In the case of, say, a GPU sanitizer, there could be a pending report
that isn't flushed before the queue dies and the program terminates. Add
an explicit flush to ensure that all work at least posted *before* the
trap fired is cleared in the HSA error callback before actually
quitting.
2026-06-26 13:54:28 -05:00
Joseph Huber 1774a65964 [Offload] Unify the kernel argument passing (#205224)
Summary:
Currently we have two conflicting methods of passing kernel arguments, a
flat pointer + size and an array of pointers. We recently decided to
move the offload API to the latter because it is more generic and lets
you construct the other formats.

This PR primarily just changes the format and the one existing core use.
The uses should be simplier now. Future changes will change the OpenMP
argument parsing.
2026-06-25 15:51:30 -05:00
Piotr Balcer 07d30c1fc9 [OpenMP][Offload] Use argument pointer array in host kernels (#205355)
This is a follow-up to #194333, which changed liboffload's kernel launch
interface to take an array of pointers to arguments instead of a
contiguous argument buffer, but left the old path intact for OpenMP, to
be cleaned up iteratively in later changes.

This patch modifies the offload host kernels, and the OpenMP clang
codegen, to also use argument pointer arrays. The host was the only
plugin that did not support the new submission path. With it converted,
OpenMP can migrate to use the new path in all scenarios, after which
everything related to contiguous argument buffer and its construction
can be removed from plugin interface and the backends.

The change itself is fairly straightforward. The bulk of the diff is
automated test updates. In the runtime, the host kernel signature
becomes an array of pointers (void **), and the codegen is updated to
match. With each argument being a pointer, the kernel function now adds
one load to read the argument's value.

Assisted-by: Claude
2026-06-24 23:15:46 +02:00
EuphoricThinking f4a8eb0a6e [offload] add support for aligned allocations (#203353)
This patch is the first step towards introducing alignment support in
memory allocations using liboffload, in order to enable SYCL
implementation of aligned allocations.

At the level of device allocators, it does not modify the Level Zero
code except for forwarding the alignment parameter, since Level Zero
already allows for specifying the alignment in its device allocator
implementation. For AMD and CUDA, it checks whether the alignment passed
by the caller is supported by the given backend; the reasoning behind
this verification is described in the following paragraphs. At the API
level, it adds a new function olMemAllocAligned, which is expected to
work similarly to olMemAlloc, with the difference that the buffers
returned by olMemAllocAligned should be aligned to the alignment passed
by the user. At the level of the plugin interface internal abstractions,
it adds a new argument Alignment to existing functions and delegates
memory allocation between olMemAllocAligned and olMemAlloc
implementations by using a common helper function.

The goal of the anticipated series of patches is to implement handling
of the alignment in the memory manager at the plugin interface level. At
the first stage, presented in this patch, the information about the
passed alignment is used mainly for checking whether the buffer returned
by the device allocators meets the requirements. In the case of the
requested memory size exceeding the thresholds of allocations handled by
the memory manager, the request is forwarded directly to the device.
Otherwise, the memory manager is responsible for allocating memory in
full pages and pooling it according to the requested chunks. In the
first scenario, the requested size, which is greater than the
aforementioned threshold, is usually a multiple of the page size.
Therefore, any alignment smaller than the page size would be correct.

Neither CUDA nor HSA provides users with the ability to specify the
alignment of the allocated memory. Their APIs include the alignment as
one of the possible arguments only in functions that reserve virtual
address space. CUDA enables users only to check the allocation
granularity, which is usually synonymous with the page size. In the case
of HSA, if the memory is allocated using a pool, the user is able to
check not only the granularity, but also the alignment of the buffers
allocated using the given pool. However, these values - granularity and
alignment - are defined only if
HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED is set to true, which
should always be set since the current implementation of the memory pool
for the AMD plugin in liboffload uses only hsa_amd_memory_pool_ts for
allocations. Only Level Zero accepts the alignment parameter during the
memory allocation process, but manages returned pointers internally.
Since pooling is also implemented in the memory manager at the plugin
level, such a design in the Level Zero device allocator duplicates
pooling in the whole application.

In the final version, the memory manager at the plugin interface level
will handle memory pooling and the buffer alignment from different
devices instead of delegating memory management to device allocator
implementations, as this would simplify the Level Zero plugin design and
provide AMD and CUDA plugins with support for the alignment in memory
allocations, which is not natively included in their APIs.
2026-06-24 19:19:33 +02:00
Joseph Huber 6a15e2d756 [Offload] Fix ordering with RPC teardown and global destructors (#205594)
Summary:
There's a bit of a chicken and egg problem for the RPC server if we want
to do something creative with the device's image for things like DWARF
dumping. The problem was that destructors can make RPC calls, but the
RPC server also needed the images to be valid. Simple fix is to just
split the destructor calling out and do it first so we can deinitialize
RPC with valid device images.
2026-06-24 11:43:40 -05:00
Robert Imschweiler 132e019c1f Reapply "[OpenMP][offload] Cross-team reductions with variable number of teams" (#204914) (#205071)
Together with the fix for
https://github.com/llvm/llvm-project/pull/195102#issuecomment-4756584289
2026-06-22 17:40:45 +02:00
Robert Imschweiler 4c16440e1e Revert "[OpenMP][offload] Cross-team reductions with variable number of teams" (#204914)
Reverts llvm/llvm-project#195102 due to some missed debug info issue
revealed by https://lab.llvm.org/buildbot/#/builders/67/builds/7022
2026-06-20 06:28:22 +00:00
Robert Imschweiler e9acb01904 [OpenMP][offload] Cross-team reductions with variable number of teams (#195102)
This is a part of a series of patches that rework OpenMP cross-team
reductions.

This patch changes the cross-team reduction runtime to no longer work
through larger number of teams in chunks. Instead, we allocate a
suitable-sized global buffer for the team values and let all teams run
at once. The last team that finishes uses a strided loop to reduce the
team values from the global buffer.

We also use `mapping::getNumberOfThreadsInBlock()` instead of
`omp_get_num_threads()` because the reduction of the team values runs
outside of the parallel region device code, which would make
`omp_get_num_threads()` always return 1. For Generic-SPMD mode, we also
want to use all available threads, which means that we need to copy the
reduction data from LDS (where it lives in that mode by default) to
scratch in codegen before calling the cross-team reduction.

Performance:
All performance tests can be reproduced with
https://github.com/ro-i/xteam-test @ commit
2f09ae1f566f13189d20b414d8b83bf2986564d2. To reproduce, simply create a
`local.mk` file in the cloned directory with a suitable `OFFLOAD_ARCH`
for your machine and `CXX_trunk` + `CXX_trunk_dev` set to the paths of
the clang++ binaries for llvm/main and this patch. (llvm/main should
best be at the commit that is currently the base for this PR. At the
moment, this is fe87c971bf). Then, run
`make trunk trunk_dev` to build the benchmark binaries for 208 and 10400
teams. Run them with `./run_bench.sh -rq -n10 red_trunk_208
red_trunk_dev_208 red_trunk_10400 red_trunk_dev_10400` to get the avg
performance numbers over 10 rounds.
This tests multiple reduction workloads, including reductions that run
in the Generic-SPMD mode, with 208 teams and with 10400 teams, both à
512 threads, and with a reduction array size of 177,777,777. I tested on
a gfx942 and didn't find any regressions - here are some numbers showing
the performance of this patch relative to the baseline:
```
red_comb_sep_arr_32    double   dev_208:   +84.37%   dev_10400:   +54.06%
red_sum_arr_32         double   dev_208:    +9.72%   dev_10400:   +51.29%
red_comb               double   dev_208:    +2.73%   dev_10400:    +8.73%
red_comb_sep           double   dev_208:    +1.89%   dev_10400:   +87.13%
red_dot                double   dev_208:    +1.46%   dev_10400:   +25.66%
red_indirect           double   dev_208:    +1.51%   dev_10400:   +23.54%
red_kernel_part        double   dev_208:    +1.27%   dev_10400:   +88.28%
red_max                double   dev_208:    +1.29%   dev_10400:   +22.69%
red_mult               double   dev_208:    +1.96%   dev_10400:   +22.02%
red_sum                double   dev_208:    +2.03%   dev_10400:   +22.00%
red_pi                 double   dev_208:    +1.08%   dev_10400:    +1.22%
red_comb_sep_arr_32    uint     dev_208:  +139.10%   dev_10400:   +88.02%
red_sum_arr_32         uint     dev_208:   +49.70%   dev_10400:  +143.24%
red_dot                uint     dev_208:    +0.77%   dev_10400:   +24.91%
red_max                uint     dev_208:    +3.43%   dev_10400:   +36.61%
red_sum                uint     dev_208:    +4.56%   dev_10400:   +36.95%
red_comb_sep_arr_32    ulong    dev_208:   +85.22%   dev_10400:   +58.17%
red_sum_arr_32         ulong    dev_208:    +9.01%   dev_10400:   +55.14%
red_dot                ulong    dev_208:    +2.94%   dev_10400:   +26.89%
red_max                ulong    dev_208:    +2.83%   dev_10400:   +23.10%
red_sum                ulong    dev_208:    +1.59%   dev_10400:   +22.82%
red_comb_sep_arr_32    Value    dev_208:   +29.88%   dev_10400:   +24.17%
red_sum_arr_32         Value    dev_208:    +7.26%   dev_10400:   +38.14%
red_dot                Value    dev_208:    +2.65%   dev_10400:    +8.60%
red_max                Value    dev_208:    +2.86%   dev_10400:    +4.77%
red_sum                Value    dev_208:    +0.47%   dev_10400:   +10.22%
```

This patch uses ideas from Johannes Doerfert, ideas from the AOMP
cross-team reduction implementation, and was assisted by Claude.
2026-06-20 07:12:30 +02:00
Kevin Sala Penades e6a92e0d2d [offload] Fix teams/threads limits in record replay (#200639)
The recording phase now sets the teams and threads limits provided by
the user (in the corresponding OpenMP clauses) or zero if not specified.
Additionally, the PR #199483 already enforces that replay's configuration
of threads and teams are respected.

This commit also changes the way we test record and replay when multiple
kernels are recorded in the same test. We use the record report to know how
to associate a json record descriptor file to the target region in the code. We
do not rely anymore on the modification time of the files to know the order,
which was problematic.
2026-06-19 12:02:11 -07:00
Kevin Sala Penades b65d5100d7 [offload][OpenMP] Fix record replay when no memory is used (#201771)
Progams that do not use any memory (e.g., no mappings) were failing
because we were trying to execute zero size transfers. This commit adds
handling for this case.
2026-06-18 23:43:38 -07:00
Kevin Sala Penades 79349e509a [offload] Improve report printing for kernel recording (#204505)
This commit extends the record reporting mechanism:
- `LIBOMPTARGET_RECORD_REPORT_FILENAME` enables the reporting mechanism
and allows specifying the name of the output file.
- The report of recorded kernels are ordered in recording order. This is
really useful for tests that need to record and replay more than one
kernel.
2026-06-18 21:57:23 -07:00
Joseph Huber 304c5a6587 [Offload] Flush pending RPC ports when tearing down a device (#204681)
The RPC client can push asynchronous work and then quit. These can be
lost if the kernel returns and is torn down before the RPC server gets
to run to check it. To handle this, we just manually flush the interface
once when we tear the device down. The interface is lock-free so this
should be safe even if the other thread is working through it as well.
2026-06-18 18:30:13 -05:00
Łukasz Plewa 0f4d8cefbf [offload][l0] Implement olLaunchHost function for level zero plugin (#204173)
Adds support to enqueue host tasks in Inorder queues for the L0 plugin.
2026-06-18 21:59:31 +02:00
Joseph Huber 96127e6a8c [Offload] Fix pessimistic max block count sizing on AMDGPU (#204242)
Summary:
For whatever reason, HSA copied the questionable choices that OpenCL
made and represents its launch parameters in a threads * blocks grid.
The problem is that you then combine this with an `int32_t` interface,
so you have 31 bits to represent your launch. We were then
pessimistically stating that your launch always had 1024 threads, which
left us with 2^21. This is only about two million which people do all
the time, and this caused us to perform weird clamping in OpenMP. The
effect was that tests like ompx_saxpy_mixed.c was hitting that clamp and
returning wrong results.

Also fix the sanitizer tests failing because of HSA core dumps.
2026-06-17 11:10:33 -05:00
Weronika Lewandowska 09a51b2818 [offload] Add Windows offload support (#187006) 2026-06-17 10:07:08 +02:00
Alex Duran 8af74a033b [OFFLOAD][L0] Switch to use inorder queues by default (#203897)
Now that other pieces are in place we can switch to using Level Zero
inorder queues by default.
2026-06-15 17:48:30 +02:00
Weronika Lewandowska 91139b1585 [Offload] define MSVC byte-order macros for rtl endianness checks (#202540)
Define MSVC byte-order macros for rtl endianness checks
Ref: https://github.com/llvm/llvm-project/pull/199901
2026-06-15 07:28:35 -05:00
Alex Duran 3b67307500 [OFFLOAD][L0] Use counter-based events for inorder queues (#202301)
Inorder queues can use counter-based events which have better
performance and provide early-reused semantics.

Assisted by Claude.
2026-06-11 19:33:16 +02:00
Alex Duran 2af4354a57 [OFFLOAD][L0] Add control for Copy Offload Hint (#203203)
In some cases setting ZE_COMMAND_QUEUE_FLAG_COPY_OFFLOAD_HINT reduces
performance. Here we introduce
LIBOFFLOAD_LEVEL_ZERO_USE_COPY_OFFLOAD_HINT env var to allow users to
control the hint (which continues to be on by default).
2026-06-11 18:24:31 +02:00
Alex Duran 0e9ff9805d [OFFLOAD][L0] Add wait events for AsyncQueue memFill (#202287)
Fix an issue where memFill operations were not chained properly with respect prior operations.
2026-06-09 10:36:59 +00:00
Alex DuranandKevin Sala Penades 7b4d5d0981 [OFFLOAD][L0] Implement Event APIs (#201306)
Introduce a new L0EventTy type used to implement most of the Event APIs
of PluginInterface (all but getEventElapsedTimeImpl).

---------

Co-authored-by: Kevin Sala Penades <kevinsala.ks@gmail.com>
2026-06-04 21:42:38 +02:00
Alex Duran b76fb96a86 [OFFLOAD][L0] Return symbol size in getGlobalMetadataFromDevice (#201352)
Return not just the address but also the size of the symbols in getGlobalMetadataFromDevice.
Fixes olGetSymbolInfoSizeGlobalTest.SuccessSize unitt test failure with L0 plugin.
2026-06-03 21:29:15 +02:00
Alex Duran f834b7f55f [OFFLOAD][L0] Move dataFence logic to L0Queue (#201046)
The dataFence device operation logic was still on L0Device. With this all the operations working on command lists have their logic consolidated in L0Queue.
2026-06-02 15:13:34 +00:00
Alex Duran 8c65695c54 [OFFLOAD][L0][NFC] Add struct for deferred memory operations (#200928)
Improve readibility a bit by using a well-defined struct instead of
tuples.
2026-06-01 22:59:47 +02:00
Alex Duran 43ce763ada [OFFLOAD][L0][NFC] Rename AsyncQueueTy struct to L0QueueTy (#200921)
L0QueueTy is more descriptive after the changes in #200650.

Also renamed the header name and one internal field to be more
descriptive.
2026-06-01 20:16:47 +00:00
Alex Duran a4f3a0153b [OFFLOAD][L0][NFC] Remove Device TLS table (#200923)
After #200650 the Device TLS table is not used anymore so it can be
removed.
2026-06-01 22:13:03 +02:00
Alex Duran 8c30cb246c [OFFLOAD][L0] Add support for dynamic l0 fallbacks (#200517)
The PR adds support to define fallbacks for DLWRAP routines that are not
found when loading the library.
It implements a fallback for
zeCommandListAppendLaunchKernelWithArguments introduced in #194333 which
might not be available in older drivers.
2026-06-01 21:24:54 +02:00
Alex Duran 4ae3323996 [OFFLOAD][L0] Refactor AsyncQueues (#200650)
This PR introduces a major refactor on how L0 queues are used in the
plugin as the current design is too tied to OpenMP behavior. There are
two major changes:

* We no longer have a per-thread queue cache as this resulted in a
single logical queue backed up by multiple L0 queues. We now have a per
device cache which should have a similar level of reuse performance.
* The AsyncQueueTy type has been largely extended to hide the logic of
the different queues types (which are now subclasses of AsyncQueueTy).
This has greatly simplified the L0Device implementation.

As part of this refactor a number of other changes happened:

* Copy command lists were removed in favor of the
ZE_COMMAND_QUEUE_FLAG_COPY_OFFLOAD_HINT driver hint.
* Support for inorder queues was added (can be selected using
LIBOMPTARGET_LEVEL_ZERO_COMMAND_MODE=inorder).
* Sync queues now use inorder queues.
* Queue operations conditionally only use events when necessary (OMPT,
profiling or queue logic).
* MemFill now support asynchronous operations

There are a few more things that still need to be adjusted and cleanup
but as this PR is already big enough as it is, I'll prepare a follow-up
to fix them.
2026-06-01 20:58:03 +02:00
Kevin Sala Penades f15904ec71 [offload][OpenMP] Add strict flag for blocks and threads in kernel arguments (#199483)
Until now, strict behavior in the number of threads and blocks has been
applied only when the kernel is in bare mode. When this mode is enabled,
the values passed in UserNumBlocks and UserThreadLimit are not adjusted
and are the definitive values used to launch the kernel. This commit
detaches the strictness from the kernel mode.

This is going to be used by the kernel replay tool. Additionally, it
starts clearing the path for the upcoming OpenMP dims modifier, used to
configure multidimensional teams and leagues, which will include
strictness choices for teams and threads.

All the bare kernels must indicate strict behavior. Asserts are added to
check this condition.
2026-05-30 02:28:35 -07:00
Piotr Balcer a10ca8ed64 [offload] use argument pointer array in olLaunchKernel (#194333)
This PR changes olLaunchKernel to accept an array of pointers to
arguments:
```
  void *ArgPtrs[] = {&A, &B, &C};
  size_t ArgSizes[] = {sizeof(A), sizeof(B), sizeof(C)};

  olLaunchKernel(Queue, Device, Kernel, &LaunchArgs, std::size(ArgPtrs), ArgPtrs, ArgSizes);
```

The newly proposed interface is implementable by existing and
anticipated
backends, is familiar to CUDA programmers, eliminates the extraneous
construction of a contiguous arguments buffer, replacing it with
constructing
an array of pointers, sidesteps the alignment requirements, does not
require reading program image metadata where it's impractical, and
enables
a compliant SYCL implementation to be built on top of it.

The ArgSizes array is required to support OpenCL, which does not have
native support for launching a kernel with an argument pointer array, or
a reliable way of retrieving argument sizes for a kernel.

## Mapping the proposed API to backends

CUDA and Level-Zero both support accepting an array of pointers to
kernel arguments, through `cuLaunchKernel`

(https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__EXEC.html#group__CUDA__EXEC_1gb8f3dc3031b40da29d5f9a7139e52e15)
and `zeCommandListAppendLaunchKernelWithArguments`

(https://oneapi-src.github.io/level-zero-spec/level-zero/latest/core/api.html#zecommandlistappendlaunchkernelwitharguments)
respectively.

For OpenCL, which requires the kernel arguments to be set separately
from the kernel launch, a potential implementation can extract the
number of arguments from the OpenCL API, and then iterate over the
argument pointer and size arrays:
```
  cl_uint num_args = 0;
  cl_int err = clGetKernelInfo(kernel, CL_KERNEL_NUM_ARGS,
                               sizeof(num_args), &num_args, NULL);
  for (cl_uint i = 0; i < num_args; ++i) {
    clSetKernelArg(kernel, i, ArgSizes[i], ArgPtrs[i]);
  }
```
The AMDGPU plugin needs to construct a contiguous buffer using the array
of argument pointers. To do this conversion, we need to have offsets
at which to place the arguments. Here, luckily, as mentioned before,
the AMD plugin already reads kernel metadata from the program image.
The implementation simply retrieves size and offset for each argument
from the kernel image, and then uses it to populate a buffer.
2026-05-29 19:54:22 +02:00
Joseph Huber a79158d2d6 [flang-rt] Remove library dependency from flang-rt to offload (#198793)
Summary:
We need the offload project's RPC thread to handle the IO requests
originating from the GPU. Previously we did the 'easy' solution and just
linked this handler directly into the offload proejct. This is not ideal
because it prevents people's ability to build and configure libraries
separately.

This PR inverts the dependency, flang-rt now conditionally enables
support using the existing RPC callback mechanism. The cost is that
every flang-rt program now pays the cost of a boolean compare, the
benefit is the libraries are now independent of each-other.
2026-05-22 07:44:27 -05:00
Alex Duran 5ee840cbe1 [OFFLOAD][L0] Remove support for non-immediate command lists (#198894)
The code was in a dead path as immediate command lists are always used.
2026-05-22 08:59:00 +02:00
Joseph Huber 012abddca1 [Offload] Fix LLVM_LINK_LLVM_DYLIB linking liboffload (#198955)
Summary:
When this is set you can only link against `LLVM`. The previous patch
did not respect this because I did not realize that internally in the
add_llvm_library that this was required.
2026-05-21 07:35:27 -05:00
Joseph HuberandKevin Sala Penades f5007fc09c [Offload] Make profiling support opt-in on events (#198810)
Summary:
Profiling requires getting time stamp information, which required
actually materializing barriers on the event. This caused performance
regressions in some OpenMP applications. Instead, we want to make this
opt in. This just adds a new argument to `olCreateEvent` which takes
some flags. Right now this is just none and profiling. Pretty mechanical
beyond that. Should revert this to the old behavior for OpenMP.

Co-authored-by: Kevin Sala Penades <kevinsala.ks@gmail.com>
2026-05-20 14:43:38 -05:00
Łukasz Plewa 7200655123 [offload][l0] Clear delayed copy lists after the copy (#198786) 2026-05-20 13:47:18 +00:00
Joseph Huber 3383f0d6fe [Offload] Fix build install directory and remove 'add_llvm_library' (#198622)
Summary:
The problem is that we do not correctly set the build directory output
for offload/. Normally, it's supposed to mirror the install pattern.
This is because we both have variants and so people can use the compiler
from the build directory.

Currently, if you build more than one variant of the offload/ library
they will clobber each-other in `<build>/lib/`, so no cross compiling
allowed. Additionally, these will not be usable in the build directory
because the compiler will think that they are in the triple directory
when they are not.

Relatively simple fix, just copy-paste the pattern every other runtime
uses and then remove the implicit handling we get from
`add_llvm_libraries`. The only this it did for us was automatically map
component names to the libraries, which is easy enough to do.
2026-05-19 15:31:41 -05:00
Łukasz Plewa 41010281d6 [offload] Add properties parameter to olLaunchKernel (#197897)
Introduce a properties argument to olLaunchKernel to enable future
extensions.
This change adds initial extension for cooperative kernel launch.

The change restores the functionality from:
https://github.com/llvm/llvm-project/pull/184343
which was later reverted in:
https://github.com/llvm/llvm-project/pull/197463

#184343 modified the API, and between the last rebase and the final
merge, additional tests were added
upstream(https://github.com/llvm/llvm-project/pull/193927) that still
relied on the previous API version.

Diff between this PR and #184343 
```
diff --git a/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp b/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp
index 0251bffefe60..cd527f18db38 100644
--- a/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp
+++ b/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp
@@ -241,8 +241,8 @@ TEST_P(olLaunchKernelSingleCounterSyncEventTest, SuccessSyncEvent) {
   ArgsSingleCounter Args{LoopRange, NumberToAdd, (uint32_t *)InitValuePassed,
                          (uint32_t *)ResNum};
 
-  ASSERT_SUCCESS(
-      olLaunchKernel(Queue, Device, Kernel, &Args, sizeof(Args), &LaunchArgs));
+  ASSERT_SUCCESS(olLaunchKernel(Queue, Device, Kernel, &Args, sizeof(Args),
+                                &LaunchArgs, nullptr));
 
   uint32_t FinalResVal = 0;
   ASSERT_SUCCESS(olMemcpy(Queue, &FinalResVal, Host, ResNum, Device, Size));
@@ -294,8 +294,8 @@ TEST_P(olLaunchKernelSingleCounterSyncEventTest, SuccessTwoQueues) {
 
   ArgsSingleCounter Args{LoopRange, NumberToAdd, (uint32_t *)InitValuePassed,
                          (uint32_t *)ResNum1};
-  ASSERT_SUCCESS(
-      olLaunchKernel(Queue, Device, Kernel, &Args, sizeof(Args), &LaunchArgs));
+  ASSERT_SUCCESS(olLaunchKernel(Queue, Device, Kernel, &Args, sizeof(Args),
+                                &LaunchArgs, nullptr));
 
   ol_event_handle_t Event = nullptr;
   ASSERT_SUCCESS(olCreateEvent(Queue, &Event));
@@ -308,7 +308,7 @@ TEST_P(olLaunchKernelSingleCounterSyncEventTest, SuccessTwoQueues) {
   // been completed by the time the kernel is executed using the second queue,
   // the FinalResVal would be incorrect.
   ASSERT_SUCCESS(olLaunchKernel(Queue2, Device, Kernel, &Args2, sizeof(Args2),
-                                &LaunchArgs));
+                                &LaunchArgs, nullptr));
 
   ASSERT_SUCCESS(olSyncQueue(Queue2));
   uint32_t FinalResVal = 0;
```
2026-05-18 17:07:38 +02:00
Joseph Huber 319a50123c [Offload] Fix missing dependency on generated OffloadAPI headers (#198055)
Summary:
These are included in the plugins but not a dependency

Fixes: https://github.com/llvm/llvm-project/issues/196690
2026-05-15 21:28:05 -05:00
Alex Duran e1135dc2bf [OFFLOAD][L0] Simplify kernel setGroups logic (#197411)
This code path is not really used with upstream code generation.
2026-05-14 10:07:19 +02:00
Robert Imschweiler 7091f885fd [NFC][offload] Some more clarifying renaming of threads and blocks variables (#197511)
As requested in https://github.com/llvm/llvm-project/pull/197419.
2026-05-13 19:14:13 +02:00