Commit Graph

2381 Commits

Author SHA1 Message Date
Joseph Huber c2acb1e5d3 [Libomptarget][NFC] Remove unused variable 2022-09-09 15:26:02 -05:00
Joseph Huber 86587f2891 [Libomptarget] Fix compiling with asserts using the bitcode library
Sumnmary:
A previous patch introduces an `exports` file which contains all the
symbol names that are not internalized in the bitcode library. This is
done to reduce the size of the bitcode library and only export needed
functions. This export file must contain all the functoins expected to
be called from the device. Since its introduction the `__assert_fail`
function used to be provided but was mistakenly not included. This patch
adds it.

Fixes #57656

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D133594
2022-09-09 15:25:24 -05:00
Joseph Huber 83fcba82cc [Libomptarget] Add proper LLVM libraries now that the AMDGPU plugin uses them
Summary:
The AMDGPU and CUDA plugins now relies on the Object and Support
libraries. This patch adds them explicitly rather than hoping that they
share the symbols loaded from the standard `libomptarget`.
2022-09-09 10:33:26 -05:00
serge-sans-paille 6f2ed8fd3f [OpenMP] Install ompt-multiplex.h alongside omp.h
The default install direction may not be in the compiler search path.

Differential Revision: https://reviews.llvm.org/D133420
2022-09-09 09:42:08 +02:00
Jonathan Peyton e5ac98fa01 [OpenMP][libomp] Cleanup __kmpc_flush() code
Have it be simple KMP_MFENCE() which incorporates x86-specific logic and
reduces to KMP_MB() for other architectures.

Differential Revision: https://reviews.llvm.org/D130928
2022-09-08 16:17:20 -05:00
Joseph Huber 6e8d93e5c2 [Libomptarget] Implement OpenMP 5.2 semantics for device pointers
In OpenMP 5.2, §5.8.6, page 160 line 32-33, when a device pointer
allocated by omp_target_alloc has implicitly been included on a target
construct as a zero-length array, the pointer initialisation should not
find a matching mapped list item, and so should retain its value as a
firstprivate variable. Previously, we would return a null pointer if the
list item was not found. This patch updates the map handling to the
OpenMP 5.2 semantics.

Reviewed By: jdoerfert, ye-luo

Differential Revision: https://reviews.llvm.org/D133447
2022-09-07 17:01:14 -05:00
Joseph Huber 8d2a447bf9 [Libomptarget] Remove leftover ELF header from x86 plugin
Summary:
We removed the linking support for `gelf.h` in a previous patch. This
header was incorrectly leftover causing build problems on some systems.
2022-09-07 13:41:40 -05:00
Joseph Huber 300155911a [Libomptarget] Replace libelf with LLVM's Elf libraries
This patch replaces the dependency on `libelf` with LLVM's ELF support.
With this patch the user no-longer needs to have `libelf` on their
system to build and configure OpenMP offloading. The replacement is
mostly mechanical, with the exception of the hash table support which
was added in D131309.

Depends on D131309

Reviewed By: JonChesterfield, saiislam

Differential Revision: https://reviews.llvm.org/D131401
2022-09-07 12:38:51 -05:00
Joseph Huber 894531f59b [Libomptarget] Add utility functions for loading an ELF symbol by name
The `SHT_HASH` sections in an ELF are used to look up a symbol in the
symbol table using a symbol's name. This is done by obtaining the
`SHT_HASH` section and using its `sh_link` attribute to access the
associated symbol table, from which we can access the string table
containing the associated name. We can then search for the symbol using
the hash of the name and the buckets and chains in the hash table
itself

This patch adds utility functions that allow us to look up a symbol in
an ELF file by name. It will first attempt to look through the hash
tables, and then search the section tables manually if failed. This
allows us to pull out constants necessary for setting up offloading
without first loading the object.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D131309
2022-09-07 12:38:50 -05:00
Joseph Huber 31f434ee3b [Libomptarget][NFC] Clean up CUDA plugin and address warnings 2022-09-06 15:28:57 -05:00
Vignesh Balasubramanian d2a6e165e8 [OpenMP][OMPD] GDB plugin code to leverage libompd to provide debugging
support for OpenMP programs.

This is 5th of 6 patches started from https://reviews.llvm.org/D100181
This plugin code, when loaded in gdb, adds a few commands like
ompd icv, ompd bt, ompd parallel.
These commands create an interface for GDB to read the OpenMP
runtime through libompd.

Reviewed By: @dreachem
Differential Revision: https://reviews.llvm.org/D100185
2022-09-06 11:28:55 +05:30
Ye Luo 0e68f483d4 [OpenMP] add a offload test involving std::complex
Taken from the https://github.com/llvm/llvm-project/issues/57064 reproducer.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D133258
2022-09-03 13:28:11 -05:00
Joseph Huber f8b1f93f26 [libomptarget] Enable the device allocator for AMDGPU
This patch adds support for the device memory type, this is currently equivalent
to the default type so it should be treated as the same.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D133128
2022-09-01 12:40:59 -05:00
Joseph Huber 56cf3d626f [Libomptarget] Remove old workaround for GCC 5,6 from libomptarget
Some code previous needed the `used` attribute to prevent the GCC
compiler versions 5 and 6 from removing it. This is no longer required
as the minimum supported GCC version for LLVM 16 is >=7.1.0.

Reviewed By: JonChesterfield, vzakhari

Differential Revision: https://reviews.llvm.org/D132976
2022-08-30 19:13:48 -05:00
Joseph Huber 52556c3c0f [Libomptarget] Make unified shared memory test unsupported on AMDGPU
This test is an expected failure on AMDGPU. The expected failure is a GPU memory
failure, which will typically result in the device totally failing. This isn't
an issue for some GPU configurations that do not use the offloading device to
also drive the display server. However, if the main GPU is used for testing it
will reliably result in the user's display becoming unresponsive. This makes it
difficult to run the GPU offloading tests on many systems.

This patch simply makes this test unsupported so it no longer runs and freezes
my computer when using `ninja check-openmp`.

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D132891
2022-08-30 12:14:25 -05:00
Joseph Huber dc400f8612 [libomptarget] Deprecate old method for setting the tripcount
Previously, the tripcount was set by a push call. We moved away from
this with the new interface that added the tripcount to the kernel
arguments struct, but kept around the old interface for legacy purposes
for the LLVM 15 release. This patch removes the support for the legacy
method.

This removes the support for the old method, but does not break
backwards compatibility. This will result in applications using the old
interface being slower when run on the device.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D132885
2022-08-29 20:08:26 -05:00
Joseph Huber 04ae35e592 [libomptarget] Always enable time tracing in libomptarget
Previously time tracing features were hidden behind an optional CMake
option. This was because `libomptarget` was not based on the LLVM
libraries at that time. Now that `libomptarget` is an LLVM library we
should be able to freely use the `LLVMSupport` library whenever we want
and do not need to guard it in this way.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D132852
2022-08-29 14:49:03 -05:00
Joseph Huber 22d71e72c9 [Libomptarget] Do not check for valid binaries twice.
The only RTLs that get added to the `UsedRTLs` list have already been
checked is they were valid binaries. We shouldn't need to do this again
when we unregister all the used binaries as they wouldn't have been used
if they were invalid anyway. Let me know if I'm incorrect in this
assumption.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D131443
2022-08-29 08:36:50 -05:00
Joseph Huber 47166968db [OpenMP] Deprecate the old driver for OpenMP offloading
Recently OpenMP has transitioned to using the "new" driver which
primarily merges the device and host linking phases into a single
wrapper that handles both at the same time. This replaced a few tools
that were only used for OpenMP offloading, such as the
`clang-offload-wrapper` and `clang-nvlink-wrapper`. The new driver
carries some marked benefits compared to the old driver that is now
being deprecated. Things like device-side LTO, static library
support, and more compatible tooling. As such, we should be able to
completely deprecate the old driver, at least for OpenMP. The old driver
support will still exist for CUDA and HIP, although both of these can
currently be compiled on Linux with `--offload-new-driver` to use the new
method.

Note that this does not deprecate the `clang-offload-bundler`, although
it is unused by OpenMP now, it is still used by the HIP toolchain both
as their device binary format and object format.

When I proposed deprecating this code I heard some vendors voice
concernes about needing to update their code in their fork. They should
be able to just revert this commit if it lands.

Reviewed By: jdoerfert, MaskRay, ye-luo

Differential Revision: https://reviews.llvm.org/D130020
2022-08-26 13:47:09 -05:00
Jon Chesterfield ffabe997a5 [openmp][amdgpu] Implement target_alloc_host as fine grain HSA memory
The cuda plugin maps TARGET_ALLOC_HOST onto cuMemAllocHost
which is page locked host memory. Fine grain HSA memory is not
necessarily page locked but has the same read/write from host or
device semantics.

The cuda plugin does this per-gpu and this patch makes it accessible
from any gpu, but it can be locked down to match the cuda behaviour
if preferred.

Enabling tests requires an equivalent to
// RUN: %libomptarget-compile-run-and-check-nvptx64-nvidia-cuda
for amdgpu which doesn't seem to be in use yet.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D132660
2022-08-25 16:27:52 +01:00
Ye Luo 322ea53144 [libomptarget][amdgpu] enable tests whenever possible.
if(TARGET amdgpu-arch) doesn't work when ENABLE_LLVM_PROJECTS=openmp because openmp subdirectory is processed before clang subdirectory. Adopt the same logic of enabling tests like the CUDA plugin.

Differential Revision: https://reviews.llvm.org/D132579
2022-08-24 14:33:28 -05:00
Joseph Huber 540a13652f [Libomptarget] Replace use of `dlopen` with LLVM's dynamic library support
This patch replaces uses of `dlopen` and `dlsym` with LLVM's support
with `loadPermanentLibrary` and `getSymbolAddress`. This allows us to
remove the explicit dependency on the `dl` libraries in the CMake. This
removes another explicit dependency and solves an issue encountered
while building on Windows platforms. The one downside to this is that
the LLVM library does not currently support `dlclose` functionality, but
this could be added in the future.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D131507
2022-08-24 10:46:21 -05:00
Joseph Huber 30efb459e0 [Libomptarget] Remove use of ELF link_address in x86_64 plugin
We use the offloading entires array to determine the relative names and
addressed of device-side kernel functions. The x86_64 plugin previously
derived the device-side entry table by first identifying the
`omp_offloading_entries` section offset in the loaded elf. Then we would
use the base offset of the loaded dyanmic library to identify the
entries array within the loaded image. This relied on some more
unconventional methods which prevented us from using the LLVM dynamic
library loader for this plugin. This patch simplifies this by instead
copying the host-side entry and replacing its address with the
device-side address looked up through `dlsym`.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D131516
2022-08-24 10:46:20 -05:00
Vitaly Buka 3195449f2b [test][openmp] Relax condition in test
It runs 8 threads. Sometimes tsan is able to detect more than one of the
same race.
2022-08-23 14:29:06 -07:00
Joseph Huber 2b8f722e63 [OpenMP] Add option to assert no nested OpenMP parallelism on the GPU
The OpenMP device runtime needs to support the OpenMP standard. However
constructs like nested parallelism are very uncommon in real application
yet lead to complexity in the runtime that is sometimes difficult to
optimize out. As a stop-gap for performance we should supply an argument
that selectively disables this feature. This patch adds the
`-fopenmp-assume-no-nested-parallelism` argument which explicitly
disables the usee of nested parallelism in OpenMP.

Reviewed By: carlo.bertolli

Differential Revision: https://reviews.llvm.org/D132074
2022-08-23 14:09:51 -05:00
utsumi 2e2caea37f [Clang][OpenMP] Make copyin clause on combined and composite construct work (patch by Yuichiro Utsumi (utsumi.yuichiro@fujitsu.com))
Make copyin clause on the following constructs work.

- parallel for
- parallel for simd
- parallel sections

Fixes https://github.com/llvm/llvm-project/issues/55547

Patch by Yuichiro Utsumi (utsumi.yuichiro@fujitsu.com)

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D132209
2022-08-23 07:58:35 -07:00
John Ericson e941b031d3 Revert "[cmake] Use `CMAKE_INSTALL_LIBDIR` too"
This reverts commit f7a33090a9.

Unfortunately this causes a number of failures that didn't show up in my
local build.
2022-08-18 22:46:32 -04:00
John Ericson f7a33090a9 [cmake] Use `CMAKE_INSTALL_LIBDIR` too
We held off on this before as `LLVM_LIBDIR_SUFFIX` conflicted with it.
Now we return this.

`LLVM_LIBDIR_SUFFIX` is kept as a deprecated way to set
`CMAKE_INSTALL_LIBDIR`. The other `*_LIBDIR_SUFFIX` are just removed
entirely.

I imagine this is too potentially-breaking to make LLVM 15. That's fine.
I have a more minimal version of this in the disto (NixOS) patches for
LLVM 15 (like previous versions). This more expansive version I will
test harder after the release is cut.

Reviewed By: sebastian-ne, ldionne, #libc, #libc_abi

Differential Revision: https://reviews.llvm.org/D130586
2022-08-18 15:33:35 -04:00
Kevin Sala Penads 1081bb08cc [OpenMP][libomptarget] Fix run region async condition
This patch fixes a condition in the openmp/libomptarget/src/device.cpp file. The code was checking if the run_region plugin API function was implemented, but it should actually check the run_region_async function instead.

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D131782
2022-08-15 13:08:45 -04:00
Fangrui Song acfe0d3b15 [openmp] Remove __ANDROID_API__ < 19 workaround
https://github.com/android/ndk/wiki/Changelog-r24 shows that the NDK has
moved forward to at least a minimum target API of 19. Remove old workaround.
2022-08-12 22:15:38 -07:00
Jennifer Yu 2ca27206f9 [OpenMP] Fix segmentation fault when data field is used in is_device_pt
Currently, the field just emit map info for this pointer variable. It is
failed at run time. For the fields, the PartialStruct is created and it
needs call to emitCombinedEntry which create the base that covers all
the pieces.

The change is to generate map info as regular fields.

Differential Revision: https://reviews.llvm.org/D129608
2022-08-12 17:10:26 -07:00
Jonathan Peyton 56f36f85e0 [OpenMP][OMPT] Fix memory leak when using GCC compatibility code
Serialized parallels allocate lightweight task teams on the heap
but never free them in the corresponding join. This patch adds a wrapper
around the allocation (if ompt enabled) and also adds the corresponding
free in the join call.

Differential Revision: https://reviews.llvm.org/D131690
2022-08-11 15:26:09 -05:00
Johannes Doerfert a8cda32909 [OpenMP][FIX] Ensure __kmpc_kernel_parallel is reachable
The problem is we create the call to __kmpc_kernel_parallel in the
openmp-opt pass but while we optimize the code, the call is not there
yet. Thus, we assume we never reach it from __kmpc_target_deinit. That
allows us to remove the store in there (`ParallelRegionFn = nullptr`),
which leads to bad results later on.

This is a shortstop solution until we come up with something better.

Fixes https://github.com/llvm/llvm-project/issues/57064
2022-08-11 09:55:56 -05:00
Joseph Huber fdbb15355e [Libomptarget][CUDA] Check CUDA compatibilty correctly
We recently added support for multi-architecture binaries in
libomptarget. This is done by extracting the architecture from the
embedded image and comparing it with the major and minor version
supported by the current CUDA installation. Previously we just compared
these directly, which was not correct for binary compatibility. The CUDA
documentation states that we can consider any image with an equivalent
major or a greater or equal to minor compatible with the current image.
Change the check to use this new logic in the CUDA plugin.

Fixes #57049

Reviewed By: jdoerfert, ye-luo

Differential Revision: https://reviews.llvm.org/D131567
2022-08-10 11:15:27 -04:00
Ron Lieberman 9ff0cc7e0f [openmp] Fix enumeration build issue for openmp library
integer value 40962 is outside the valid range of values [0, 31] for this enumeration type [-Wenum-constexpr-conversion]` (Issue #57022)

turn on -Wno-enum-constexpr-conversion to buy some time to fix the more egregious issue in hsa_agent_into_t and hsa_amd_agent_info_t interfaces.

relates to https://reviews.llvm.org/D131307/new/

Differential Revision: https://reviews.llvm.org/D131477
2022-08-09 10:25:03 +00:00
Fangrui Song 0972a390b9 LLVM_FALLTHROUGH => [[fallthrough]]. NFC 2022-08-09 04:06:52 +00:00
Jon Chesterfield 521a5c11ac Rename OPENMP_HAVE_STD_CPP14_FLAG to match c++17 2022-08-08 17:07:45 +01:00
Ron Lieberman af28b27d31 Move openmp from -std=c++14 to -std=c++17 2022-08-08 16:04:57 +00:00
Jon Chesterfield 104f11630a [nfc][openmp] clang-format system.cpp prior to D131401 2022-08-08 16:24:34 +01:00
Shilei Tian 294bbdc0b8 [NFC] Fix wrong header in `LibC.cpp` 2022-08-04 23:54:07 -04:00
Shilei Tian 459e3c5184 [OpenMP] Fix the test case issue that printf cannot be used in target region for AMDGPU 2022-08-04 14:48:48 -04:00
Shilei Tian db5a2afa62 [OpenMP][DeviceRTL] Implement libc function `memcmp`
We will add some simple implementation of libc functions starting from
this patch, and the first one is `memcmp`, which is reported in #56929. Note that
`malloc` and `free` are not included in this patch because of the use of
`declare variant`. In the near future we will implement the two functions w/o
using any vendor provided function.

This fixes #56929.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D131182
2022-08-04 14:37:54 -04:00
Joseph Huber b3335e8ed7 [Libomptarget][NFC] Clang format the AMDGPU plugin
Summary:
A previous patch did not format the plugin again after making changes.
Ensure that libomptarget stays formatted.
2022-08-03 15:18:16 -04:00
Joseph Huber 2b7203a359 [Libomptarget] Deinitialize AMDGPU global state more intentionally
A previous patch made the destruction of the HSA plugin more
deterministic. However, there were still other global values that are not
handled this way. When attempting to call a destructor kernel, the
device would have already been uninitialized and we could not find the
appropriate kernel to call. This is because they were stored in global
containers that had their destructors called already. Merges this global
state into the rest of the info state by putting those global values
inside of the global pointer already allocated and deallocated by the
constructor and destructor. This should allow the AMDGPU plugin to
correctly identify the destructors if we were to run them.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D131011
2022-08-02 18:24:39 -04:00
Jonathan Peyton 9cf6511bff [OpenMP][libomp] Detect if test compiler has omp.h
omp50_taskdep_depobj.c relies on the test compiler's omp.h file.
If the test compiler does not have an omp.h file, then use the one
within the build tree.

Fixes: https://github.com/llvm/llvm-project/issues/56820
Differential Revision: https://reviews.llvm.org/D131000
2022-08-02 17:05:56 -05:00
Martin Storsjö 3f25ad335b [OpenMP] Fix warnings about unused expressions when OMPT_LOOP_DISPATCH is a no-op. NFC.
This fixes warnings like these:

../runtime/src/kmp_dispatch.cpp:2159:24: warning: left operand of comma operator has no effect [-Wunused-value]
    OMPT_LOOP_DISPATCH(*p_lb, *p_ub, pr->u.p.st, status);
                       ^~~~~
../runtime/src/kmp_dispatch.cpp:2159:31: warning: left operand of comma operator has no effect [-Wunused-value]
    OMPT_LOOP_DISPATCH(*p_lb, *p_ub, pr->u.p.st, status);
                              ^~~~~
../runtime/src/kmp_dispatch.cpp:2159:46: warning: left operand of comma operator has no effect [-Wunused-value]
    OMPT_LOOP_DISPATCH(*p_lb, *p_ub, pr->u.p.st, status);
                                     ~~~~~~~ ^~
../runtime/src/kmp_dispatch.cpp:2159:50: warning: expression result unused [-Wunused-value]
    OMPT_LOOP_DISPATCH(*p_lb, *p_ub, pr->u.p.st, status);
                                                 ^~~~~~
2022-08-02 11:16:23 +03:00
Martin Storsjö 7f24fd26a8 [OpenMP] Only include CMAKE_DL_LIBS on unix platforms
CMAKE_DL_LIBS is documented as "Name of library containing dlopen
and dlclose".

On Windows platforms, there's no system provided dlopen/dlclose, but
it can be argued that if you really intend to call dlopen/dlclose,
you're going to be using a third party compat library like
https://github.com/dlfcn-win32/dlfcn-win32, and CMAKE_DL_LIBS should
expand to its name.

This has been argued upstream in CMake in
https://gitlab.kitware.com/cmake/cmake/-/issues/17600 and
https://gitlab.kitware.com/cmake/cmake/-/merge_requests/1642, that
CMAKE_DL_LIBS should expand to "dl" on mingw platforms.

The merge request wasn't merged though, as it caused some amount of
breakage, but in practice, Fedora still carries a custom CMake patch
with the same effect.

Thus, this patch fixes cross compiling OpenMP for mingw targets
on Fedora with their custom-patched CMake.

Differential Revision: https://reviews.llvm.org/D130892
2022-08-02 10:56:30 +03:00
Joseph Huber 5afb5312a0 [Libomptarget][NFC] Remove unused CMake file
Summary:
This file is no longer used, get rid of it.
2022-08-01 16:21:53 -04:00
Joseph Huber 51bda3a0e7 [Libomptarget] Replace std::vector with llvm::SmallVector
The runtime makes some use of `std::vector` data structures. We should
be able to replace these trivially with `llvm::SmallVector` instead.
This should allow us to avoid heap allocations in the majority of cases
now.

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D130927
2022-08-01 15:59:15 -04:00
Michał Górny eb4612ca23 [openmp] [test] Fix prepending config.library_dir to LD_LIBRARY_PATH
Fix the LD_LIBRARY_PATH prepending order to make sure that
config.library_path ends up before any potentially-system directories
(e.g. config.hwloc_library_dir).  This makes sure that we are testing
against the just-built openmp libraries rather than the version that is
already installed.

Also rename the function to `prepend_*` to make it clearer what it
actually does.

https://github.com/llvm/llvm-project/issues/56821
Differential Revision: https://reviews.llvm.org/D130825
2022-08-01 18:54:06 +02:00