2672 Commits

Author SHA1 Message Date
Joseph Huber
37def00806 [OpenMP] Update the bug report link for libomp assertion failures
Currently we still print the old https://bugs.llvm.org/ bugzilla link.
We should update this to the issues pane for the LLVM github.

Reviewed By: tlwilmar

Differential Revision: https://reviews.llvm.org/D144426
2023-02-21 09:43:51 -06:00
Joseph Huber
22d618f543 [libomptarget] Remove unused image from global data movement function
This interface function does not actually need the device image type.
It's unused in the function, so it should be able to be safely removed.
The motivation for this is to facilitate downsteam porting of the
amd-stg-open RPC module into the nextgen plugin so we can delete the old
plugin entirely. For that to work we need to be able to call this
function at kernel-launch time, which doesn't have the image. Also it's
cleaner.

Reviewed By: jplehr

Differential Revision: https://reviews.llvm.org/D144436
2023-02-21 07:09:36 -06:00
Joseph Huber
5d560b6966 [Libomptarget] Implement the host memory allocator with fine grained memory
This patch should enable the "Host" allocation using fine-grained
memory. As far as I understand, this is HSA managed memory that is
availible to the host, but can be accessed by the device as well.
The original patch that introduced these extensions just stipulated that
it's "non-migratable" memory, which is most likely true because it's
managed by the host but accessible by the device. This should work
sufficiently well for what we expect the "host" allocation to do.

Depends on D143771

Reviewed By: kevinsala

Differential Revision: https://reviews.llvm.org/D143775
2023-02-20 08:44:09 -06:00
Joseph Huber
5216a9bfb0 [Libmoptarget] Enable the shared allocator for AMDGPU
Currently, the AMDGPU plugin did not support the `TARGET_ALLOC_SHARED`
allocation kind. We used the fine-grained memory allocator for the
"host" alloc when this is most likely not what is intended. Fine-grained
memory can be accessed by all agents, so it should be considered shared.
This patch removes the use of fine-grained memory for the host
allocator. A later patch will add support for this via the
`hsa_amd_memory_lock` method.

Reviewed By: kevinsala

Differential Revision: https://reviews.llvm.org/D143771
2023-02-20 08:44:08 -06:00
Ye Luo
e2069be83e [OpenMP] Make isDone lightweight without calling synchronize
~TaskAsyncInfoWrapperTy() calls isDone. With synchronize inside isDone, we need to handle the error return from synchronize in the destructor.
The consumers of TaskAsyncInfoWrapperTy, targetDataMapper and targetKernel, both call AsyncInfo.synchronize() before exiting.
For this reason in ~TaskAsyncInfoWrapperTy(), calling synchronize() via isDone() is redundant.
This patch removes synchronize() call inside isDone() and makes it a lightweight check.
__tgt_target_nowait_query needs to call synchronize() before checking isDone().

Differential Revision: https://reviews.llvm.org/D144315
2023-02-17 20:45:43 -06:00
Joseph Huber
5172877bbd [Libomptarget] Check errors when synchronizing the async queue
Summary:
Currently when we synchronize the asynchronous queue for the plugins, we
ignore the return value. This is problematic because we will continue on
like nothing happened if the kernel fails.

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

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D144191
2023-02-16 14:56:09 -06:00
Joseph Huber
48c8e16020 Revert "[Libomptarget] Check errors when synchronizing the async queue"
This reverts commit 861709107b43d40ad366e0efd225cb804be3b44d.

Reverting this to reland as it will make it easier to backport.
2023-02-16 14:56:08 -06:00
Joseph Huber
861709107b [Libomptarget] Check errors when synchronizing the async queue
Currently when we synchronize the asynchronous queue for the plugins, we
ignore the return value. This is problematic because we will continue on
like nothing happened if the kernel fails.

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

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D144191
2023-02-16 10:10:21 -06:00
Martin Storsjö
96fcaf0cc0 [openmp] Fix building for mingw targets after import library changes
06d9bf5e64d472db5485815d9c3f70631064bb25 (https://reviews.llvm.org/D143431)
did a large restructuring of how the import library is created;
previously, a second step to tweak the import library was only
done for MSVC style targets, but after this commit, that logic
was applied for mingw targets too.

Since LIBOMP_GENERATED_IMP_LIB_FILENAME and LIBOMP_IMP_LIB_FILE
are equal on mingw targets (both are "libomp.dll.a", while they
are "libomp.dll.lib" and "libomp.lib" for MSVC targets), this caused
a conflict, with errors like this:

  ninja: error: build.ninja:875: multiple rules generate runtime/src/libomp.dll.a [-w dupbuild=err]

Skip the logic with a second step to recreate the import library
for mingw targets. The MSVC specific logic for this relies on
running the static archiver with CMAKE_LINK_DEF_FILE_FLAG, which
with MS lib.exe (and llvm-lib) ignore the input object files and
just generates an import library - but mingw style tools don't
support this mode of operation. (By attemptinig the same, mingw tools
would generate a static library with the def file as one member.)
With mingw tools, the same can be achieved by invoking the dlltool
executable instead.

Instead of adding alternative logic for invoking dlltool, just skip
the second import library step, since neither GNU nor LLVM mingw
tools actually generate import libraries that link by ordinal - so
there's no need for a second import library.

Differential Revision: https://reviews.llvm.org/D143992
2023-02-15 00:30:30 +02:00
Ye Luo
0d4e55ba69 [OpenMP] Recover non-blocking target nowait disabled by D141232
Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D143871
2023-02-14 15:48:38 -06:00
Alexey Bataev
ddde06906b [OpenMP]Fix PR55970: Miscompile of collapse(3) with non-rectangular loop nest.
Need to assign the calculated lower bound back to temp variable,
otherwise incorrect value (upper bound instead of lower bound) might be
used.

Differential Revision: https://reviews.llvm.org/D144015
2023-02-14 10:39:04 -08:00
Vadim Paretsky (Intel Americas Inc)
8c74defcca [OpenMP] Fix extra parenthesis in kmp_os.h
Differential Revision: https://reviews.llvm.org/D143940
2023-02-13 21:43:36 -08:00
Nawrin Sultana
eb0ea28b6a [OpenMP] Add check for target allocator regardless of the availability of libmemkind
Current runtime implementation only checks for target allocator when libmemkind is
not available. This patch adds checks for target allocator regardless of the
presence of libmemkind library.

Differential Revision: https://reviews.llvm.org/D142582
2023-02-13 16:08:22 -06:00
Vadim Paretsky (Intel Americas Inc)
06d9bf5e64 [OpenMP] generate the Windows import library that imports by name rather
than ordinal

This check-in changes the OpenMP build script to generate the Windows
import library that imports by name rather than ordinal to reduce
ordinals order dependency and promote runtime flavors compatibility
going forward. The existing ordinals ordering is preserved to maintain
backward compatibility.

Differential Revision: https://reviews.llvm.org/D143431
2023-02-13 10:30:12 -08:00
Joseph Huber
9f650ae779 [Libomptarget] Remove dependency on the DeviceRTL from the GPU plugins
The GPU plugins have a dependency on the device libraries. Sometimes we
cannot build the device libraries because the user does not have a valid
`clang` to use or it was explicitly disabled. Currently this leads to a
transitive failure because we cannot meet this dependency. This patch
simply removes that dependency.

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

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D143196
2023-02-13 07:01:52 -06:00
Samuel Parker
2a58be4239 [HardwareLoops] NewPM support.
With the NPM, we're now defaulting to preserving LCSSA, so a couple
of tests have changed slightly.

Differential Revision: https://reviews.llvm.org/D140982
2023-02-13 09:46:31 +00:00
Martin Storsjö
89197b59f5 [openmp] Fix building z_Linux_asm.S for armv5t
Don't use the ldrd instruction; that one requires armv5te. Instead
do two separate loads (or only one if OMPT_SUPPORT isn't defined).

This should fix https://github.com/llvm/llvm-project/issues/60370.

Differential Revision: https://reviews.llvm.org/D143683
2023-02-11 00:03:13 +02:00
Terry Wilmarth
8d689e5bfd Fix initialization of th_task_state on each thread on expanding hot teams.
The th_task_state was initialized from the master thread's value, or
from its memo stack, but this causes problems because neither of those
may have the right value at the right time. However, other threads in
the team are guaranteed to have the right values, so we change the
initialize the new threads' th_task_state from the th_task_state of
the last of the older threads in the hot team.

Differential Revision: https://reviews.llvm.org/D142247
Fix #56307.
2023-02-08 17:36:14 -06:00
Jonathan Peyton
4ce32d2f12 [OpenMP][libomp] Remove false positive for memory sanitizer
The memory sanitizer intercepts the memcpy() call but not the direct
assignment of last byte to 0. This leads the sanitizer to believe the
last byte of a string based on the kmp_str_buf_t type is uninitialized.
Hence, the eventual strlen() inside __kmp_env_dump() leads to an
use-of-uninitialized-value warning.

Using strncat() instead gives the sanitizer the information it needs.

Differential Revision: https://reviews.llvm.org/D143401

Fixes #60501
2023-02-07 10:00:34 -06:00
Archibald Elliott
62c7f035b4 [NFC][TargetParser] Remove llvm/ADT/Triple.h
I also ran `git clang-format` to get the headers in the right order for
the new location, which has changed the order of other headers in two
files.
2023-02-07 12:39:46 +00:00
Ron Lieberman
c55d6f169b Revert "[OpenMP][libomp] Remove false positive for memory sanitizer"
breaks amdgpu buildbot

This reverts commit 402981ee25fe135d63226a7de17dbb14c437c71b.
2023-02-06 13:16:37 -06:00
Jonathan Peyton
402981ee25 [OpenMP][libomp] Remove false positive for memory sanitizer
The memory sanitizer intercepts the memcpy() call but not the direct
assignment of last byte to 0. This leads the sanitizer to believe the
last byte of a string based on the kmp_str_buf_t type is uninitialized.
Hence, the eventual strlen() inside __kmp_env_dump() leads to an
use-of-uninitialized-value warning.

Using strncat() instead gives the sanitizer the information it needs.

Differential Revision: https://reviews.llvm.org/D143401

Fixes #60501
2023-02-06 09:30:21 -06:00
Kevin Sala
230d976853 [NFC][OpenMP][libomptarget] Fix format in PluginInterface header 2023-02-06 10:15:50 +01:00
Kevin Sala
6ca034644d [OpenMP][libomptarget] Notify the plugins regarding new mapping/unmappings
The NextGen plugins use the information regarding new mapping/unmappings to
lock/unlock the corresponding host buffer and speed up the host-device memory
transfers involving those buffers. The locking/unlocking is disabled by default
and can be enabled by the LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS envar. The
envar accepts boolean values (on/off) and a special option:
  - off:       Do not lock mapped host buffers (default).
  - on:        Lock mapped host buffers automatically, but do not report lock
               failures if the plugin fails to lock them.
  - mandatory: Lock mapped host buffers automatically and treat locking failures
               in the plugins as fatal errors. This option may be useful for
               debugging purposes.

Differential Revision: https://reviews.llvm.org/D142514
2023-02-06 10:09:35 +01:00
Samuel Thibault
cc72df2b7b [Libomptarget] Add the same to the other AMD plugin
Summary:
The previous patch also needed to apply this to the other AMDGPU plugin,
this will be removed soon but it should be correct while it's here at
least.
2023-02-04 07:46:25 -06:00
Samuel Thibault
71fb11ff34 [Libomptarget] Fix disabling amdgpu on non-Linux.
Previously, on non-Linux, amdgpu would get enabled whatever the CPU architecture.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D143017
2023-02-04 07:45:03 -06:00
Jonathan Peyton
c32022ad26 [OpenMP][libomp] Fix CMake version symbol testing
Do not check for version symbol support if the necessary linker flag is
not supported.

Differential Revision: https://reviews.llvm.org/D143200
2023-02-03 10:52:34 -06:00
Johannes Doerfert
434992c96e [OpenMP][FIX] Do not overalign mapped structures
While we potentially need to align partially mapped structs more than
the first member, we do not need to align past the struct itself. This
prevents us from moving the base pointer past the struct beginning too.

See https://reviews.llvm.org/D142508 for a discussion.

Reviewed By: pavelkopyl, grokos, jhuber6

Differential Revision: https://reviews.llvm.org/D142586
2023-02-03 07:57:16 -06:00
Shilei Tian
2d6adb366e [OpenMP] Guard the code if ITT is not used
`check_loc` is not used if ITT is disabled or debug is off, causing a
compiler warning.

Reviewed By: jlpeyton

Differential Revision: https://reviews.llvm.org/D143004
2023-02-02 22:54:34 -05:00
Joseph Huber
70ff191900 [Libomptarget] Add new enum to the dynamically opened HSA implementation
Summary:
We added a new agent information enum in a previous commit. This was not
added to the dynamic HSA implementation so it failed to compile without
a local HSA install to use.
2023-02-02 15:15:09 -06:00
Joseph Huber
6dd84983d0 [Libomptarget] Improve next-gen AMDGPU plugin error messages
The next-gen plugin properly prints errors. This patch improves the
error messages by including the Node-ID of the GPU that failed as well
as a textual representation of the enumeration values.

Reviewed By: kevinsala

Differential Revision: https://reviews.llvm.org/D143192
2023-02-02 12:55:53 -06:00
Joseph Huber
48560e264c [Libomptarget] Fix the NVPTX Libomptarget test
Summary:
This was broken, we weren't adding these for the NVPTX tests.
2023-02-02 09:46:10 -06:00
Joseph Huber
1bde4ccae6 [Libomptarget] Fix building AMDGPU tests
Summary:
Accidentally deleted this.
2023-01-30 17:56:48 -06:00
Shilei Tian
516ae48170 [OpenMP][NVPTX] Guard the target name macro definition 2023-01-30 14:02:22 -05:00
Joseph Huber
292eca41d9 [Libomptarget] Fix tests after previous patch
Summary:
The previous patch didn't remove these tests correctly.
2023-01-30 07:18:51 -06:00
Joseph Huber
9b1d0ee10c [Libomptarget] Remove unused test targets in libomptaget
Summary:
These don't need to be set.
2023-01-30 06:34:15 -06:00
Shilei Tian
ad95b0e977 [OpenMP][NVPTX] Added __tgt_rtl_launch_kernel in old CUDA plugin
Fix #60248.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D142819
2023-01-28 18:56:07 -05:00
Shilei Tian
544f8c7f39 [OpenMP] Fix stack overflow for test bug54082.c
When `N` is 1024, `int result[N][N]` is obviously large stack that Windows cannot support...

Fix #60326.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D142684
2023-01-26 23:45:11 -05:00
Joachim Protze
488d17154b Re-apply "[OpenMP][Archer] Use dlsym rather than weak symbols for TSan annotations"
Explicitly link libdl this time.

Differential Revision: https://reviews.llvm.org/D142378
2023-01-26 15:32:23 +01:00
Joseph Huber
21b1d55c04 [Libomptarget] Add correct relative path for the nexgen plugin
Summary:
I forgot that this file "borrowed" the source from the other file tree.
Fix that.
2023-01-25 14:05:53 -06:00
Joseph Huber
84d0243d21 [Libomptarget] Clean up CUDA plugin CMake files
Clean up this file after changing it in D142568.

Depends on D142568

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D142573
2023-01-25 13:58:02 -06:00
Joseph Huber
c568622046 [Libomptarget] Remove find_package(CUDA) as it has been deprecated
Since D137724 and the LLVM 17 release we have updated to CMake version
3.20. This means that `find_package(CUDA)` is officially deprecated and
can be replaced with `find_package(CUDAToolkit)` instead. This patch
does this and also cleans up a bit of the CMake.

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D142568
2023-01-25 13:58:01 -06:00
Tom Stellard
603c286334 Bump the trunk major version to 17 2023-01-24 22:57:27 -08:00
Shilei Tian
5ba8ecb6cc [Clang][OpenMP] Find the type omp_allocator_handle_t from identifier table
In Clang, in order to determine the type of `omp_allocator_handle_t`, Clang
checks the type of those predefined allocators. The first one it checks is
`omp_null_allocator`. If the language is C, and the system is 64-bit, what Clang
gets is a `int`, instead of an enum of size 8, given the fact how we define
`omp_allocator_handle_t` in `omp.h`.  If the allocator is captured by a region,
let's say a parallel region, the allocator will be privatized. Because Clang deems
`omp_allocator_handle_t` as an `int`, it will first cast the value returned by
the runtime library (for `libomp` it is a `void *`) to `int`, and then in the
outlined function, it casts back to `omp_allocator_handle_t`. This two casts
completely shaves the first 32-bit of the pointer value returned from `libomp`,
and when the private "new" pointer is fed to another runtime function
`__kmpc_allocate()`, it causes segment fault. That is the root cause of PR54082.
I have no idea why `-fno-pic` could hide this bug.

In this patch, we detect `omp_allocator_handle_t` using roughly the same method
as `omp_event_handle_t`, by looking it up into the identifier table.

Fix #54082.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D142297
2023-01-24 22:49:05 -05:00
Shilei Tian
dafebd5b5a [OpenMP] Create a temp file in /tmp if /dev/shm is not accessible
When `libomp` is initialized, it creates a temp file in `/dev/shm` to store
registration flag. Some systems, like Android, don't have `/dev/shm`, then this
feature is disabled by the macro `KMP_USE_SHM`, though most Linux distributions
have that. However, some customized distribution, such as the one reported in
https://github.com/llvm/llvm-project/issues/53955, doesn't support it either.
It causes a core dump. In this patch, if it is the case, we will try to create a
temporary file in `/tmp`, and if it still doesn't make it, then we error out.
Note that we don't consider in this patch if the temporary directory has been
set to `TMPDIR` in this patch. If `/tmp` is not accessible, we error out.

Fix #53955.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D142175
2023-01-24 21:45:38 -05:00
Kevin Sala
2a539ee17d [OpenMP][libomptarget] Implement memory lock/unlock API in NextGen plugins
This patch implements the memory lock/unlock API, introduced in patch https://reviews.llvm.org/D139208,
in the NextGen plugins. Locked buffers feature reference counting and we allow certain overlapping. Given
an already locked buffer A, other buffers that are fully contained inside A can be locked again, even if
they are smaller than A. In this case, the reference count of locked buffer A will be incremented. However,
extending an existing locked buffer is not allowed. The original buffer is actually unlocked once all its
users have released the locked buffer and sub-buffers (i.e., the reference counter becomes zero).

Differential Revision: https://reviews.llvm.org/D141227
2023-01-25 00:11:38 +01:00
Joseph Huber
5d1dc9fa04 [OpenMP] Do not link the bitcode OpenMP runtime when targeting AMDGPU.
The AMDGPU target can only emit LLVM-IR, so we can always rely on LTO to
link the static version of the runtime optimally. Using the static
library only has a few advantages. Namely, it avoids several known bugs
and allows us to optimize out more functions. This is legal since the
changes in D142486 and D142484

Depends on D142486 D142484

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D142491
2023-01-24 17:01:37 -06:00
Giorgis Georgakoudis
4b88bf5c70 [OpenMP][docs] Update for record-and-replay
Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D142492
2023-01-24 14:36:37 -08:00
Shilei Tian
7e89420116 [OpenMP] Disable tests that are not supported by GCC if it is used for testing
GCC doesn't support `-fopenmp-version`, causing test failure if the compiler used
for testing is GCC.

GCC's OpenMP 5.2 support is very limited yet. Disable those tests requiring 5.2
feature for GCC as well.

We might want to take a look at all `libomp` tests and mark those tests that
don't support GCC yet.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D142173
2023-01-24 17:00:15 -05:00
Johannes Doerfert
62bc222875 [OpenMP][NFC] Augment release notes 2023-01-24 13:23:15 -08:00