summaryrefslogtreecommitdiff
path: root/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp
AgeCommit message (Collapse)Author
2024-04-22[Offload] Move `/openmp/libomptarget` to `/offload` (#75125)Johannes Doerfert
In a nutshell, this moves our libomptarget code to populate the offload subproject. With this commit, users need to enable the new LLVM/Offload subproject as a runtime in their cmake configuration. No further changes are expected for downstream code. Tests and other components still depend on OpenMP and have also not been renamed. The results below are for a build in which OpenMP and Offload are enabled runtimes. In addition to the pure `git mv`, we needed to adjust some CMake files. Nothing is intended to change semantics. ``` ninja check-offload ``` Works with the X86 and AMDGPU offload tests ``` ninja check-openmp ``` Still works but doesn't build offload tests anymore. ``` ls install/lib ``` Shows all expected libraries, incl. - `libomptarget.devicertl.a` - `libomptarget-nvptx-sm_90.bc` - `libomptarget.rtl.amdgpu.so` -> `libomptarget.rtl.amdgpu.so.18git` - `libomptarget.so` -> `libomptarget.so.18git` Fixes: https://github.com/llvm/llvm-project/issues/75124 --------- Co-authored-by: Saiyedul Islam <Saiyedul.Islam@amd.com>
2024-04-17Revert "[Libomptarget] Rework Record & Replay to be a plugin member" (#89028)Jan Patrick Lehr
Reverts llvm/llvm-project#88928 This broke the AMDGPU buildbots: https://lab.llvm.org/buildbot/#/builders/193/builds/50201 https://lab.llvm.org/staging/#/builders/185/builds/5565 https://lab.llvm.org/buildbot/#/builders/259/builds/2955
2024-04-16[Libomptarget] Rework Record & Replay to be a plugin member (#88928)Joseph Huber
Summary: Previously, the R&R support was global state initialized by a global constructor. This is bad because it prevents us from adequately constraining the lifetime of the library. Additionally, we want to minimize the amount of global state floating around. This patch moves the R&R support into a plugin member like everything else. This means there will be multiple copies of the R&R implementation floating around, but this was already the case given the fact that we currently handle everything with dynamic libraries.
2024-04-01[Libomptarget] Fix resizing the buffer of RPC handlesJoseph Huber
Summary: The previous code would potentially make it smaller if a device with a lower ID touched it later. Also we should minimize changes to the state for multi threaded reasons. This just sets up an owned slot for each at initialization time.
2024-03-29[libc] Change RPC interface to not use device ids (#87087)Joseph Huber
Summary: The current implementation of RPC tied everything to device IDs and forced us to do init / shutdown to manage some global state. This turned out to be a bad idea in situations where we want to track multiple hetergeneous devices that may report the same device ID in the same process. This patch changes the interface to instead create an opaque handle to the internal device and simply allocates it via `new`. The user will then take this device and store it to interface with the attached device. This interface puts the burden of tracking the device identifier to mapped d evices onto the user, but in return heavily simplifies the implementation.
2024-03-27[Libomptarget] Move API implementations into GenericPluginTy (#86683)Joseph Huber
Summary: The plan is to remove the entire plugin interface and simply use the `GenericPluginTy` inside of `libomptarget` by statically linking against it. This means that inside of `libomptarget` we will simply do `Plugin.data_alloc` without the dynamically loaded interface. To reduce the amount of code required, this patch simply moves all of the RTL implementation functions inside of the Generic device. Now the `__tgt_rtl_` interface is simply a shallow wrapper that will soon go away. There is some redundancy here, this will be improved later. For now what is important is minimizing the changes to the API.
2024-03-26[Libomptarget] Replace global `PluginTy::get` interface with references (#86595)Joseph Huber
Summary: We have a plugin singleton that implements the Plugin interface. This then spawns separate device and kernels. Previously when these needed to reach into the global singleton they would use the `PluginTy::get` routine to get access to it. In the future we will move away from this as the lifetime of the plugin will be handled by `libomptarget` directly. This patch removes uses of this inside of the plugin implementaion themselves by simply keeping a reference to the plugin inside of the device. The external `__tgt_rtl` functions still use the global method, but will be removed later.
2024-03-25[Libomptarget] Factor functions out of 'Plugin' interface (#86528)Joseph Huber
Summary: This patch factors common functions out of the `Plugin` interface prior to its removal in a future patch. This simply temporarily renames it to `PluginTy` so that we could re-use `Plugin::check` internally as this needs to be defined statically per plugin now. We can refactor this later. The future patch will delete `PluginTy` and `PluginTy::get` entirely. This simply tries to minimize a few changes to make it easier to land.
2024-03-19[OpenMP] Increment kernel args version, used by runtime for detecting ↵dhruvachak
dyn_ptr. (#85363) A kernel implicit parameter (dyn_ptr) was introduced some time back. This patch increments the kernel args version for a compiler supporting dyn_ptr. The version will be used by the runtime to determine whether the implicit parameter is generated by the compiler. The versioning is required to support use cases where code generated by an older compiler is linked with a newer runtime. If approved, this patch should be backported to release 18.
2024-03-15[Libomptarget][NFC] Remove warning on return value constJoseph Huber
2024-02-05[Libomptarget] Remove unused 'SupportsEmptyImages' API function (#80316)Joseph Huber
Summary: This function is always false in the current implementation and is not even considered required. Just remove it and if someone needs it in the future they can add it back in. This is done to simplify the interface prior to other changes
2024-01-22[Libomptarget] Move target table handling out of the plugins (#77150)Joseph Huber
Summary: This patch removes the bulk of the handling of the `__tgt_offload_entries` out of the plugins itself. The reason for this is because the plugins themselves should not be handling this implementation detail of the OpenMP runtime. Instead, we expose two new plugin API functions to get the points to a device pointer for a global as well as a kernel type. This required introducing a new type to represent a binary image that has been loaded on a device. We can then use this to load the addresses as needed. The creation of the mapping table is then handled just in `libomptarget` where we simply look up each address individually. This should allow us to expose these operations more generically when we provide a separate API.
2024-01-22[OpenMP] Enable automatic unified shared memory on MI300A. (#77512)carlobertolli
This patch enables applications that did not request OpenMP unified_shared_memory to run with the same zero-copy behavior, where mapped memory does not result in extra memory allocations and memory copies, but CPU-allocated memory is accessed from the device. The name for this behavior is "automatic zero-copy" and it relies on detecting: that the runtime is running on a MI300A, that the user did not select unified_shared_memory in their program, and that XNACK (unified memory support) is enabled in the current GPU configuration. If all these conditions are met, then automatic zero-copy is triggered. This patch also introduces an environment variable OMPX_APU_MAPS that, if set, triggers automatic zero-copy also on non APU GPUs (e.g., on discrete GPUs). This patch is still missing support for global variables, which will be provided in a subsequent patch. Co-authored-by: Thorsten Blass <thorsten.blass@amd.com>
2024-01-10[Libomptarget] Do not abort on failed plugin init (#77623)Joseph Huber
Summary: The current code logic is supposed to skip plugins that aren't found or could not be loaded. However, the plugic ontained a call to `abort` if it failed, which prevented us from continuing if initilalization the plugin failed (such as if `dlopen` failed for the dyanmic plugins).
2024-01-10[Libomptarget][NFC] Format in-line comments consistently (#77530)Joseph Huber
Summary: The LLVM style uses /*Foo=*/ when indicating the name of a constant. See https://llvm.org/docs/CodingStandards.html#comment-formatting. This is useful for consistency, as well as because `clang-format` understands this syntax and formats it more cleanly. Do a bulk update of this syntax.
2024-01-08Revert "[OpenMP][libomptarget] Enable automatic unified shared memory ↵carlobertolli
executi…" (#77371) Reverts llvm/llvm-project#75999 lit test is failing.
2024-01-08[OpenMP][libomptarget] Enable automatic unified shared memory executi… ↵carlobertolli
(#75999) …on (zero-copy) on MI300A. This patch enables applications that did not request OpenMP unified_shared_memory to run with the same zero-copy behavior, where mapped memory does not result in extra memory allocations and memory copies, but CPU-allocated memory is accessed from the device. The name for this behavior is "automatic zero-copy" and it relies on detecting: that the runtime is running on a MI300A, that the user did not select unified_shared_memory in their program, and that XNACK (unified memory support) is enabled in the current GPU configuration. If all these conditions are met, then automatic zero-copy is triggered. This patch is still missing support for global variables, which will be provided in a subsequent patch. Co-authored-by: Thorsten Blass <thorsten.blass@amd.com>
2024-01-08[Libomptarget][NFC] Fix unhandled allocator enum valueJoseph Huber
2023-12-29[Libomptarget] Rework image checking further (#76120)Joseph Huber
Summary: In the future, we may have more checks for different kinds of inputs, e.g. SPIR-V. This patch simply reworks the handling to be more generic and do the magic detection up-front. The checks inside the routines are now asserts so we don't spend time checking this stuff over and over again. This patch also tweaked the bitcode check. I used a different function to get the Lazy-IR module now, as it returns the raw expected value rather than the SM diganostic. No functionality change intended.
2023-12-19[Libomptarget] Remove __tgt_image_info and use the ELF directly (#75720)Joseph Huber
Summary: This patch reorganizes a lot of the code used to check for compatibility with the current environment. The main bulk of this patch involves moving from using a separate `__tgt_image_info` struct (which just contains a string for the architecture) to instead simply checking this information from the ELF directly. Checking information in the ELF is very inexpensive as creating an ELF file is simply writing a base pointer. The main desire to do this was to reorganize everything into the ELF image. We can then do the majority of these checks without first initializing the plugin. A future patch will move the first ELF checks to happen without initializing the plugin so we no longer need to initialize and plugins that don't have needed images. This patch also adds a lot more sanity checks for whether or not the ELF is actually compatible. Such as if the images have a valid ABI, 64-bit width, executable, etc.
2023-12-18[OpenMP] Directly use user's grid and block size in kernel language mode ↵Shilei Tian
(#70612) In kernel language mode, use user's grid and blocks size directly. No validity check, which means if user's values are too large, the launch will fail, similar to what CUDA and HIP are doing right now.
2023-12-18[Libomptarget] Remove remaining global constructors in plugins (#75814)Joseph Huber
Summary: This patch fixes the remaining global constructor in the plguins after addressing the ones in the JIT interface. This struct was mistakenly using global constructors as not all the members were being initialized properly. This was almost certainly being optimized out because it's trivial, but would still be present in debug builds and prevented us from compiling with `-Werror=global-constructors`. We will want to do that once offloading is moved to a runtimes only build.
2023-12-06[OpenMP][FIX] Ensure we do not read outside the device image (#74669)Johannes Doerfert
Before we expected all symbols in the device image to be backed up with data that we could read. However, uninitialized values are not. We now check for this case and avoid reading random memory. This also replaces the correct readGlobalFromImage call with a isSymbolInImage check after https://github.com/llvm/llvm-project/pull/74550 picked the wrong one. Fixes: https://github.com/llvm/llvm-project/issues/74582
2023-12-06[Libomptarget] Add a utility function for checking existence of symbols (#74550)Joseph Huber
Summary: There are now a few cases that check if a symbol is present before continuing, effectively making them optional features if present in the image. This was done in at least three locations and required an ugly operation to consume the error. This patch makes a utility function to handle that instead.
2023-12-05[OpenMP] Reorganize the initialization of `PluginAdaptorTy` (#74397)Johannes Doerfert
This introduces checked errors into the creation and initialization of `PluginAdaptorTy`. We also allow the adaptor to "hide" devices from the user if the initialization failed. The new organization avoids the "initOnce" stuff but we still do not eagerly initialize the plugin devices (I think we should merge `PluginAdaptorTy::initDevices` into `PluginAdaptorTy::init`)
2023-12-05[OpenMP][FIX] Ensure we allow shared libraries without kernels (#74532)Johannes Doerfert
This fixes two bugs and adds a test for them: - A shared library with declare target functions but without kernels should not error out due to missing globals. - Enabling LIBOMPTARGET_INFO=32 should not deadlock in the presence of indirect declare targets.
2023-12-01[OpenMP] Add an INFO message for data transfer of kernel launch env. (#74030)dhruvachak
2023-11-29[OpenMP][NFC] Move out plugin API and APITypes into standalone headers (#73868)Johannes Doerfert
2023-11-29[OpenMP] Avoid initializing the KernelLaunchEnvironment if possible (#73864)Johannes Doerfert
If we don't have a team reduction we don't need a kernel launch environment (for now). In that case we can avoid the cost.
2023-11-29[OpenMP][NFC] Move OMPT headers into OpenMP/OMPT (#73718)Johannes Doerfert
2023-11-29[OpenMP][NFC] Flatten plugin-nextgen/common folder sturcture (#73725)Johannes Doerfert
For historic reasons we had it setup that there was ` plugin-nextgen/common/PluginInterface/<sources + headers>` which is not what we do anywhere else. Now it looks like the rest: ``` plugin-nextgen/common/include/<headers> plugin-nextgen/common/src/<sources> ``` As part of this, `dlwrap.h` was moved into common/include (as `DLWrap.h`) since it is exclusively used by the plugins.