1 //===- Synchronization.h - OpenMP synchronization utilities ------- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 //===----------------------------------------------------------------------===//
12 #ifndef OMPTARGET_DEVICERTL_SYNCHRONIZATION_H
13 #define OMPTARGET_DEVICERTL_SYNCHRONIZATION_H
19 namespace synchronize
{
21 /// Initialize the synchronization machinery. Must be called by all threads.
22 void init(bool IsSPMD
);
24 /// Synchronize all threads in a warp identified by \p Mask.
25 void warp(LaneMaskTy Mask
);
27 /// Synchronize all threads in a block.
30 /// Synchronizing threads is allowed even if they all hit different instances of
31 /// `synchronize::threads()`. However, `synchronize::threadsAligned()` is more
32 /// restrictive in that it requires all threads to hit the same instance. The
33 /// noinline is removed by the openmp-opt pass and helps to preserve the
34 /// information till then.
36 #pragma omp begin assumes ext_aligned_barrier
38 /// Synchronize all threads in a block, they are are reaching the same
39 /// instruction (hence all threads in the block are "aligned").
40 __attribute__((noinline
)) void threadsAligned();
42 #pragma omp end assumes
45 } // namespace synchronize
49 /// Memory fence with \p Ordering semantics for the team.
50 void team(int Ordering
);
52 /// Memory fence with \p Ordering semantics for the contention group.
53 void kernel(int Ordering
);
55 /// Memory fence with \p Ordering semantics for the system.
56 void system(int Ordering
);
62 /// Atomically load \p Addr with \p Ordering semantics.
63 uint32_t load(uint32_t *Addr
, int Ordering
);
65 /// Atomically store \p V to \p Addr with \p Ordering semantics.
66 void store(uint32_t *Addr
, uint32_t V
, int Ordering
);
68 /// Atomically increment \p *Addr and wrap at \p V with \p Ordering semantics.
69 uint32_t inc(uint32_t *Addr
, uint32_t V
, int Ordering
);
71 /// Atomically add \p V to \p *Addr with \p Ordering semantics.
72 uint32_t add(uint32_t *Addr
, uint32_t V
, int Ordering
);
74 /// Atomically add \p V to \p *Addr with \p Ordering semantics.
75 uint64_t add(uint64_t *Addr
, uint64_t V
, int Ordering
);