Commit Graph

3182 Commits

Author SHA1 Message Date
Ethan Luis McDonough
813a671232 [OpenMP] Remove unnecessary dependencies from plugin unit tests (#76266)
This was an oversight that seems to be causing problems on certain
builds. This patch should fix #76225.
2023-12-22 14:44:23 -06:00
Felipe Cabarcas
9b6ea5e8f8 [OpenMP] Improve omp offload profiler (#68016)
Summary:
Adding information to the LIBOMPTARGET profiler runtime kernel and API
calls.

Key changes:
* Adding information to runtime calls for better understanding of how
the application
is executing. For example teams requested by the user, size of memory
transfers.
* Profile timer was changed from 'us' to 'ns', since 'us' was too
coarse-grain
  to register some important details like key kernel duration
* Removed non API or Runtime calls, to reduce complexity of profile for
application
  developers.

---------

Co-authored-by: Felipe Cabarcas <cabarcas@leia.crpl.cis.udel.edu>
Co-authored-by: fel-cab <fel-cab@github.com>
2023-12-22 14:58:11 -05:00
Fabian Mora
12250c4092 Reland [OpenMP][Fix] libomptarget Fortran tests (#76189)
This patch fixes the erroneous multiple-target requirement in Fortran
offloading tests. Additionally, it adds two new variables
(test_flags_clang, test_flags_flang) to lit.cfg so that
compiler-specific flags for Clang and Flang can be specified.

This patch re-lands: #74543. The error was caused by having:
```
config.substitutions.append(("%flags", config.test_flags))
config.substitutions.append(("%flags_clang", config.test_flags_clang))
config.substitutions.append(("%flags_flang", config.test_flags_flang))
```
when instead it has to be:
```
config.substitutions.append(("%flags_clang", config.test_flags_clang))
config.substitutions.append(("%flags_flang", config.test_flags_flang))
config.substitutions.append(("%flags", config.test_flags))
```
because LIT replaces with the first longest sub-string match.
2023-12-21 14:18:36 -08:00
Ethan Luis McDonough
cb3a893436 [OpenMP] Check for gtest when building libomptarget unit tests (#76141)
This patch addresses an issue introduced in pull request #74398. CMake
will attempt to re-build gtest if openmp is enabled as a project (as
opposed to being enabled as a runtime). This patch adds a check that
prevents this from happening.
2023-12-21 04:00:35 -06:00
Joseph Huber
ba192debb4 [Libomptarget][Obvious] Fix typo in attribute lookup
Summary:
These are keys into the AMDGPU target metadata. One of them had a typo
which prevented it from being extracted.
2023-12-20 19:03:35 -06:00
Joseph Huber
f324584ae3 [Libomptarget][NFCI] Remove caching of created ELF files (#76080)
Summary:
We currently keep a cache of created ELF files from the relevant images.
This shouldn't be necessary as the entire ELF interface is generally
trivially constructable and extremely cheap. The cost of constructing
one of these objects is simply a size check and writing a pointer to the
underlying data. Given that, keeping a cache of these images should not
be necessary overall.
2023-12-20 17:13:41 -06:00
Shilei Tian
7e4c6f6cb2 [OpenMP] Reduce the size of heap memory required by the test malloc_parallel.c (#75885)
This patch reduces the size of heap memory required by the test
`malloc_parallel.c` and `malloc.c`. The original size is too large such
that `malloc` returns `nullptr` on many threads, causing illegal
memory access.
2023-12-20 15:03:01 -08:00
Ethan Luis McDonough
3c10e5b2f6 [OpenMP] Add unit tests for nextgen plugins (#74398)
This patch add three GTest unit tests that test plugin read and write
operations. Tests can be compiled with `ninja -C runtimes/runtimes-bins
LibomptUnitTests`.
2023-12-20 14:58:56 -08:00
Joseph Huber
e4f4022b70 [Libomptarget][NFC] Fix linting warnings in the plugins
Summary:
Fix some linting warnings present in the plugins.
2023-12-20 10:07:34 -06:00
Joseph Huber
ac029e02a9 [Libomptarget] Remove __tgt_image_info and use the ELF directly (#75720)
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-19 20:01:31 -06:00
Joseph Huber
219355d4c0 [Libomptarget] Use scoped atomics in the device runtime (#75834)
Summary:
A recent patch allowed us to easily replace GNU atomics with scoped
variants that make use of the backend's handling for more permissive
scopes. The default is full "system" scope, that means the atomic
operation must be consistent with operations that may happen on the
host's memory. This is generally only required for processes that are
communicating with something via global fine-grained memory. This patch
uses these atomics to make everything device scoped, as nothing in the
OpenMP runtime should depend on the host.

This is only provided as a very new clang extension but the DeviceRTL is
only compiled with clang so it is always available.
2023-12-19 14:30:34 -06:00
Carlos Eduardo Seo
dcd7c8b7c9 [OpenMP][AArch64] Workaround for ompt/synchronization tests (#75848)
ompt/synchronization/[masked.c | master.c] tests fail due to a wrong
offset being calculated for the possible return addreses. PR #65936
fixes this for Darwin and the same has to be done for Linux.

Updates #69627
2023-12-19 19:26:23 +01:00
Fabian Mora
ac82c8b925 Revert "[OpenMP][Fix] libomptarget Fortran tests" (#75953)
Reverts llvm/llvm-project#74543
2023-12-19 12:11:08 -05:00
Gheorghe-Teodor Bercea
65909177e3 [OpenMP][libomptarget][Fix] Disable test on NVIDIA platforms (#75949)
The tests doesn't seem to work for NVIDIA so disabling it for now.
2023-12-19 11:58:10 -05:00
Fabian Mora
49efb082cc [OpenMP][Fix] libomptarget Fortran tests (#74543)
This patch fixes the erroneous multiple-target requirement in Fortran
offloading tests. Additionally, it adds two new variables
(`test_flags_clang`, `test_flags_flang`) to `lit.cfg` so that
compiler-specific flags for Clang and Flang can be specified.
2023-12-19 11:35:14 -05:00
Shilei Tian
3768039913 [OpenMP] Directly use user's grid and block size in kernel language mode (#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 12:26:18 -05:00
Joseph Huber
913622d012 [Libomptarget] Remove remaining global constructors in plugins (#75814)
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-18 11:01:02 -06:00
Joseph Huber
1580877555 [Libomptarget] Remove bitcode image map used for JIT processing (#75672)
Summary:
Libomptarget supports JIT by treating an LLVM-IR file as a regular input
image. The handling here used a global map to keep track of triples once
it was parsed. This was done to same time, however this created a global
constructor as well as an extra mutex to handle it. This patch removes
the use of this map.

Instead, we simply use the file magic to perform a quick check if the
input image is valid bitcode. If not, we then create a lazy module. This
should roughly equivalent to the old handling that create an IR symbol
table. Here we can prevent the module from materializing everything but
the single triple metadata we read in later.
2023-12-18 09:28:06 -06:00
Gheorghe-Teodor Bercea
cd1038a46a [OpenMP][libomptarget][Fix]Require presence of libomptarget-debug for newly added test (#75807)
Require presence of libomptarget-debug fixes https://github.com/llvm/llvm-project/pull/75642
2023-12-18 10:07:52 -05:00
Gheorghe-Teodor Bercea
4ef6587715 [Clang][OpenMP] Fix mapping of structs to device (#75642)
Fix mapping of structs to device.

The following example fails:

```
#include <stdio.h>
#include <stdlib.h>

struct Descriptor {
  int *datum;
  long int x;
  int xi;
  long int arr[1][30];
};

int main() {
  Descriptor dat = Descriptor();
  dat.datum = (int *)malloc(sizeof(int)*10);
  dat.xi = 3;
  dat.arr[0][0] = 1;

  #pragma omp target enter data map(to: dat.datum[:10]) map(to: dat)

  #pragma omp target
  {
    dat.xi = 4;
    dat.datum[dat.arr[0][0]] = dat.xi;
  }

  #pragma omp target exit data map(from: dat)

 return 0;
}
```

This is a rework of the previous attempt:
https://github.com/llvm/llvm-project/pull/72410
2023-12-18 09:47:59 -05:00
Kazu Hirata
b8f89b84bc Use StringRef::{starts,ends}_with (NFC)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-16 15:02:17 -08:00
Shilei Tian
a4d1d5f5b5 [OpenMP] Use simple VLA implementation to replace uses of actual VLA
Use of VLA can cause compile warning that was introduced in D156565. This patch
implements a simple stack/heap-based VLA that can miminc the behavior of an
actual VLA and prevent the warning. By default the stack accomodates the
elements. If the number of emelements is greater than N, which by default is 8,
a heap buffer will be allocated and used to acccomodate the elements.
2023-12-15 15:12:33 -05:00
dhruvachak
e4de6a602f [OpenMP] [OMPT] A pointer to HostOpId should be passed in EMI callbacks. (#75574)
With this change, TargetRegionOpId is no more used and hence deleted.
2023-12-15 12:07:42 -08:00
Shilei Tian
54b54d63ca [OpenMP] Fix compile error caused by #74397 (#75419)
This patch fixed the following compile error caused by #74397.

```
openmp/libomptarget/src/PluginManager.cpp: In static member function ‘static llvm::Expected<std::unique_ptr<PluginAdaptorTy> >
PluginAdaptorTy::create(const string&)’:
openmp/libomptarget/src/PluginManager.cpp:50:10: error: could not convert ‘PluginAdaptor’ from ‘std::unique_ptr<PluginAdaptorTy
>’ to ‘llvm::Expected<std::unique_ptr<PluginAdaptorTy> >’
   return PluginAdaptor;                                                                                                                                                                    ^~~~~~~~~~~~~
```
2023-12-15 08:15:52 -05:00
Andrew Brown
68ea91dd8b [openmp][wasm] Allow compiling OpenMP to WebAssembly (#71297)
This change allows building the static OpenMP runtime, `libomp.a`, as
WebAssembly. It builds on the work done in [D142593] but goes further in
several ways:
 - it makes the OpenMP CMake files more WebAssembly-aware
- it conditions much more code (or code that had been refactored since
[D142593]) for `KMP_ARCH_WASM` and `KMP_OS_WASI`
- it fixes a Clang crash due to unimplemented common symbols in
WebAssembly

The commit messages have more details. Please understand this PR as a
start, not the completed work, for WebAssembly support in OpenMP.
Getting the tests running somehow would be a good next step, e.g.; but
what is contained here works, at least with recent versions of
[wasi-sdk] and engines that support [wasi-threads]. I suspect the same
is true for Emscripten and browsers, but I have not tested that
workflow.

[D142593]: https://reviews.llvm.org/D142593
[wasi-sdk]: https://github.com/WebAssembly/wasi-sdk
[wasi-threads]: https://github.com/WebAssembly/wasi-threads

---------

Co-authored-by: Atanas Atanasov <atanas.atanasov@intel.com>
2023-12-14 13:48:01 -06:00
Joseph Huber
0ab663d202 [Libomptarget] Move ELF symbol extraction to the ELF utility (#74717)
Summary:
We shouldn't have the format specific ELF handling in the generic plugin
manager. This patch moves that out of the implementation and into the
ELF utilities. This patch changes the SHT_NOBITS case to be a hard
error, which should be correct as the existing use already seemed to
return an error if the result was a null pointer.

This also uses a `const_cast`, which is bad practice. However,
rebuilding the `constness` of all of this would be a massive overhaul,
and this matches the previous behaviour (We would take a pointer to the
image that is most likely read-only in the ELF).
2023-12-14 11:04:13 -06:00
Johannes Doerfert
fe6f137e48 [OpenMP][NFC] Move mapping related code into OpenMP/Mapping.cpp (#75239)
DeviceTy provides an abstraction for "middle-level" operations that can
be done with a offload device. Mapping was tied into it but is not
strictly necessary. Other languages do not track mapping, and even
OpenMP can be used completely without mapping. This simply moves the
relevant code into the OpenMP/Mapping.cpp as part of a new class
MappingInfoTy. Each device still has one, but it does not clutter the
device.cpp anymore.
2023-12-12 12:49:46 -08:00
Johannes Doerfert
5dd1fc7008 [OpenMP][NFC] Improve profiling for the offload runtime 2023-12-11 17:30:35 -08:00
Johannes Doerfert
2ada7bb68b [OpenMP][NFCI] Remove effectively unused mutex
The only use was already guarded by a different lock in the caller of
loadBinary.
2023-12-11 17:30:35 -08:00
Johannes Doerfert
f0ccaeecd2 [OpenMP][NFC] Move rtl.cpp to OffloadRTL.cpp 2023-12-11 17:30:35 -08:00
Johannes Doerfert
cee6918d87 [OpenMP][NFC] Move api.cpp to OpenMP/API.cpp 2023-12-11 17:30:34 -08:00
Johannes Doerfert
12cbccc312 [OpenMP] Add extra flags to libomptarget and plugin builds (#74520) 2023-12-11 10:41:50 -08:00
Brad Smith
8b5af3139c [OpenMP] Change check for OS to check for defined for a macro (#75012)
Check for the existence of the macro instead of checking for Solaris.
illumos has this macro in sys/time.h.

/export/home/brad/llvm-brad/openmp/runtime/src/z_Linux_util.cpp:77:9: warning: 'TIMEVAL_TO_TIMESPEC' macro redefined [-Wmacro-redefined]
   77 | #define TIMEVAL_TO_TIMESPEC(tv, ts)                                            \
      |         ^
/usr/include/sys/time.h:424:9: note: previous definition is here
  424 | #define TIMEVAL_TO_TIMESPEC(tv, ts) { \
      |         ^
2023-12-11 09:54:24 -05:00
Gheorghe-Teodor Bercea
5fc76e6b6d [OpenMP][Fix] Fix test initialization (#74801)
Fix test initialization
2023-12-07 22:20:32 -05:00
Gheorghe-Teodor Bercea
1216a31cae Revert "[OpenMP][Fix] Fix test array initialization. (#74799)" (#74800)
This reverts commit d413681344.
2023-12-07 22:14:12 -05:00
Gheorghe-Teodor Bercea
d413681344 [OpenMP][Fix] Fix test array initialization. (#74799)
Fix test array initialization.
2023-12-07 22:09:08 -05:00
jyu2-git
8e8bff3397 Fix test. (#74745)
Just add
// REQUIRES: libomptarget-debug

So that test will not run with release compiler.
2023-12-07 10:45:59 -08:00
jyu2-git
0113722d82 [OpenMP] Fix runtime problem due to wrong map size. (#74692)
Currently we are missing set up-boundary address for FinalArraySection
as highests elements in partial struct data.

Currently for:
\#pragma omp target map(D.a) map(D.b[:2])
The size is:
  %a = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 0
  %b = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 1
  %arrayidx = getelementptr inbounds [2 x float], ptr %b, i64 0, i64 0
  %2 = getelementptr float, ptr %arrayidx, i32 1
  %3 = ptrtoint ptr %2 to i64
  %4 = ptrtoint ptr %a to i64
  %5 = sub i64 %3, %4
%6 = sdiv exact i64 %5, ptrtoint (ptr getelementptr (i8, ptr null, i32
1) to i64)

Where %2 is wrong for (D.b[:2]) is pointer to first element of array
section. It should pointe to last element of array section.
  
The fix is to emit the pointer to the last element of array section and
use this pointer as the highest element in partial struct data.

After change IR:
  %a = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 0
  %b = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 1
  %arrayidx = getelementptr inbounds [2 x float], ptr %b, i64 0, i64 0
  %b1 = getelementptr inbounds %struct.DataTy, ptr %D, i32 0, i32 1
  %arrayidx2 = getelementptr inbounds [2 x float], ptr %b1, i64 0, i64 1
  %1 = getelementptr float, ptr %arrayidx2, i32 1
  %2 = ptrtoint ptr %1 to i64
  %3 = ptrtoint ptr %a to i64
  %4 = sub i64 %2, %3
%5 = sdiv exact i64 %4, ptrtoint (ptr getelementptr (i8, ptr null, i32
1) to i64)
2023-12-07 09:38:56 -08:00
Joseph Huber
52fe16a47e [Libomptarget][Obvious] Fix incorrect if-else in CMake for destination
Summary:
This was added in a previous patch to update how we export the static
library used for OpenMP offloading. By mistake this if-else was using
the output incorrectly.

Fixes https://github.com/llvm/llvm-project/issues/74079
2023-12-07 08:27:38 -06:00
Johannes Doerfert
13b8826508 Revert " [OpenMP][NFC] Remove DelayedBinDesc" (#74679)
Reverts llvm/llvm-project#74360

As I wrote in the analysis of #74360:

Since
bc4e0c048a
we will not add PluginAdaptors into the container of all plugin adaptors
before the plugin is not ready. The error is thereby gone. When and old
HSA loads other libraries they can call register_image but that will
simply not register the image with the plugin we are currently
initializing. That seems like reasonable behavior, thought it is good to
keep in mind if we ever want a kernel library (@jhuber6 @mjklemm). We
can still have a standalone kernel library though or load it late after
all plugins are setup (which seems reasonable).

I did not expect one our tests actually doing exactly what this will not
allow anymore, at least when you use rocm <5.5.0. Need to figure out if
we want this behavior (for rocm <5.5.0).
2023-12-06 16:04:23 -08:00
Johannes Doerfert
62b11e1b16 [OpenMP][NFC] Actually use a string in the error message 2023-12-06 15:06:21 -08:00
Johannes Doerfert
0ace6ee73a [OpenMP][FIX] Ensure we do not read outside the device image (#74669)
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 14:57:57 -08:00
Johannes Doerfert
dcbb1968a8 [OpenMP][FIX] Use unique library name to avoid clashes with other tests
We probably should use a temporary name, but having stable names helps
debugging.
2023-12-06 14:50:28 -08:00
Johannes Doerfert
d552ce2638 [OpenMP][NFC] Remove DelayedBinDesc (#74360)
Remove `DelayedBinDesc` as it is not necessary since
bc4e0c048a.
See
https://github.com/llvm/llvm-project/pull/74360#issuecomment-1843603736
for details.
2023-12-06 14:48:23 -08:00
Johannes Doerfert
2a1bcf1f38 [OpenMP] Allow to specify what plugins to look for (#74538)
By default we now only look for the plugins we build, but the user can
overwrite that with `LIBOMPTARGET_PLUGINS_TO_LOAD="cuda,amdgpu,x86_64"`
2023-12-06 14:16:02 -08:00
Joseph Huber
6f3bd3a2f6 [Libomptarget] Add a utility function for checking existence of symbols (#74550)
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-06 07:41:27 -06:00
JP Lehr
a65363d989 [OpenMP] Disable offloading/barrier_fence test
Unblock build bot, while investigating. Issue is tracked under llvm
https://github.com/llvm/llvm-project/issues/74582
2023-12-06 04:32:48 -06:00
Johannes Doerfert
20da662656 [OpenMP][FIX] Fixup test that doesn't work with lit's env substitute 2023-12-05 16:32:19 -08:00
Johannes Doerfert
68db7aef74 [OpenMP] Reorganize the initialization of PluginAdaptorTy (#74397)
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 16:04:01 -08:00
Johannes Doerfert
9f87509b19 [OpenMP][FIX] Ensure we allow shared libraries without kernels (#74532)
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-05 15:25:10 -08:00