Changeset View
Changeset View
Standalone View
Standalone View
openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
Show First 20 Lines • Show All 240 Lines • ▼ Show 20 Lines | uint32_t atomic::add(uint32_t *Addr, uint32_t V, int Ordering) { | ||||
return impl::atomicAdd(Addr, V, Ordering); | return impl::atomicAdd(Addr, V, Ordering); | ||||
} | } | ||||
uint64_t atomic::add(uint64_t *Addr, uint64_t V, int Ordering) { | uint64_t atomic::add(uint64_t *Addr, uint64_t V, int Ordering) { | ||||
return impl::atomicAdd(Addr, V, Ordering); | return impl::atomicAdd(Addr, V, Ordering); | ||||
} | } | ||||
extern "C" { | extern "C" { | ||||
void __kmpc_ordered(IdentTy *Loc, int32_t TId) {} | void __kmpc_ordered(IdentTy *Loc, int32_t TId) { FunctionTracingRAII(); } | ||||
void __kmpc_end_ordered(IdentTy *Loc, int32_t TId) {} | void __kmpc_end_ordered(IdentTy *Loc, int32_t TId) { FunctionTracingRAII(); } | ||||
int32_t __kmpc_cancel_barrier(IdentTy *Loc, int32_t TId) { | int32_t __kmpc_cancel_barrier(IdentTy *Loc, int32_t TId) { | ||||
FunctionTracingRAII(); | |||||
__kmpc_barrier(Loc, TId); | __kmpc_barrier(Loc, TId); | ||||
return 0; | return 0; | ||||
} | } | ||||
void __kmpc_barrier(IdentTy *Loc, int32_t TId) { | void __kmpc_barrier(IdentTy *Loc, int32_t TId) { | ||||
FunctionTracingRAII(); | |||||
if (mapping::isMainThreadInGenericMode()) | if (mapping::isMainThreadInGenericMode()) | ||||
return __kmpc_flush(Loc); | return __kmpc_flush(Loc); | ||||
if (mapping::isSPMDMode()) | if (mapping::isSPMDMode()) | ||||
return __kmpc_barrier_simple_spmd(Loc, TId); | return __kmpc_barrier_simple_spmd(Loc, TId); | ||||
impl::namedBarrier(); | impl::namedBarrier(); | ||||
} | } | ||||
__attribute__((noinline)) void __kmpc_barrier_simple_spmd(IdentTy *Loc, | __attribute__((noinline)) void __kmpc_barrier_simple_spmd(IdentTy *Loc, | ||||
int32_t TId) { | int32_t TId) { | ||||
FunctionTracingRAII(); | |||||
synchronize::threads(); | synchronize::threads(); | ||||
} | } | ||||
int32_t __kmpc_master(IdentTy *Loc, int32_t TId) { | int32_t __kmpc_master(IdentTy *Loc, int32_t TId) { | ||||
FunctionTracingRAII(); | |||||
return omp_get_team_num() == 0; | return omp_get_team_num() == 0; | ||||
} | } | ||||
void __kmpc_end_master(IdentTy *Loc, int32_t TId) {} | void __kmpc_end_master(IdentTy *Loc, int32_t TId) { FunctionTracingRAII(); } | ||||
int32_t __kmpc_single(IdentTy *Loc, int32_t TId) { | int32_t __kmpc_single(IdentTy *Loc, int32_t TId) { | ||||
FunctionTracingRAII(); | |||||
return __kmpc_master(Loc, TId); | return __kmpc_master(Loc, TId); | ||||
} | } | ||||
void __kmpc_end_single(IdentTy *Loc, int32_t TId) { | void __kmpc_end_single(IdentTy *Loc, int32_t TId) { | ||||
FunctionTracingRAII(); | |||||
// The barrier is explicitly called. | // The barrier is explicitly called. | ||||
} | } | ||||
void __kmpc_flush(IdentTy *Loc) { fence::kernel(__ATOMIC_SEQ_CST); } | void __kmpc_flush(IdentTy *Loc) { | ||||
FunctionTracingRAII(); | |||||
fence::kernel(__ATOMIC_SEQ_CST); | |||||
} | |||||
uint64_t __kmpc_warp_active_thread_mask(void) { return mapping::activemask(); } | uint64_t __kmpc_warp_active_thread_mask(void) { | ||||
FunctionTracingRAII(); | |||||
return mapping::activemask(); | |||||
} | |||||
void __kmpc_syncwarp(uint64_t Mask) { synchronize::warp(Mask); } | void __kmpc_syncwarp(uint64_t Mask) { | ||||
FunctionTracingRAII(); | |||||
synchronize::warp(Mask); | |||||
} | |||||
void __kmpc_critical(IdentTy *Loc, int32_t TId, CriticalNameTy *Name) { | void __kmpc_critical(IdentTy *Loc, int32_t TId, CriticalNameTy *Name) { | ||||
FunctionTracingRAII(); | |||||
omp_set_lock(reinterpret_cast<omp_lock_t *>(Name)); | omp_set_lock(reinterpret_cast<omp_lock_t *>(Name)); | ||||
} | } | ||||
void __kmpc_end_critical(IdentTy *Loc, int32_t TId, CriticalNameTy *Name) { | void __kmpc_end_critical(IdentTy *Loc, int32_t TId, CriticalNameTy *Name) { | ||||
FunctionTracingRAII(); | |||||
omp_unset_lock(reinterpret_cast<omp_lock_t *>(Name)); | omp_unset_lock(reinterpret_cast<omp_lock_t *>(Name)); | ||||
} | } | ||||
void omp_init_lock(omp_lock_t *Lock) { impl::initLock(Lock); } | void omp_init_lock(omp_lock_t *Lock) { impl::initLock(Lock); } | ||||
void omp_destroy_lock(omp_lock_t *Lock) { impl::destoryLock(Lock); } | void omp_destroy_lock(omp_lock_t *Lock) { impl::destoryLock(Lock); } | ||||
void omp_set_lock(omp_lock_t *Lock) { impl::setLock(Lock); } | void omp_set_lock(omp_lock_t *Lock) { impl::setLock(Lock); } | ||||
void omp_unset_lock(omp_lock_t *Lock) { impl::unsetLock(Lock); } | void omp_unset_lock(omp_lock_t *Lock) { impl::unsetLock(Lock); } | ||||
int omp_test_lock(omp_lock_t *Lock) { return impl::testLock(Lock); } | int omp_test_lock(omp_lock_t *Lock) { return impl::testLock(Lock); } | ||||
} // extern "C" | } // extern "C" | ||||
#pragma omp end declare target | #pragma omp end declare target |