This PR implements SLM for Level Zero backend. Every kernel in a module lowered by the new SPIR-V pass receives a trailing `__local` argument, including kernels that do not use SLM. In order to support existing code that uses offload, the PR adds an additional pass to SPIRV backend. The idea is that the pass is searching for all extern unsized workgroup arrays and then it converts them to a global variable that is initialized by an additional kernel argument to every kernel in the module, including kernels that do not reference the array. The pass closes the gap between cuda/hsa and level_zero handling of the dynamically sized workgroup memory, because level_zero (and openCL) only support the local memory sized through kernel arguments compared to cuda which configures it during kernel launch. It was inspired by existing code in intel's fork of llvm. Adds two new tests that exercise the local memory in liboffload and openMP lit. They both follow a similar pattern where the local memory is used to share data between threads, so we can be certain that no thread overwrites it. It was necessary, because Intel Graphics Compiler would sometimes be okay with such uninitialized array and the threads would use memory that was not allocated for them. Tests such as `dyn_groupprivate.cpp` are not enabled yet for intel GPUs due to problems with generic mode. Assisted by claude.
Liboffload
This directory contains the implementation of the work-in-progress new API for Offload. It builds on top of the existing plugin implementations but provides a single level of abstraction suitable for implementation of many offloading language runtimes, rather than just OpenMP.
Testing liboffload
The main test suite for liboffload can be run with the check-offload-unit
target, which runs the offload.unittests executable. The test suite will
automatically run on every available device, but can be restricted to a single
platform (CUDA, AMDGPU) with a command line argument:
$ ./offload.unittests --platform=CUDA
Tracing of Offload API calls can be enabled by setting the OFFLOAD_TRACE
environment variable. This works with any program that uses liboffload.
$ OFFLOAD_TRACE=1 ./offload.unittests
---> olInit(nullptr)-> OL_SUCCESS
# etc
The host plugin is not currently supported.
Modifying liboffload
The main header (OffloadAPI.h) and some implementation details are
autogenerated with tablegen. See the API definition README
for implementation details.