1 / 26

Code Optimization in Compaan

Code Optimization in Compaan. Problem statement. 1. Why code optimization ? 2. Where to do code optimization? 3. How to do code optimization ?. Peter Held Test (Modified). for i = 1 : 2 : 10, for j = 1 : 2 : 10, if i-3*div(i,3) <= 0, [ a(i,j) ] = funcA(); end

toni
Download Presentation

Code Optimization in Compaan

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Code Optimization in Compaan

  2. Problem statement • 1. Why code optimization ? • 2. Where to do code optimization? • 3. How to do code optimization ?

  3. Peter Held Test (Modified) • for i = 1 : 2 : 10, • for j = 1 : 2 : 10, • if i-3*div(i,3) <= 0, • [ a(i,j) ] = funcA(); • end • if j-3*div(j,3) <= 0, • [ ] = funcB( a(i,j) ); • end • end • end Matlab Code:

  4. Peter Held Test • Single Assignment Code (SAC): for i = 1 : 2 : 10, for j = 1 : 2 : 10, if -i+3*div(i,3) >= 0, [out_0]=funcA( ); [a_1(i,j)]=opd(out_0); end if -j+3*div(j,3) >= 0, d3 = div(i+1,2); if -i+2*d3-1 >= 0, d4 = div(j+1,2); if -j+2*d4-1 >= 0, d5 = div(2*d3+2,3); if -I+3*d5-3 >= 0, [in_0]=ipd(a_1(3*d5-3, 2*d4-1)); else %%if i-3*d5+2 >=0, [in_0]=ipd(a(i,j)); end end end [ ]=funcB(in_0); end end end

  5. Parse Tree of SAC for i=1:2:10 for j=1:2:10 if -i+3*div(i,3)>=0 if -j+3*div(j,3)>=0 d3=div(i+1,2) []=funcB(in_0) [out_0]=funcA() [a_1(i,j)]=opd(out_0) if -i+2*d3-1>=0 d4=div(j+1,2) if -j+2*d4-1>=0 d5=div(2*d3+2,3) if -i+3*d5-3>=0 if i-3*d5+2>=0 [in_0]=ipd(a_1(3*d5-3,2*d4-1)) [in_0]=ipd(a(i,j)) high dimension dense polytope lattice ?

  6. Lattice and Z-Polyhedron j j j i i Lattice L Z-Polyhedron Z i Polyhedron P P = { ( i , j )   | 1  i  6, 1  j  9 } L = { ( i , j )   | 2 i + 1, 2 j + 1 } Z = P  L Z = { ( 2 i + 1 , 2 j +1 ) | 0  2 i  5, 0  2 j  8 }

  7. Top-down Analysis <1> : For-loop j i for i = 1 : 2 : 10, for j = 1 : 2 : 10, for i = 1 : 1 : 10, for j = 1 : 1 : 10, d0 = div(i,2); if i-2*d0-1 >= 0, d1 = div(j,2); if j-2*d1-1 >= 0, for i = 1 : 1 : 10, for j = 1 : 1 : 10, if mod(i-1,2) == 0, if mod(j-1,2) == 0,

  8. Top-down Analysis <2> : for loop + “if” for i = 1 : 1 : 10, for j = 1 : 1 : 10, d0 = div(i,2); if i-2*d0-1 >= 0, d1 = div(j,2); if j-2*d1-1 >= 0, for i = 1 : 1 : 10, for j = 1 : 1 : 10, if mod(i-1,2) == 0, if mod(j-3,6) == 0, d2 = div(j,3); if -j+3*d2 >= 0,

  9. Top-down Analysis <3> Redundant! i j Domain of dependency: d3 = div(i+1,2); if -i+2*d3-1 >= 0, d4 = div(j+1,2); if -j+2*d4-1 >= 0, d5 = div(2*d3+2,3); if -i+3*d5-3 >= 0, [in_0] = ipd( a_1(3*d5-3, 2*d4-1) ); if mod(i-3,6) == 0, if mod(j+1,2) == 0, [in_0] =ipd(a_1(i,j));

  10. Top-down Analysis <4> : Put it together ? Redundant! for i = 1 : 1 : 10, for j = 1 : 1 : 10, if mod(i-1,2) == 0, if mod(j-3,6) == 0, if mod(i-3,6) == 0, if mod(j+1,2) == 0, [in_0]=ipd(a_1(i,j));

  11. Holy Cup Lattice Intersection for i = 1 : 1 : 10, for j = 1 : 1 : 10, if mod(i-3,6) == 0, if mod(j-3,6) == 0, [in_0]=ipd(a_1(i,j));

  12. How to get the lattice? lattice? for i = 1 : 1 : 10, for j = 1 : 1 : 10, d0 = div(i,2); if i-2*d0-1 >= 0, d1 = div(j,2); if j-2*d1-1 >= 0, d2 = div(j,3); if -j+3*d2 >= 0, d3 = div(i+1,2); if -i+2*d3-1 >= 0, d4 = div(j+1,2); if -j+2*d4-1 >= 0, d5 = div(2*d3+2,3); if -i+3*d5-3 >= 0, [in_0] = ipd( a_1(3*d5-3, 2*d4-1) ); else if i-3*d5+2 >= 0, [in_0] = ipd( a(i,j) ); end end end [] = funcB( in_0 ); end end end

  13. System of inequalities div if

  14. Solution Particular solution not in the null space • 1. N has a null space of dimension 2, so there exists 2 linearly independent vectors ( c1, c2 ) or C2 such that : N ( C2Kf ) == 0 • So, if is a solution, then + C2 Kf is also • a solution. • 2. Hermite Normal Form ( HNF ) • N C = [ H 0 ] => N [ C1 C2 ] =0 => N C2 Kf = 0 • So, I = C21 Kf + O

  15. Solution (cont.) So O=C11Kb Bounded by(*) & (**).

  16. Sum up • So, the lattice corresponding to the polytope is defined by: • I = C21 Kf + O & O = C11 Kb • b1 <= N C1 Kb <= b2 • Nq C1 Kb <= bq • In our example, • C21 = 6 0 & O = 9 • 0 6 3

  17. Else statement O= 9 ipd(a_1(i,j)) 3 O= 7 ipd(a(i,j)) 3 O= 5 ipd(a(i,j)) 3 … … d5 = div(2*d3+2,3); if -i+3*d5-3 >= 0, [in_0]=ipd(a_1(3*d5-3, 2*d4-1)); else %%if i-3*d5+2 >= 0, [in_0]=ipd(a(i,j)); end … …

  18. Altogether for i = 1 : 1 : 10, for j = 1 : 1 : 10, if mod(i-3,6) == 0, if mod(j-1,2) == 0, [out_0]=funcA(); [a_1(i,j)]=opd(out_0); if mod(j-3,6) == 0, if mod(i-3,6) == 0, [in_0]=ipd(a_1(i,j)); else if mod(i-5,6) == 0, [in_0]=ipd(a(i,j)); else if mod(i-7,6) == 0, [in_0]=ipd(a(i,j)); end [ ] = funcB(in_0); end end end

  19. Conclusion <1> • By introducing lattice, we can reduce the complexity of the program. The improvements are as follows: •  No control variables ; •  Less div and if statements ; •  The data dependency becomes explicit.

  20. Is that the whole story? d = div(i-3, 6); if i-3-6*d <= 0, • Observation : • We have to express those “mod”s with “div”s + “if”s : if mod(i-3, 6) == 0

  21. Further analysis Z-Polyhedron Polyhedral image ?

  22. Further analysis (cont.) Polyhedral preimage

  23. Further analysis (cont.) So, if we set O = [ -3 -3 ], which gives us the same system, we can express the mod with a div and a if: d = div(i+3, 6); if i+3-6*d <= 0, if mod(i+3, 6) == 0

  24. Conclusion <2> • Providing that the lattice is invertable, we can get a dense polyhedron by preimaging the Z-polyhedron. The integer points in the dense polyhedron have a one-to-one affine mapping to the integer points in the Z-polyhedron.

  25. Things to be done • 1. Compute the offset. Pip ? or … … • 2. Rewrite the program in a reduced form using lattice ; • 3. Testing.

  26. Thank you!

More Related