Changes between Initial Version and Version 1 of OpenMP-Transformation-Introduction


Ignore:
Timestamp:
12/02/21 15:59:26 (4 years ago)
Author:
wuwenhao
Comment:

Create this page for NextGen Omp Trans Sec.1 Intro

Legend:

Unmodified
Added
Removed
Modified
  • OpenMP-Transformation-Introduction

    v1 v1  
     1= 1 OpenMP Transformation Introduction =
     2
     3== 1.1 The Sequentially Consistent Subset of OpenMP ==
     4The current domain for OpenMP program verification focuses on sequentially consistent programs that:
     5* Do not use non-sequentially consistent atomic directives;
     6* Do not rely on the accuracy of a false result from omp_test_lock and omp_test_nest_lock; and
     7* Correctly avoid data races as required in Section 1.4.1 on page 23 (OpenMP spec 5.0) ([https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5.0.pdf spec])
     8
     9The relaxed consistency model is invisible for such programs, and any explicit flush operations in such programs are redundant.
     10
     11== 1.2 Overview of OpenMP Transformation ==
     12
     13=== 1.2.1 Data Race Detection by Analyzing !Read/Write Operations ===
     14
     15==== Basic Transformation Pattern ====
     161. At a right mover (e.g. lock, enter_critical, enter_atomic), we do yield and push.
     172. At a left mover (e.g., unlock, exit_critical, exit_atomic), we do check and then clean (pop).
     18    (Note that it only clean whats in between a pair of right mover and left mover.)
     193. A barrier is transformed as: barrier() ; $check_data_race(); $track_clean(); barrier();
     204. Read and write operations are tracked in $atomic scope and functions/primitives of tracking read/write operations are:
     21  - {{{$track{}}} . . . . . . . . . . . . . . . . creates a new pair of read/write sets for tracking.
     22  - {{{} // end of $track scope}}} . . removes read/write sets currently used for tracking.
     23  - {{{$track_empty();}}} . . . . . . . . . . empties read/write sets currently used for tracking.
     24  - {{{$tracked_reads();}}} . . . . . . . . returns a set of tracked shared variables read by its caller process.
     25  - {{{$tracked_writes();}}} . . . . . . . returns a set of tracked shared variables written by its caller process.
     265. {{{$check_data_race}}} asserts that:
     27{{{
     28  $forall (int i, j: 0 .. nthreads - 1) (i != j) ==>
     29    $mem_disjoint(
     30      writes[i],
     31      $mem_union(reads[j], writes[j])
     32    );
     33}}}
     34
     35E.g.,
     36{{{
     37#pragma omp parallel shared(s)
     38{
     39  A;
     40  #pragma omp critical(c)
     41  {
     42    B;
     43  }
     44  C;
     45}
     46}}}
     47
     48 ==>
     49
     50{{{
     51void $check_data_race($mem *rs, $mem *ws, int n, int tid) {
     52  rs[tid] = $tracked_reads();
     53  ws[tid] = $tracked_writes();
     54  $assert(
     55    $forall (int j: 0 .. nthreads - 1) (j != tid) ==>
     56      $mem_disjoint(ws[tid], $mem_union(rs[j], ws[j])) &&
     57      $mem_disjoint(...)
     58  );
     59}
     60}}}
     61{{{
     62// Init parallel region env.
     63$range thread_range = 0 .. nthreads - 1;
     64$domain(1) dom = ($domain){thread_range};
     65$omp_gteam gteam = $omp_gteam_create($here, nthreads);
     66$mem rs[nthreads], ws[nthreads]; // read sets and write sets.
     67for(int i=0; i<nthreads; i++) {
     68  ws[i] = $mem_empty();
     69  rs[i] = $mem_empty();
     70}
     71
     72// Transformed parallel region
     73$for (int tid: dom) {
     74  $depends_on(/*nothing*/)$atomic{
     75    $omp_team team = $omp_team_create($here, gteam, tid);
     76    $track{ // RS stack: rs0:={}; WS stack: ws0:={};
     77      // Enter parallel region
     78      A;
     79      $yield();
     80      $when(critical_c->value == 0);
     81      $track{ // Ignore race on lock
     82         critical_c->value = 1; // Enter critical block
     83      }
     84      B;
     85      $track{ // Ignore race on lock
     86         critical_c->value = 0; // Exit critical block
     87      }
     88      // RS stack: rs0:={A, B}; WS stack: ws0:={A, B};
     89      $check_data_race(&rs, &ws, nthreads, tid); // 1st check
     90      $track_clean();
     91      rs[tid] = $mem_empty();
     92      ws[tid] = $mem_empty();
     93      // RS stack: rs0:={}; WS stack: ws0:={};
     94      C;
     95      $check_data_race(&rs, &ws, nthreads, tid); // 2nd check
     96    } // RS stack: <empty>; WS stack: <empty>; empty sets rs0, ws0;
     97  } // end $atomic
     98} // end $for
     99}}}
     100
     101We denotes that thread x executes statement A as Ax.
     102Assuming there are two threads 0 and 1, two traces shall be explored:
     103
     104Trace1: A0y0 A1y1 B0cdr0C0cdr0 B1cdr1C1cdr1;
     105
     106Trace2: A0y0 A1y1 B1cdr1C1cdr1 B0cdr0C0cdr0;
     107
     108For the first trace, cdr0 following B0 checks data races between
     109
     110A0 and A1;
     111B0 and A1;
     112
     113Then, w/r sets on thread 0 is cleaned.
     114
     115The second cdr0 following C0 checks data races between
     116
     117C0 and A1;
     118
     119An implicit barrier is placed at the end after the second cdr0,
     120thus thread 1 starts executing its remaining part.
     121The first cdr1 checks data races between
     122
     123C0 and A1;
     124C0 and B1;
     125
     126Then, tracked sets on both A1 and B1 are cleaned.
     127
     128Finally, the last cdr1 in the first trace checks data races between
     129
     130C0 and C1;
     131
     132The second trace will complete checking by performing checks between
     133
     134B1 and A0
     135C1 and A0
     136C1 and B0
     137
     138Because B is protected by critical section, races between B0 and B1 are not checked.
     139As a result, all required pairs are checked.
     140
     141[https://vsl.cis.udel.edu/trac/civl/wiki/Next-GenOpenMPTransformation Back: Index]
     142
     143[https://vsl.cis.udel.edu/trac/civl/wiki/OpenMP-Transformation-Supported-Features Next: Supported OpenMP Features]