Commit Graph

2243 Commits

Author SHA1 Message Date
Joel E. Denny 48ca3a5ebb [OpenMP] Extend omp teams to permit nested omp atomic
OpenMP 5.2, sec. 10.2 "teams Construct", p. 232, L9-12 restricts what
regions can be strictly nested within a `teams` construct.  This patch
relaxes Clang's enforcement of this restriction in the case of nested
`atomic` constructs unless `-fno-openmp-extensions` is specified.
Cases like the following then seem to work fine with no additional
implementation changes:

```
 #pragma omp target teams map(tofrom:x)
 #pragma omp atomic update
 x++;
```

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D126323
2022-05-26 14:59:16 -04:00
Joseph Huber 20ec4161d7 [Libomptarget] Add branch prediction intrinsic to state check
Summary:
We usually used the `OMP_LIKELY` and `OMP_UNLIKELY` macros to add branch
prediction intrinsics to help the optimizer ignore unlikely loops. This
wasn't applied to this one loop so add that in.
2022-05-20 15:38:54 -04:00
Jonathan Peyton f613e6d19d [OpenMP][libomp] Fix accidental removal of else for core attributes 2022-05-19 14:00:27 -05:00
Joseph Huber eda4ef3add [Libomptarget] Add `leaf` attribute to `vprintf` declaration
Summary:
This patch adds the `leaf` attribute to the `vprintf` declaration in the
OpenMP runtime. This attribute allows us to determine that the `vprintf`
function will not call any functions within the translation unit,
allowing us to deduce `norecurse` attributes on the caller.
2022-05-19 14:22:53 -04:00
AndreyChurbanov c44ba01de7 [OpenMP] libomp: honor passive wait policy requested with tasking
Currently the library ignores requested wait policy in the presence
of tasking. Threads always actively spin. The patch fixes this problem
making the wait policy passive if this explicitly requested by user.

Differential Revision: https://reviews.llvm.org/D123044
2022-05-18 10:04:30 -05:00
Joseph Huber 5ffecd28c9 [Libomptarget] Don't build the device runtime without a new Clang
The OpenMP device offloading library is a bitcode library and thus only
expect to build and linked with the same version of clang that was used
to create it. This somewhat copmlicates the building process as we
require the Clang that was just built to be used to create the library.
This is either done with a two-step build, where OpenMP is built with
the Clang that was just installed, or through the
`-DLLLVM_ENABLE_RUNTIMES=openmp` option. This has always been the case,
but recent changes have caused this to make it difficult to build the
rest of OpenMP. This patchs adds a check to not build the OpenMP device
runtime if the current compiler is not Clang with the same version as
the LLVM installation. This should allow users to build OpenMP as a
project using any compiler without it erroring out due to the bitcode
library, but if users require it they will need to use the above methods
to compile it.

Reviewed By: jdoerfert, tianshilei1992, ye-luo

Differential Revision: https://reviews.llvm.org/D125698
2022-05-16 18:18:32 -04:00
Joseph Huber 54e02179b3 [Libomptarget] Build the static library without CUDA installed
Summary:
This patch allows users to compile the static library without CUDA
installed on the system. This requires the new flag `--cuda-feature` to
indicate that we need `+ptx61` in order to compile the runtime.
2022-05-13 16:30:58 -04:00
Joseph Huber 16b7a0b43b [Libomptarget] Build the device runtime as a static library
This patch adds the necessary CMake configuration to build a static
library version of the device runtime, `libomptarget.devicertl.a`.
Various improvements in how we handle static libraries and generating
offloading code should allow us to treat the device library as a regular
project without needing to invoke the clang front-end directly. Here we
generate a job for each offloading architecture supported. Each
offloading architecture will be embedded into the static library and
used as-needed by the host.

This library will primarily be used to replace the bitcode library when
performing LTO. Currently, we need to manually pass in the bitcode
library which requires foreknowledge of the offloading architecture.
This approach lets us handle that in the linker wrapper instead.
Furthermore this should improve our interface to the device runtime. We
can now build it fully under a release build and have all the expected
entry points, as well as supporting debug builds.

Depends on D125265 D125256 D125260 D125314 D125563

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D125315
2022-05-13 14:38:51 -04:00
Joseph Huber 9ffa945c40 [Libomptarget] Remove global include directory from libomptarget
We used to globally include the libomptarget include directory for all
projects. This caused some conflicts with the other files named
"Debug.h". This patch changes the cmake to include these files via the
target include instead.

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D125563
2022-05-13 14:38:47 -04:00
Joseph Huber ce0caf41bd [Libomptarget] Address existing warnings in the device runtime library
This patche attemps to address the current warnings in the OpenMP
offloading device runtime. Previously we did not see these because we
compiled the runtime without the standard warning flags enabled.
However, these warnings are used when we now build the static library
version of this runtime. This became extremely noisy when coupled with
the fact the we compile each file roughly 32 times when all the
architectures are considered. So it would be ideal to not have all these
warnings show up when building.

Most of these errors were simply implicit switch-case fallthroughs,
which can be addressed using C++17's fallthrough attribute. Additionally
there was a volatile variable that was being casted away. This is most
likely safe to remove because we cast it away before its even used and
didn't seem to affect anything in testing.

Depends on D125260

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D125339
2022-05-13 14:38:31 -04:00
Joseph Huber b4f8443d97 [Libomptarget] Allow the device runtime to be compiled for the host
Currently the OpenMP offloading device runtime is only expected to be
compiled for the specific architecture it's targeting. This is
problematic if we want to make compiling the device runtime more general
via the standar `clang` driver rather than invoking the clang front-end
directly. This patch addresses this by primarily changing the declare
type to `nohost` so the host will not contain any of this code.
Additionally we forward declare the functions that are defined via
variants, otherwise these would cause problems on the host.

Reviewed By: jdoerfert, tianshilei1992

Differential Revision: https://reviews.llvm.org/D125260
2022-05-13 14:38:27 -04:00
serge-sans-paille 40d3a0ba4d [openmp] Fix strict aliasing issue in cmpxchg routine
Avoid warning under -fstrict-aliasing by using a call to memcpy to perform type
punning.

Differential Revision: https://reviews.llvm.org/D125467
2022-05-12 16:14:48 +02:00
AndreyChurbanov 52d0ef3c00 [OpenMP] libomp: Add itt notifications to sync dependent tasks.
Intel Inspector uses itt notifications to analyze code execution, and it
reports race conditions in dependent tasks.
This patch fixes the issue notifying Inspector on tasks dependency
synchronizations.

Differential Revision: https://reviews.llvm.org/D123042
2022-05-05 11:30:59 -05:00
AndreyChurbanov 4a64bed216 [OpenMP] libomp: cleanup - remove duplicate check
The identical check remains 20 lines above in the code.

Differential Revision: https://reviews.llvm.org/D123046
2022-05-05 11:01:20 -05:00
AndreyChurbanov eed0d85152 [OpenMP] libomp: cleanup dead code
Differential Revision: https://reviews.llvm.org/D123047
2022-05-05 10:56:49 -05:00
Hansang Bae 7e23b46ab8 [OpenMP] Possible fix for sporadic test failure from loop_dispatch.c
This patch tries to fix sporadic test failure after the change
https://reviews.llvm.org/D122107.
Made the test wait until every thread has at least one loop iteration.

Differential Revision: https://reviews.llvm.org/D124812
2022-05-03 14:46:32 -05:00
Joseph Huber 5ad07ac400 [Libomptarget] Use entry name for global info
Currently, globals on the device will have an infinite reference count
and an unknown name when using `LIBOMPTARGET_INFO` to print the mapping
table. We already store the name of the global in the offloading entry
so we should be able to use it, although there will be no source
location. To do this we need to create a valid `ident_t` string from a
name only.

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D124381
2022-04-25 09:56:43 -04:00
Ye Luo 8a880db519 [libomptarget] Make omp_target_is_present checks storage instead of zero length array.
Consider checking whether a pointer has been mapped can be achieved via omp_get_mapped_ptr.
omp_target_is_present is more needed to check whether the storage being pointed is mapped.
This restore the old behavior of omp_target_is_present before D123093
Fixes https://github.com/llvm/llvm-project/issues/54899

Reviewed By: jdenny

Differential Revision: https://reviews.llvm.org/D123891
2022-04-22 17:37:06 -05:00
Ye Luo 91ccd8248c [Clang][OpenMP] libompd: get libomp hwloc includedir by target_link_libraries
When hwloc is used and is installed outside of the default paths, the omp CMake target
needs to provide the needed include path thru the CMake target by adding it with
target_include_directories to it, so libompd gets it as well when it defines it's cmake
target using target_link_libraries.

As suggested in D122667

Reviewed By: ye-luo

Differential Revision: https://reviews.llvm.org/D123888
2022-04-22 17:33:41 -05:00
Joseph Huber f557bb8733 [OpenMP][Docs] Remove usage of deprecated flag in documentation
Summary:
This documentation used the `-fopenmp-target-new-runtime` flag which is
deprecated and has no effect. Remove it.
2022-04-21 18:50:25 -04:00
Atmn Patel c44420e90d [Libomptarget][remote] Add OpenMP linker flag to the plugin
The remote offloading server and plugin rely on OpenMP, so this needs to be added as a linker flag. Without this, applications segfault.

Differential Revision: https://reviews.llvm.org/D124200
2022-04-21 15:45:29 -04:00
Atmn Patel 489894f363 [Libomptarget][remote] Fix compile-time error
This fixes a compile-time error recently introduced within the remote
offloading plugin. This patch also removes some extra linker flags that are unnecessary, and adds an explicit abseil linker flag without which we occasionally get problems.

Differential Revision: https://reviews.llvm.org/D119984
2022-04-19 16:46:01 -04:00
Joseph Huber 80787213ea [Libomptarget] Fix test using old unsupported lit string
Summary:
One test had an old "unsupported" string that used the old `newDriver`
string which was removed. This test should be updated to use the
`oldDriver` one instead.
2022-04-18 23:08:12 -04:00
Joseph Huber ae23be84cb [OpenMP] Make the new offloading driver the default
Previously an opt-in flag `-fopenmp-new-driver` was used to enable the
new offloading driver. After passing tests for a few months it should be
sufficiently mature to flip the switch and make it the default. The new
offloading driver is now enabled if there is OpenMP and OpenMP
offloading present and the new `-fno-openmp-new-driver` is not present.

The new offloading driver has three main benefits over the old method:
- Static library support
- Device-side LTO
- Unified clang driver stages

Depends on D122683

Differential Revision: https://reviews.llvm.org/D122831
2022-04-18 15:05:09 -04:00
Joseph Huber ba01306009 [Libomptarget] Fix LIBOMPTARGET_INFO test
Summary:
A patch added a new line to one of the info outputs without updating
this test. This patch adds the new text to the existing test.
2022-04-18 14:09:02 -04:00
Dhruva Chakrabarti 7086a1db80 [libomptarget] [amdgpu] Hostcall offset check should consider implicit args
Fixed hostcall offset check to compare against kernarg segment size
and implicit arguments. Improved the corresponding debug print.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D123827
2022-04-15 00:53:47 +00:00
Saiyedul Islam 54a6cc3405
[libomptarget][amdgpu] Add hidden_heap_v1 kernarg metadata
Code object version 5 adds support of hidden_heap_v1 kernarg
metadata field [1]. It is a global address space pointer to an
initialized memory buffer that conforms to the requirements of the
malloc/free device library V1 version implementation.

[1] https://llvm.org/docs/AMDGPUUsage.html#amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v5

Reviewed By: carlo.bertolli

Differential Revision: https://reviews.llvm.org/D123527
2022-04-13 03:57:29 +00:00
Johannes Doerfert a3a42c3ca2 [OpenMP][FIX] Ensure to set the context for wait events if necessary
Differential Revision: https://reviews.llvm.org/D123445
2022-04-12 16:42:50 -05:00
Jonathan Peyton d49ce7c356 [OpenMP][libomp] Replace global variable references with local object
Remove references to global __kmp_topology within a kmp_topology_t
object method. There should just be implicit references to the
private object.
2022-04-12 12:50:41 -05:00
Jonathan Peyton 747a490612 [OpenMP][libomp] Fix some Doxygen issues
Fix spelling of variable names and remove accidental references (#)
in Doxygen comments.
2022-04-12 11:05:30 -05:00
Joseph Huber 2e0cb61570 [OpenMP] Fix linker error when building info tool
Summary:
The changes made in D123177 added new targets to the
`LIBOMPTARGET_TESTED_PLUGINS` variable which was linked against when
building the `llvm-omp-target-info` tool. This caused linker errors on
the export scripts. This patch removes that dependency, it still builds
and runs as expected so I will assume it's correct.
2022-04-08 10:50:31 -04:00
Ye Luo c1a6fe196d [libomptarget] Implement pointer lookup as 5.1 spec.
As described in 5.1 spec
2.21.7.2 Pointer Initialization for Device Data Environments

Reviewed By: RaviNarayanaswamy

Differential Revision: https://reviews.llvm.org/D123093
2022-04-07 23:01:25 -05:00
Joseph Huber a3f423cf57 [OpenMP] Add dynamic memory function to omp.h and add documentation
This patch adds the `llvm_omp_target_dynamic_shared_alloc` function to
the `omp.h` header file so users can access it by default. Also changed
the name to keep it consistent with the other target allocators. Added
some documentation so users know how to use it. Didn't add the interface
for Fortran since there's no way to test it right now.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D123246
2022-04-07 14:23:23 -04:00
Joseph Huber 840c040498 [OpenMP] Change target memory tests to use allocators
The target allocators have been supported for NVPTX offloading for
awhile. The tests should use the allocators instead of calling the
functions manually. Also the comments indicating these being a preview
should be removed.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D123242
2022-04-07 14:23:14 -04:00
Michael Kruse 7fa7b0cbd8 [libomptarget] Add device RTL to regression test dependencies.
In a clean build directory, `check-openmp` or `check-libomptarget` will fail because of missing device RTL .bc files. Ensure that the new targets new custom targets `omptarget.devicertl.nvptx` and `omptarget.devicertl.amdgpu` (corresponding to the plugin rtl targets `omptarget.rtl.cuda`, respectively `omptarget.rlt.amdgpu` ) are dependencies of the regression tests.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D123177
2022-04-06 20:01:47 -05:00
Hansang Bae 090309d316 [OpenMP] Fix warnings
Silenced compiler warnings after pushing the following change.
https://reviews.llvm.org/D122107

Differential Revision: https://reviews.llvm.org/D123233
2022-04-06 12:35:05 -05:00
Hansang Bae e4ac11beb7 [OpenMP] Add support for ompt_callback_dispatch
This change adds support for ompt_callback_dispatch with the new
dispatch chunk type introduced in 5.2. Definitions of the new
ompt_work_loop types were also added in the header file.

Differential Revision: https://reviews.llvm.org/D122107
2022-04-06 08:01:02 -05:00
Jonathan Peyton d345fe7c22 [OpenMP][libomp] NFC: Move omp_* functions out of kmp_* section 2022-03-31 13:39:30 -05:00
Joachim Protze 7641e42def [OpenMP][Tools] Fix handling of initial-task-end
Latest OpenMP spec says parallel_data is NULL for initial/implicit-task-end.
We nevertheless need to cleanup the ParallelData here, as there is no other
callback for the end of the implicit parallel region. We can use the reference
stored in the TaskData.

Reviewed By: dreachem

Differential Revision: https://reviews.llvm.org/D114005
2022-03-31 12:33:40 -05:00
Ron Lieberman 95eac47260 [libomptarget] x86 offloading fails map_back_race.cpp intermittently
Differential Revision: https://reviews.llvm.org/D122658
2022-03-29 16:01:17 +00:00
Johannes Doerfert b803f06901 [OpenMP] The test does not have check lines 2022-03-29 00:02:55 -05:00
Johannes Doerfert b309bdb970 [OpenMP][FIX] Use clang++ for the C++ test case 2022-03-28 23:14:24 -05:00
Johannes Doerfert b316126887 [OpenMP][FIX] Avoid races in the handling of to be deleted mapping entries
If we decided to delete a mapping entry we did not act on it right away
but first issued and waited for memory copies. In the meantime some
other thread might reuse the entry. While there was some logic to avoid
colliding on the actual "deletion" part, there were two races happening:

1) The data transfer back of the thread deleting the entry and
   the data transfer back of the thread taking over the entry raced.
2) The update to the shadow map happened regardless if the entry was
   actually reused by another thread which left the shadow map in a
   inconsistent state.

To fix both issues we will now update the shadow map and delete the
entry only if we are sure the thread is responsible for deletion, hence
no other thread took over the entry and reused it. We also wait for a
potential former data transfer from the device to finish before we issue
another one that would race with it.

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

Differential Revision: https://reviews.llvm.org/D121058
2022-03-28 22:33:18 -05:00
Johannes Doerfert ba93e4e33e [OpenMP][NFC] Add missing virtual destructor to silence warning 2022-03-28 22:33:18 -05:00
Johannes Doerfert 7df2eba7fa [Attributor][OpenMP] Add assumption for non-call assembly instructions
Inline assembly is scary but we need to support it for the OpenMP GPU
device runtime. The new assumption expresses the fact that it may not
have call semantics, that is, it will not call another function but
simply perform an operation or side-effect. This is important for
reachability in the presence of inline assembly.

Differential Revision: https://reviews.llvm.org/D109986
2022-03-28 20:57:52 -05:00
Shilei Tian 545fcc3d84 [OpenMP][CUDA] Fix potential program crash caused by double free resources
As we mentioned in the code comments for function `ResourcePoolTy::release`,
at some point there could be two identical resources on the two sides of `Next`
mark. It is usually not an issue, unless the following case:
1. Some resources are not returned.
2. We need to iterate the pool and free the element.

That will cause double free, which is the case for event pool. Since we don't release
events hold by the data map, it can happen that the `Next` mark is not reset, and
we have two identical items in the pool. When the pool is destroyed, we will call
`cuEventDestroy` twice on the same event. In the best case, we can only observe
CUDA errors. In the worst case, it can cause internal failures in CUDART and further
crash.

This patch fixes the issue by tracking all resources that have been given using
an `unordered_set`. We don't remove it when a resource is returned. When the pool
is destroyed, we merge the pool (a `vector`) and the set. In this way, we can make
sure that the set contains all resources allocated from the device. We just need
to iterate the set and free the resource accordingly.

For now, only event pool is set to use it. Stream pool is not because we can make
sure all streams are returned when the plugin is destroyed.

Someone might be wondering, why don't we release all events hold in the data map.
That is because, plugins are determined to be destroyed *before* `libomptarget`.
If we can somehow make the plugin outlast `libomptarget`, life will be much
easier.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D122014
2022-03-25 22:49:32 -04:00
Joseph Huber 9d3550c517 [OpenMP] Add AMDGPU calling convention to ctor / dtor functions
This patch adds the necessary AMDGPU calling convention to the ctor /
dtor kernels. These are fundamentally device kenels called by the host
on image load. Without this calling convention information the AMDGPU
plugin is unable to identify them.

Depends on D122504

Fixes #54091

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D122515
2022-03-25 22:44:20 -04:00
Johannes Doerfert 6c2be885ff Revert "[OpenMP][NFC] Add missing virtual destructor to silence warning"
This reverts commit b9fd8f34ae as it
accidentally contained a unit test change that is not finished (and
unrelated).
2022-03-25 16:07:11 -05:00
Johannes Doerfert 7dfad948f1 [OpenMP][FIX] Repair ExclusiveAccess move semantic snafu 2022-03-25 16:00:53 -05:00
Johannes Doerfert b9fd8f34ae [OpenMP][NFC] Add missing virtual destructor to silence warning 2022-03-25 16:00:53 -05:00