// tiArray performance tester, Dan Bonachea public class arrperf { public static single void report(String desc, Timer t, int iters) { Ti.barrier(); if (Ti.thisProc() == 0) System.out.println(desc + ": " + t.micros()/iters + " us per iteration (" + t.secs() + " secs total)"); Ti.barrier(); } public static void arr1Gnoop(int [1d] arr) {} public static void arr1Lnoop(int [1d] local arr) {} public static void arr2Gnoop(int [2d] arr) {} public static void arr2Lnoop(int [2d] local arr) {} public static void arr3Gnoop(int [3d] arr) {} public static void arr3Lnoop(int [3d] local arr) {} public void noop() {} public void noopb(boolean b) {} int [1d] local tiarrL1; int [1d] tiarrG1; int [2d] local tiarrL2; int [2d] tiarrG2; int [3d] local tiarrL3; int [3d] tiarrG3; public static void main(String[]args) { int iters = 10000; if (args.length > 0) try { iters = Integer.parseInt(args[0]); } catch (Throwable exn) {} if (Ti.thisProc()==0) System.out.println("Running " + iters + " iterations of tiArray performance test..."); (new arrperf()).doit(iters); } public single local void doit(int iters) { Timer t = new Timer(); int [1d] tiarr1; int [2d] tiarr2; int [3d] tiarr3; #define TEST(msg, code) do { \ t.reset(); \ t.start(); \ for (int i=0; i < iters; i++) { \ code; \ } \ t.stop(); \ report(msg, t, iters); \ } while (false) //------------------------------------------------------------------------------------ // creation test RectDomain<1> rd1tiny = [[1]:[1]]; RectDomain<2> rd2tiny = [[1,1]:[1,1]]; RectDomain<3> rd3tiny = [[1,1,1]:[1,1,1]]; t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarr1 = new int[rd1tiny]; } t.stop(); report("small 1-d array creation", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarr2 = new int[rd2tiny]; } t.stop(); report("small 2-d array creation", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarr3 = new int[rd3tiny]; } t.stop(); report("small 3-d array creation", t, iters); //------------------------------------------------------------------------------------ // cast tiarrL1 = (int [1d] local) tiarr1; tiarrG1 = broadcast tiarrL1 from 0; tiarrG1 = tiarrL1; tiarrL2 = (int [2d] local) tiarr2; tiarrG2 = broadcast tiarrL2 from 0; tiarrG2 = tiarrL2; tiarrL3 = (int [3d] local) tiarr3; tiarrG3 = broadcast tiarrL3 from 0; tiarrG3 = tiarrL3; t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarrG1 = tiarrL1; //arr1Gnoop(tiarrG1); noop(); } t.stop(); report("small 1-d array cast local->global", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarrL1 = (int [1d] local)tiarrG1; //arr1Lnoop(tiarrL1); noop(); } t.stop(); report("small 1-d array cast global->local", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarrG2 = tiarrL2; //arr2Gnoop(tiarrG2); noop(); } t.stop(); report("small 2-d array cast local->global", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarrL2 = (int [2d] local)tiarrG2; //arr2Lnoop(tiarrL2); noop(); } t.stop(); report("small 2-d array cast global->local", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarrG3 = tiarrL3; //arr3Gnoop(tiarrG3); noop(); } t.stop(); report("small 3-d array cast local->global", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarrL3 = (int [3d] local)tiarrG3; //arr3Lnoop(tiarrL3); noop(); } t.stop(); report("small 3-d array cast global->local", t, iters); //------------------------------------------------------------------------------------ // isnull t.reset(); t.start(); for (int i=0; i < iters; i++) { noopb(tiarrL1 == null); } t.stop(); report("1-d local array isnull ", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { noopb(tiarrG1 == null); } t.stop(); report("1-d global array isnull", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { noopb(tiarrL2 == null); } t.stop(); report("2-d local array isnull ", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { noopb(tiarrG2 == null); } t.stop(); report("2-d global array isnull", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { noopb(tiarrL3 == null); } t.stop(); report("3-d local array isnull ", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { noopb(tiarrG3 == null); } t.stop(); report("3-d global array isnull", t, iters); //------------------------------------------------------------------------------------ // slice int [][1d] junk1 = new int[iters][1d]; int [2d] tiarr2x = new int[[0,0]:[iters,0]]; t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarr1 = tiarr2x.slice(1,i); junk1[i] = tiarr1; // defeat lifting opt } t.stop(); report("2-d array slice", t, iters); int [][2d] junk2 = new int[iters][2d]; int [3d] tiarr3x = new int[[0,0,0]:[iters,0,0]]; t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarr2 = tiarr3x.slice(1,i); junk2[i] = tiarr2; // defeat lifting opt } t.stop(); report("3-d array slice", t, iters); //------------------------------------------------------------------------------------ // set TEST("1-d local array set(0)", tiarrL1.set(0)); TEST("1-d global array set(0)", tiarrG1.set(0)); TEST("2-d local array set(0)", tiarrL2.set(0)); TEST("2-d global array set(0)", tiarrG2.set(0)); TEST("3-d local array set(0)", tiarrL3.set(0)); TEST("3-d global array set(0)", tiarrG3.set(0)); //------------------------------------------------------------------------------------ // small contiguous copy int [1d] tiarr1a = new int[rd1tiny]; int [2d] tiarr2a = new int[rd2tiny]; int [3d] tiarr3a = new int[rd3tiny]; int [1d] tiarr1b = new int[rd1tiny]; int [2d] tiarr2b = new int[rd2tiny]; int [3d] tiarr3b = new int[rd3tiny]; int [1d] tiarr1c = new int[rd1tiny+[4]]; int [2d] tiarr2c = new int[rd2tiny+[4,4]]; int [3d] tiarr3c = new int[rd3tiny+[4,4,4]]; RectDomain<1> rd1tiny2 = [[0]:[4]]; RectDomain<2> rd2tiny2 = [[1,0]:[1,4]]; RectDomain<3> rd3tiny2 = [[1,1,0]:[1,1,4]]; int [1d] tiarr1d = new int[rd1tiny2]; int [2d] tiarr2d = new int[rd2tiny2]; int [3d] tiarr3d = new int[rd3tiny2]; t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarr1a.copy(tiarr1b); } t.stop(); report("small complete contiguous local 1-d array copy", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarr2a.copy(tiarr2b); } t.stop(); report("small complete contiguous local 2-d array copy", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarr3a.copy(tiarr3b); } t.stop(); report("small complete contiguous local 3-d array copy", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarr1a.copy(tiarr1d); } t.stop(); report("small incomplete contiguous local 1-d array copy", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarr2a.copy(tiarr2d); } t.stop(); report("small incomplete contiguous local 2-d array copy", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarr3a.copy(tiarr3d); } t.stop(); report("small incomplete contiguous local 3-d array copy", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarr1a.copy(tiarr1c); } t.stop(); report("small empty local 1-d array copy", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarr2a.copy(tiarr2c); } t.stop(); report("small empty local 2-d array copy", t, iters); t.reset(); t.start(); for (int i=0; i < iters; i++) { tiarr3a.copy(tiarr3c); } t.stop(); report("small empty local 3-d array copy", t, iters); //------------------------------------------------------------------------------------ // small non-contiguous copy RectDomain<1> rd1small1 = [[1]:[64]]; RectDomain<2> rd2small1 = [[1,1]:[8,8]]; RectDomain<3> rd3small1 = [[1,1,1]:[4,4,4]]; RectDomain<1> rd1small2 = [[1]:[64]:[8]]; RectDomain<2> rd2small2 = [[1,1]:[8,8]:[4,2]]; RectDomain<3> rd3small2 = [[1,1,1]:[4,4,4]:[2,2,2]]; RectDomain<1> rd1smallb1 = [[8]:[12]]; RectDomain<2> rd2smallb1 = [[2,1]:[6,1]]; RectDomain<2> rd2smallb2 = [[1,2]:[1,6]]; RectDomain<3> rd3smallb1 = [[1,1,1]:[4,1,1]]; RectDomain<3> rd3smallb2 = [[1,1,1]:[1,4,1]]; RectDomain<3> rd3smallb3 = [[1,1,1]:[1,1,4]]; int [1d] tiarr1s1 = new int[rd1small1]; int [2d] tiarr2s1 = new int[rd2small1]; int [3d] tiarr3s1 = new int[rd3small1]; int [1d] tiarr1s2 = new int[rd1small2]; int [2d] tiarr2s2 = new int[rd2small2]; int [3d] tiarr3s2 = new int[rd3small2]; int [1d] tiarr1b1 = new int[rd1smallb1]; int [2d] tiarr2b1 = new int[rd2smallb1]; int [2d] tiarr2b2 = new int[rd2smallb2]; int [3d] tiarr3b1 = new int[rd3smallb1]; int [3d] tiarr3b2 = new int[rd3smallb2]; int [3d] tiarr3b3 = new int[rd3smallb3]; TEST("non-contiguous local 1-d array copy fwd", tiarr1s1.copy(tiarr1s2)); TEST("non-contiguous local 1-d array copy rev", tiarr1s2.copy(tiarr1s1)); TEST("non-contiguous local 2-d array copy fwd", tiarr2s1.copy(tiarr2s2)); TEST("non-contiguous local 2-d array copy rev", tiarr2s2.copy(tiarr2s1)); TEST("non-contiguous local 3-d array copy fwd", tiarr3s1.copy(tiarr3s2)); TEST("non-contiguous local 3-d array copy rev", tiarr3s2.copy(tiarr3s1)); TEST("contiguous local border 1-d array copy", tiarr1b1.copy(tiarr1s1)); TEST("non-contiguous local border 2-d array copy", tiarr2b1.copy(tiarr2s1)); TEST("contiguous local border 2-d array copy", tiarr2b2.copy(tiarr2s1)); TEST("non-contiguous local border 3-d array copy", tiarr3b1.copy(tiarr3s1)); TEST("non-contiguous local border 3-d array copy", tiarr3b2.copy(tiarr3s1)); TEST("contiguous local border 3-d array copy", tiarr3b3.copy(tiarr3s1)); }}