55import org .apache .sysds .common .Types .ExecMode ;
66import org .apache .sysds .common .Types .ExecType ;
77import org .apache .sysds .hops .OptimizerUtils ;
8+ import org .apache .sysds .hops .codegen .cplan .CNodeBinary ;
9+ import org .apache .sysds .performance .TimingUtils ;
810import org .apache .sysds .runtime .matrix .data .MatrixValue ;
911import org .apache .sysds .test .AutomatedTestBase ;
1012import org .apache .sysds .test .TestConfiguration ;
1315import org .junit .Test ;
1416
1517import java .io .File ;
18+ import java .io .FileWriter ;
19+ import java .io .IOException ;
20+ import java .io .PrintWriter ;
21+ import java .time .LocalDateTime ;
22+ import java .time .format .DateTimeFormatter ;
1623import java .util .HashMap ;
1724
1825public class TypicalExpressionTest extends AutomatedTestBase {
@@ -21,30 +28,106 @@ public class TypicalExpressionTest extends AutomatedTestBase {
2128
2229 private static final String TEST_NAME = "expression" ;
2330 private static final String TEST_NAME1 = TEST_NAME +"1" ;
31+ private static final String TEST_NAME2 = TEST_NAME +"2" ;
2432
2533 private static final String TEST_DIR = "performance/primitives/" ;
2634 private static final String TEST_CLASS_DIR = TEST_DIR + TypicalExpressionTest .class .getSimpleName () + "/" ;
2735 private final static String TEST_CONF = "SystemDS-config-codegen.xml" ;
2836 private final static File TEST_CONF_FILE = new File (SCRIPT_DIR + TEST_DIR , TEST_CONF );
2937
30- private final static int rows = 500 ;
31- private final static int cols = 1000 ;
3238 private final static double sparsity1 = 0.9 ;
3339 private final static double sparsity2 = 0.1 ;
3440 private final static double eps = 1e-8 ;
41+ private int rows = 500 ;
42+ private int cols = 1000 ;
43+ double [] sparsities = new double [] {1 , 0.3333 , 0.1111 , 0.0333 , 0.0111 , 0.0033 , 0.0011 };
44+ int warmupRuns = 100 ;
45+ int repetitions = 100 ;
3546
3647 @ Override
3748 public void setUp () {
3849 TestUtils .clearAssertionInformation ();
39- for (int i =1 ; i <=1 ; i ++)
50+ for (int i =1 ; i <=2 ; i ++)
4051 addTestConfiguration ( TEST_NAME +i , new TestConfiguration (TEST_CLASS_DIR , TEST_NAME +i , new String [] { String .valueOf (i ) }) );
4152 }
4253
4354 @ Test
44- public void testSparseNewImplCP () {runSparseExpression (TEST_NAME1 , true , true , ExecType .CP );}
55+ public void testSparseNewImpl1CP () {runSparseExpression (TEST_NAME1 , true , true , ExecType .CP );}
4556
4657 @ Test
47- public void testOldSparseImplCP () {runSparseExpression (TEST_NAME1 , true , false , ExecType .CP );}
58+ public void testOldSparseImpl1CP () {runSparseExpression (TEST_NAME1 , true , false , ExecType .CP );}
59+
60+ @ Test
61+ public void testSparseNewImpl2CP () {runSparseExpression (TEST_NAME2 , true , true , ExecType .CP );}
62+
63+ @ Test
64+ public void testOldSparseImpl2CP () {runSparseExpression (TEST_NAME2 , true , false , ExecType .CP );}
65+
66+ public static void main (String [] args ) {
67+ new TypicalExpressionTest ().runBenchmark (TEST_NAME2 );
68+ }
69+
70+ public void runBenchmark (String testname ) {
71+ setUp ();
72+ logResults (runPerfTest (testname , true , ExecType .CP ), true );
73+ logResults (runPerfTest (testname , false , ExecType .CP ), false );
74+ }
75+
76+ public void runBenchmark (String testname , int rows , int cols ) {
77+ setUp ();
78+ this .rows = rows ;
79+ this .cols = cols ;
80+ logResults (runPerfTest (testname , true , ExecType .CP ), true );
81+ logResults (runPerfTest (testname , false , ExecType .CP ), false );
82+ }
83+
84+ private String [] runPerfTest (String testname , boolean sparseRowVec , ExecType et ) {
85+
86+ ExecMode platformOld = setExecMode (et );
87+
88+ String [] resultTime = new String [sparsities .length ];
89+
90+ try {
91+
92+ getAndLoadTestConfiguration (testname );
93+
94+ String HOME = SCRIPT_DIR + TEST_DIR ;
95+ fullDMLScriptName = HOME + testname + ".dml" ;
96+ if (sparseRowVec )
97+ programArgs = new String []{"-explain" , "codegen" , "-sparseIntermediate" , "-args" ,
98+ input ("A" ), input ("B" ), input ("V" ), output ("S" )};
99+ else
100+ programArgs = new String []{"-explain" , "codegen" , "-args" ,
101+ input ("A" ), input ("B" ), input ("V" ), output ("S" )};
102+
103+
104+ fullRScriptName = HOME + TEST_NAME1 + ".R" ;
105+ rCmd = "Rscript" + " " + fullRScriptName + " " + inputDir () + " " + expectedDir ();
106+
107+ for (int i = 0 ; i < sparsities .length ; i ++) {
108+ //get a random matrix of values with
109+ double [][] A = getRandomMatrix (rows , cols , 1 , 31 , sparsities [i ], 1234 );
110+ double [][] B = getRandomMatrix (rows , cols , 1 , 31 , sparsities [i ], 5678 );
111+ double [][] V = getRandomMatrix (rows , 1 , 1 , 31 , sparsities [i ], 9876 );
112+ writeInputMatrixWithMTD ("A" , A , true );
113+ writeInputMatrixWithMTD ("B" , B , true );
114+ writeInputMatrixWithMTD ("V" , V , true );
115+
116+ TimingUtils .time (() -> runTest (true , false , null , -1 ), warmupRuns );
117+ double [] result = TimingUtils .time (() -> runTest (true , false , null , -1 ), repetitions );
118+
119+ resultTime [i ] = TimingUtils .stats (result ).split ("\\ +-" )[0 ];
120+
121+ }
122+
123+ }
124+ finally {
125+ resetExecMode (platformOld );
126+ OptimizerUtils .ALLOW_AUTO_VECTORIZATION = true ;
127+ OptimizerUtils .ALLOW_OPERATOR_FUSION = true ;
128+ }
129+ return resultTime ;
130+ }
48131
49132 private void runSparseExpression (String testname , boolean sparse , boolean sparseRowVec , ExecType et ) {
50133
@@ -55,7 +138,7 @@ private void runSparseExpression(String testname, boolean sparse, boolean sparse
55138 getAndLoadTestConfiguration (testname );
56139
57140 String HOME = SCRIPT_DIR + TEST_DIR ;
58- fullDMLScriptName = HOME + TEST_NAME1 + ".dml" ;
141+ fullDMLScriptName = HOME + testname + ".dml" ;
59142 if (sparseRowVec )
60143 programArgs = new String []{"-explain" , "codegen" , "-sparseIntermediate" , "-args" ,
61144 input ("A" ), input ("B" ), input ("V" ), output ("S" )};
@@ -92,6 +175,26 @@ private void runSparseExpression(String testname, boolean sparse, boolean sparse
92175
93176 }
94177
178+ public void logResults (String [] result , boolean sparseInterm ) {
179+ String currDate = LocalDateTime .now ().format (DateTimeFormatter .ofPattern ("ddMMyyyy_HHmmss" ));
180+ PrintWriter writer = null ;
181+ try {
182+ writer = new PrintWriter (new FileWriter ("C:\\ Users\\ tomok\\ OneDrive - Technische Universität Berlin\\ Bachelorarbeit\\ performance\\ expression_testing"
183+ + "expressionTest_" + currDate + "_" + (sparseInterm ? "sparseInterm" : "denseInterm" ) + "_" + ".csv" ));
184+ }
185+ catch (IOException e ) {
186+ throw new RuntimeException (e );
187+ }
188+ writer .printf ("%4$s Repetitions: %1$2s, rl: %2$2s, cl: %3$2s with %5$2s%n" , repetitions , rows , cols );
189+ writer .printf ("%1$2s;%2$2s;%3$2s;%4$2s%n" , "Sparsity" , "rows" , "cols" ,"time in ms" );
190+ for (int i = 0 ; i < sparsities .length ; i ++) {
191+ writer .printf ("%1$2s;%2$2s;%3$2s;%4$2s%n" , result [i ]);
192+ }
193+
194+ writer .flush ();
195+ writer .close ();
196+ }
197+
95198 /**
96199 * Override default configuration with custom test configuration to ensure
97200 * scratch space and local temporary directory locations are also updated.
0 commit comments