@@ -130,6 +130,8 @@ int testLock(omp_lock_t *);
130
130
void initLock (omp_lock_t *);
131
131
void destroyLock (omp_lock_t *);
132
132
void setLock (omp_lock_t *);
133
+ void unsetCriticalLock (omp_lock_t *);
134
+ void setCriticalLock (omp_lock_t *);
133
135
134
136
// / AMDGCN Implementation
135
137
// /
@@ -269,6 +271,25 @@ void initLock(omp_lock_t *) { __builtin_trap(); }
269
271
void destroyLock (omp_lock_t *) { __builtin_trap (); }
270
272
void setLock (omp_lock_t *) { __builtin_trap (); }
271
273
274
+ constexpr uint32_t UNSET = 0 ;
275
+ constexpr uint32_t SET = 1 ;
276
+
277
+ void unsetCriticalLock (omp_lock_t *Lock) {
278
+ (void )atomicExchange ((uint32_t *)Lock, UNSET, atomic::acq_rel);
279
+ }
280
+
281
+ void setCriticalLock (omp_lock_t *Lock) {
282
+ uint64_t LowestActiveThread = utils::ffs (mapping::activemask ()) - 1 ;
283
+ if (mapping::getThreadIdInWarp () == LowestActiveThread) {
284
+ fenceKernel (atomic::release);
285
+ while (!atomicCAS ((uint32_t *)Lock, UNSET, SET, atomic::relaxed,
286
+ atomic::relaxed)) {
287
+ __builtin_amdgcn_s_sleep (32 );
288
+ }
289
+ fenceKernel (atomic::aquire);
290
+ }
291
+ }
292
+
272
293
#pragma omp end declare variant
273
294
// /}
274
295
@@ -450,6 +471,14 @@ uint32_t atomic::inc(uint32_t *Addr, uint32_t V, atomic::OrderingTy Ordering) {
450
471
return impl::atomicInc (Addr, V, Ordering);
451
472
}
452
473
474
+ void unsetCriticalLock (omp_lock_t *Lock) {
475
+ impl::unsetLock (Lock);
476
+ }
477
+
478
+ void setCriticalLock (omp_lock_t *Lock) {
479
+ impl::setLock (Lock);
480
+ }
481
+
453
482
extern " C" {
454
483
void __kmpc_ordered (IdentTy *Loc, int32_t TId) { FunctionTracingRAII (); }
455
484
@@ -518,12 +547,12 @@ void __kmpc_syncwarp(uint64_t Mask) {
518
547
519
548
void __kmpc_critical (IdentTy *Loc, int32_t TId, CriticalNameTy *Name) {
520
549
FunctionTracingRAII ();
521
- omp_set_lock (reinterpret_cast <omp_lock_t *>(Name));
550
+ impl::setCriticalLock (reinterpret_cast <omp_lock_t *>(Name));
522
551
}
523
552
524
553
void __kmpc_end_critical (IdentTy *Loc, int32_t TId, CriticalNameTy *Name) {
525
554
FunctionTracingRAII ();
526
- omp_unset_lock (reinterpret_cast <omp_lock_t *>(Name));
555
+ impl::unsetCriticalLock (reinterpret_cast <omp_lock_t *>(Name));
527
556
}
528
557
529
558
void omp_init_lock (omp_lock_t *Lock) { impl::initLock (Lock); }
0 commit comments