Skip to content

Attributes #69358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions openmp/libomptarget/DeviceRTL/include/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ inline uint32_t &lookupImpl(uint32_t state::ICVStateTy::*Var,
return TeamState.ICVState.*Var;
}

__attribute__((always_inline, flatten)) inline uint32_t &
[[gnu::always_inline, gnu::flatten]] inline uint32_t &
lookup32(ValueKind Kind, bool IsReadonly, IdentTy *Ident, bool ForceTeamState) {
switch (Kind) {
case state::VK_NThreads:
Expand Down Expand Up @@ -218,7 +218,7 @@ lookup32(ValueKind Kind, bool IsReadonly, IdentTy *Ident, bool ForceTeamState) {
__builtin_unreachable();
}

__attribute__((always_inline, flatten)) inline void *&
[[gnu::always_inline, gnu::flatten]] inline void *&
lookupPtr(ValueKind Kind, bool IsReadonly, bool ForceTeamState) {
switch (Kind) {
case state::VK_ParallelRegionFn:
Expand All @@ -232,47 +232,45 @@ lookupPtr(ValueKind Kind, bool IsReadonly, bool ForceTeamState) {
/// A class without actual state used to provide a nice interface to lookup and
/// update ICV values we can declare in global scope.
template <typename Ty, ValueKind Kind> struct Value {
__attribute__((flatten, always_inline)) operator Ty() {
[[gnu::flatten, gnu::always_inline]] operator Ty() {
return lookup(/* IsReadonly */ true, /* IdentTy */ nullptr,
/* ForceTeamState */ false);
}

__attribute__((flatten, always_inline)) Value &operator=(const Ty &Other) {
[[gnu::flatten, gnu::always_inline]] Value &operator=(const Ty &Other) {
set(Other, /* IdentTy */ nullptr);
return *this;
}

__attribute__((flatten, always_inline)) Value &operator++() {
[[gnu::flatten, gnu::always_inline]] Value &operator++() {
inc(1, /* IdentTy */ nullptr);
return *this;
}

__attribute__((flatten, always_inline)) Value &operator--() {
[[gnu::flatten, gnu::always_inline]] Value &operator--() {
inc(-1, /* IdentTy */ nullptr);
return *this;
}

__attribute__((flatten, always_inline)) void
[[gnu::flatten, gnu::always_inline]] void
assert_eq(const Ty &V, IdentTy *Ident = nullptr,
bool ForceTeamState = false) {
ASSERT(lookup(/* IsReadonly */ true, Ident, ForceTeamState) == V, nullptr);
}

private:
__attribute__((flatten, always_inline)) Ty &
[[gnu::flatten, gnu::always_inline]] Ty &
lookup(bool IsReadonly, IdentTy *Ident, bool ForceTeamState) {
Ty &t = lookup32(Kind, IsReadonly, Ident, ForceTeamState);
return t;
}

__attribute__((flatten, always_inline)) Ty &inc(int UpdateVal,
IdentTy *Ident) {
[[gnu::flatten, gnu::always_inline]] Ty &inc(int UpdateVal, IdentTy *Ident) {
return (lookup(/* IsReadonly */ false, Ident, /* ForceTeamState */ false) +=
UpdateVal);
}

__attribute__((flatten, always_inline)) Ty &set(Ty UpdateVal,
IdentTy *Ident) {
[[gnu::flatten, gnu::always_inline]] Ty &set(Ty UpdateVal, IdentTy *Ident) {
return (lookup(/* IsReadonly */ false, Ident, /* ForceTeamState */ false) =
UpdateVal);
}
Expand All @@ -284,12 +282,12 @@ template <typename Ty, ValueKind Kind> struct Value {
/// a nice interface to lookup and update ICV values
/// we can declare in global scope.
template <typename Ty, ValueKind Kind> struct PtrValue {
__attribute__((flatten, always_inline)) operator Ty() {
[[gnu::flatten, gnu::always_inline]] operator Ty() {
return lookup(/* IsReadonly */ true, /* IdentTy */ nullptr,
/* ForceTeamState */ false);
}

__attribute__((flatten, always_inline)) PtrValue &operator=(const Ty Other) {
[[gnu::flatten, gnu::always_inline]] PtrValue &operator=(const Ty Other) {
set(Other);
return *this;
}
Expand Down
2 changes: 1 addition & 1 deletion openmp/libomptarget/DeviceRTL/include/Synchronization.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void threads(atomic::OrderingTy Ordering);
/// (hence all threads in the block are "aligned"). Also perform a fence before
/// and after the barrier according to \p Ordering. Note that the
/// fence might be part of the barrier if the target offers this.
__attribute__((noinline)) void threadsAligned(atomic::OrderingTy Ordering);
[[gnu::noinline]] void threadsAligned(atomic::OrderingTy Ordering);

#pragma omp end assumes
///}
Expand Down
2 changes: 1 addition & 1 deletion openmp/libomptarget/DeviceRTL/include/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ template <typename DstTy, typename SrcTy> inline DstTy convertViaPun(SrcTy V) {
}

/// A pointer variable that has by design an `undef` value. Use with care.
__attribute__((loader_uninitialized)) static void *const UndefPtr;
[[clang::loader_uninitialized]] static void *const UndefPtr;

#define OMP_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
#define OMP_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
Expand Down
5 changes: 3 additions & 2 deletions openmp/libomptarget/DeviceRTL/src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ using namespace ompx;

// This variable should be visibile to the plugin so we override the default
// hidden visibility.
DeviceEnvironmentTy CONSTANT(__omp_rtl_device_environment)
__attribute__((used, retain, weak, visibility("protected")));
[[gnu::used, gnu::retain, gnu::weak,
gnu::visibility("protected")]] DeviceEnvironmentTy
CONSTANT(__omp_rtl_device_environment);

uint32_t config::getDebugKind() {
return __omp_rtl_debug_kind & __omp_rtl_device_environment.DebugKind;
Expand Down
8 changes: 4 additions & 4 deletions openmp/libomptarget/DeviceRTL/src/Mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ uint32_t mapping::getNumberOfProcessorElements() {

// TODO: This is a workaround for initialization coming from kernels outside of
// the TU. We will need to solve this more correctly in the future.
int __attribute__((weak)) SHARED(IsSPMDMode);
[[gnu::weak]] int SHARED(IsSPMDMode);

void mapping::init(bool IsSPMD) {
if (mapping::isInitialThreadInLevel0(IsSPMD))
Expand All @@ -358,15 +358,15 @@ bool mapping::isGenericMode() { return !isSPMDMode(); }
///}

extern "C" {
__attribute__((noinline)) uint32_t __kmpc_get_hardware_thread_id_in_block() {
[[gnu::noinline]] uint32_t __kmpc_get_hardware_thread_id_in_block() {
return mapping::getThreadIdInBlock();
}

__attribute__((noinline)) uint32_t __kmpc_get_hardware_num_threads_in_block() {
[[gnu::noinline]] uint32_t __kmpc_get_hardware_num_threads_in_block() {
return impl::getNumberOfThreadsInBlock(mapping::DIM_X);
}

__attribute__((noinline)) uint32_t __kmpc_get_warp_size() {
[[gnu::noinline]] uint32_t __kmpc_get_warp_size() {
return impl::getWarpSize();
}
}
Expand Down
14 changes: 6 additions & 8 deletions openmp/libomptarget/DeviceRTL/src/Parallelism.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ uint32_t determineNumberOfThreads(int32_t NumThreadsClause) {
}

// Invoke an outlined parallel function unwrapping arguments (up to 32).
__attribute__((always_inline)) void invokeMicrotask(int32_t global_tid,
int32_t bound_tid, void *fn,
void **args,
int64_t nargs) {
[[clang::always_inline]] void invokeMicrotask(int32_t global_tid,
int32_t bound_tid, void *fn,
void **args, int64_t nargs) {
switch (nargs) {
#include "generated_microtask_cases.gen"
default:
Expand All @@ -84,7 +83,7 @@ __attribute__((always_inline)) void invokeMicrotask(int32_t global_tid,

extern "C" {

__attribute__((always_inline)) void
[[clang::always_inline]] void
__kmpc_parallel_51(IdentTy *ident, int32_t, int32_t if_expr,
int32_t num_threads, int proc_bind, void *fn,
void *wrapper_fn, void **args, int64_t nargs) {
Expand Down Expand Up @@ -262,8 +261,7 @@ __kmpc_parallel_51(IdentTy *ident, int32_t, int32_t if_expr,
__kmpc_end_sharing_variables();
}

__attribute__((noinline)) bool
__kmpc_kernel_parallel(ParallelRegionFnTy *WorkFn) {
[[clang::noinline]] bool __kmpc_kernel_parallel(ParallelRegionFnTy *WorkFn) {
// Work function and arguments for L1 parallel region.
*WorkFn = state::ParallelRegionFn;

Expand All @@ -277,7 +275,7 @@ __kmpc_kernel_parallel(ParallelRegionFnTy *WorkFn) {
return ThreadIsActive;
}

__attribute__((noinline)) void __kmpc_kernel_end_parallel() {
[[clang::noinline]] void __kmpc_kernel_end_parallel() {
// In case we have modified an ICV for this thread before a ThreadState was
// created. We drop it now to not contaminate the next parallel region.
ASSERT(!mapping::isSPMDMode(), nullptr);
Expand Down
12 changes: 5 additions & 7 deletions openmp/libomptarget/DeviceRTL/src/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using namespace ompx;
constexpr const uint32_t Alignment = 16;

/// External symbol to access dynamic shared memory.
extern unsigned char DynamicSharedBuffer[] __attribute__((aligned(Alignment)));
[[gnu::aligned(Alignment)]] extern unsigned char DynamicSharedBuffer[];
#pragma omp allocate(DynamicSharedBuffer) allocator(omp_pteam_mem_alloc)

/// The kernel environment passed to the init method by the compiler.
Expand Down Expand Up @@ -105,10 +105,8 @@ struct SharedMemorySmartStackTy {
}

/// The actual storage, shared among all warps.
unsigned char Data[state::SharedScratchpadSize]
__attribute__((aligned(Alignment)));
unsigned char Usage[mapping::MaxThreadsPerTeam]
__attribute__((aligned(Alignment)));
[[gnu::aligned(Alignment)]] unsigned char Data[state::SharedScratchpadSize];
[[gnu::aligned(Alignment)]] unsigned char Usage[mapping::MaxThreadsPerTeam];
};

static_assert(state::SharedScratchpadSize / mapping::MaxThreadsPerTeam <= 256,
Expand Down Expand Up @@ -423,11 +421,11 @@ int omp_get_initial_device(void) { return -1; }
}

extern "C" {
__attribute__((noinline)) void *__kmpc_alloc_shared(uint64_t Bytes) {
[[clang::noinline]] void *__kmpc_alloc_shared(uint64_t Bytes) {
return memory::allocShared(Bytes, "Frontend alloc shared");
}

__attribute__((noinline)) void __kmpc_free_shared(void *Ptr, uint64_t Bytes) {
[[clang::noinline]] void __kmpc_free_shared(void *Ptr, uint64_t Bytes) {
memory::freeShared(Ptr, Bytes, "Frontend free shared");
}

Expand Down
7 changes: 3 additions & 4 deletions openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,12 @@ void __kmpc_barrier(IdentTy *Loc, int32_t TId) {
impl::namedBarrier();
}

__attribute__((noinline)) void __kmpc_barrier_simple_spmd(IdentTy *Loc,
int32_t TId) {
[[clang::noinline]] void __kmpc_barrier_simple_spmd(IdentTy *Loc, int32_t TId) {
synchronize::threadsAligned(atomic::OrderingTy::seq_cst);
}

__attribute__((noinline)) void __kmpc_barrier_simple_generic(IdentTy *Loc,
int32_t TId) {
[[clang::noinline]] void __kmpc_barrier_simple_generic(IdentTy *Loc,
int32_t TId) {
synchronize::threads(atomic::OrderingTy::seq_cst);
}

Expand Down
2 changes: 1 addition & 1 deletion openmp/libomptarget/DeviceRTL/src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

using namespace ompx;

extern "C" __attribute__((weak)) int IsSPMDMode;
extern "C" [[gnu::weak]] int IsSPMDMode;

namespace impl {

Expand Down