1 //===- Synchronization.h - OpenMP synchronization utilities ------- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // 10 //===----------------------------------------------------------------------===// 11 12 #ifndef OMPTARGET_DEVICERTL_SYNCHRONIZATION_H 13 #define OMPTARGET_DEVICERTL_SYNCHRONIZATION_H 14 15 #include "Types.h" 16 17 namespace _OMP { 18 19 namespace synchronize { 20 21 /// Initialize the synchronization machinery. Must be called by all threads. 22 void init(bool IsSPMD); 23 24 /// Synchronize all threads in a warp identified by \p Mask. 25 void warp(LaneMaskTy Mask); 26 27 /// Synchronize all threads in a block. 28 void threads(); 29 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. 33 ///{ 34 #pragma omp begin assumes ext_aligned_barrier 35 36 /// Synchronize all threads in a block, they are are reaching the same 37 /// instruction (hence all threads in the block are "aligned"). 38 void threadsAligned(); 39 40 #pragma omp end assumes 41 ///} 42 43 } // namespace synchronize 44 45 namespace fence { 46 47 /// Memory fence with \p Ordering semantics for the team. 48 void team(int Ordering); 49 50 /// Memory fence with \p Ordering semantics for the contention group. 51 void kernel(int Ordering); 52 53 /// Memory fence with \p Ordering semantics for the system. 54 void system(int Ordering); 55 56 } // namespace fence 57 58 namespace atomic { 59 60 /// Atomically load \p Addr with \p Ordering semantics. 61 uint32_t load(uint32_t *Addr, int Ordering); 62 63 /// Atomically store \p V to \p Addr with \p Ordering semantics. 64 void store(uint32_t *Addr, uint32_t V, int Ordering); 65 66 /// Atomically increment \p *Addr and wrap at \p V with \p Ordering semantics. 67 uint32_t inc(uint32_t *Addr, uint32_t V, int Ordering); 68 69 /// Atomically add \p V to \p *Addr with \p Ordering semantics. 70 uint32_t add(uint32_t *Addr, uint32_t V, int Ordering); 71 72 /// Atomically add \p V to \p *Addr with \p Ordering semantics. 73 uint64_t add(uint64_t *Addr, uint64_t V, int Ordering); 74 75 } // namespace atomic 76 77 } // namespace _OMP 78 79 #endif 80