Misplaced Pages

Banerjee test

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Test for determining computer program dependents
The topic of this article may not meet Misplaced Pages's general notability guideline. Please help to demonstrate the notability of the topic by citing reliable secondary sources that are independent of the topic and provide significant coverage of it beyond a mere trivial mention. If notability cannot be shown, the article is likely to be merged, redirected, or deleted.
Find sources: "Banerjee test" – news · newspapers · books · scholar · JSTOR (October 2011) (Learn how and when to remove this message)
This article includes a list of references, related reading, or external links, but its sources remain unclear because it lacks inline citations. Please help improve this article by introducing more precise citations. (January 2021) (Learn how and when to remove this message)

In compiler theory, the Banerjee test is a dependence test. The Banerjee test assumes that all loop indices are independent, however in reality, this is often not true. The Banerjee test is a conservative test. That is, it will not break a dependence that does not exist.

This means that the only thing the test can guarantee is the absence of a dependence.

Antidependence is broken True dependence is broken
True There are no
antidependencies
There are no
true dependencies
False There may or may not be
antidependencies
There may or may not be
true dependencies

General form

For a loop of the form:

for(i=0; i<n; i++) {
    c = a + b; /* statement s1 */
    d = c + e;    /* statement s2 */
}

A true dependence exists between statement s1 and statement s2 if and only if :

i , j [ 0 , n 1 ] : i j     and     f ( i ) = g ( j ) {\displaystyle \exists i,j\in \left:i\leq j~~{\textrm {and}}~~f\left(i\right)=g\left(j\right)\!}

An anti dependence exists between statement s1 and statement s2 if and only if :

i , j [ 0 , n 1 ] : i > j     and     f ( i ) = g ( j ) {\displaystyle \exists i,j\in \left:i>j~~{\textrm {and}}~~f\left(i\right)=g\left(j\right)\!}

For a loop of the form:

for(i=0; i<n; i++) {
    c = a + b; /* statement s1 */
    a = d + e;    /* statement s2 */
}

A true dependence exists between statement s1 and statement s2 if and only if :

i , j [ 0 , n 1 ] : i < j     and     f ( i ) = g ( j ) {\displaystyle \exists i,j\in \left:i<j~~{\textrm {and}}~~f\left(i\right)=g\left(j\right)\!}

Example

An example of Banerjee's test follows below.

The loop to be tested for dependence is:

for(i=0; i<10; i++)  {
    c = a + b; /*statement s1*/
    d = c + e;    /*statement s2*/
}

Let

f ( i )   =   i + 9 g ( j )   =   j + 0. {\displaystyle {\begin{array}{lcr}f(i)\ =\ i+9\\g(j)\ =\ j+0.\end{array}}}

So therefore,

a 0 = 9   ,   a 1 = 1 , b 0 = 0   ,   b 1 = 1. {\displaystyle {\begin{array}{lcr}a_{0}=9\ ,\ a_{1}=1,\\b_{0}=0\ ,\ b_{1}=1.\\\end{array}}}

and b 0 a 0 = 9. {\displaystyle b_{0}-a_{0}=-9.}

Testing for antidependence

Then

U max   =   max { a 1 × i b 1 × j }     when     0 j < i < n L min   =   min { a 1 × i b 1 × j }     when     0 j < i < n , {\displaystyle {\begin{array}{lcr}U_{\max }\ =\ \max \left\{a_{1}\times i-b_{1}\times j\right\}~~{\textrm {when}}~~0\leq j<i<n\\L_{\min }\ =\ \min \left\{a_{1}\times i-b_{1}\times j\right\}~~{\textrm {when}}~~0\leq j<i<n,\\\end{array}}}

which gives

U max   =   9 0 = 9 L min   =   1 0 = 1. {\displaystyle {\begin{array}{lcr}U_{\max }\ =\ 9-0=9\\L_{\min }\ =\ 1-0=1.\\\end{array}}}

Now, the bounds on b 0 a 0 {\displaystyle b_{0}-a_{0}} are 1 9 9. {\displaystyle 1\leq -9\leq 9.}

Clearly, -9 is not inside the bounds, so the antidependence is broken.

Testing for true dependence

U m a x   =   max { a 1 × i b 1 × j }     when     i j < n L m i n   =   min { a 1 × i b 1 × j }     when     i j < n . {\displaystyle {\begin{array}{lcr}U_{max}\ =\ \max \left\{a_{1}\times i-b_{1}\times j\right\}~~{\textrm {when}}~~\leq i\leq j<n\\L_{min}\ =\ \min \left\{a_{1}\times i-b_{1}\times j\right\}~~{\textrm {when}}~~\leq i\leq j<n.\\\end{array}}}

Which gives:

U m a x   =   9 9 = 0 L m i n   =   0 9 = 9. {\displaystyle {\begin{array}{lcr}U_{max}\ =\ 9-9=0\\L_{min}\ =\ 0-9=-9.\\\end{array}}}

Now, the bounds on b 0 a 0 {\displaystyle b_{0}-a_{0}} are 9 9 0. {\displaystyle -9\leq -9\leq 0.}

Clearly, -9 is inside the bounds, so the true dependence is not broken.

Conclusion

Because the antidependence was broken, we can assert that anti dependence does not exist between the statements.

Because the true dependence was not broken, we do not know if a true dependence exists between the statements.

Therefore, the loop is parallelisable, but the statements must be executed in order of their (potential) true dependence.


See also

References

  • Randy Allen and Ken Kennedy. Optimizing Compilers for Modern Architectures: A Dependence-based Approach
  • Lastovetsky, Alex. Parallel Computing on Heterogenous Networks
Category: