Johannes Doerfert 330d8983d2
[Offload] Move /openmp/libomptarget to /offload (#75125)
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-22 09:51:33 -07:00

102 lines
3.6 KiB
C++

//===-- OpenMP/Requirements.h - User required requirements -----*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Handling of the `omp requires` directive, e.g., requiring unified shared
// memory.
//
//===----------------------------------------------------------------------===//
#ifndef OMPTARGET_OPENMP_REQUIREMENTS_H
#define OMPTARGET_OPENMP_REQUIREMENTS_H
#include "Shared/Debug.h"
#include "llvm/ADT/StringRef.h"
#include <cassert>
#include <cstdint>
enum OpenMPOffloadingRequiresDirFlags : int64_t {
/// flag undefined.
OMP_REQ_UNDEFINED = 0x000,
/// no requires directive present.
OMP_REQ_NONE = 0x001,
/// reverse_offload clause.
OMP_REQ_REVERSE_OFFLOAD = 0x002,
/// unified_address clause.
OMP_REQ_UNIFIED_ADDRESS = 0x004,
/// unified_shared_memory clause.
OMP_REQ_UNIFIED_SHARED_MEMORY = 0x008,
/// dynamic_allocators clause.
OMP_REQ_DYNAMIC_ALLOCATORS = 0x010,
/// Auto zero-copy extension:
/// when running on an APU, the GPU plugin may decide to
/// run in zero-copy even though the user did not program
/// their application with unified_shared_memory requirement.
OMPX_REQ_AUTO_ZERO_COPY = 0x020
};
class RequirementCollection {
int64_t SetFlags = OMP_REQ_UNDEFINED;
/// Check consistency between different requires flags (from different
/// translation units).
void checkConsistency(int64_t NewFlags, int64_t SetFlags,
OpenMPOffloadingRequiresDirFlags Flag,
llvm::StringRef Clause) {
if ((SetFlags & Flag) != (NewFlags & Flag)) {
FATAL_MESSAGE(2, "'#pragma omp requires %s' not used consistently!",
Clause.data());
}
}
public:
/// Register \p NewFlags as part of the user requirements.
void addRequirements(int64_t NewFlags) {
// TODO: add more elaborate check.
// Minimal check: only set requires flags if previous value
// is undefined. This ensures that only the first call to this
// function will set the requires flags. All subsequent calls
// will be checked for compatibility.
assert(NewFlags != OMP_REQ_UNDEFINED &&
"illegal undefined flag for requires directive!");
if (SetFlags == OMP_REQ_UNDEFINED) {
SetFlags = NewFlags;
return;
}
// Auto zero-copy is only valid when no other requirement has been set
// and it is computed at device initialization time, after the requirement
// flag has already been set to OMP_REQ_NONE.
if (SetFlags == OMP_REQ_NONE && NewFlags == OMPX_REQ_AUTO_ZERO_COPY) {
SetFlags = NewFlags;
return;
}
// If multiple compilation units are present enforce
// consistency across all of them for require clauses:
// - reverse_offload
// - unified_address
// - unified_shared_memory
// - dynamic_allocators
checkConsistency(NewFlags, SetFlags, OMP_REQ_REVERSE_OFFLOAD,
"reverse_offload");
checkConsistency(NewFlags, SetFlags, OMP_REQ_UNIFIED_ADDRESS,
"unified_address");
checkConsistency(NewFlags, SetFlags, OMP_REQ_UNIFIED_SHARED_MEMORY,
"unified_shared_memory");
checkConsistency(NewFlags, SetFlags, OMP_REQ_DYNAMIC_ALLOCATORS,
"dynamic_allocators");
}
/// Return the user provided requirements.
int64_t getRequirements() const { return SetFlags; }
};
#endif // OMPTARGET_OPENMP_DEVICE_REQUIREMENTS_H