Skip to content

Commit a06ea0f

Browse files
committed
[SYSTEMDS-3832] MatrixBlock Append performance
This commit contains a new performance measuring script for appending matrices. See the PR for performance details Closes #2223
1 parent 52ca491 commit a06ea0f

File tree

6 files changed

+210
-43
lines changed

6 files changed

+210
-43
lines changed

src/test/java/org/apache/sysds/performance/Main.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.sysds.performance.generators.GenMatrices;
3232
import org.apache.sysds.performance.generators.IGenerate;
3333
import org.apache.sysds.performance.generators.MatrixFile;
34+
import org.apache.sysds.performance.matrix.MatrixAppend;
3435
import org.apache.sysds.performance.matrix.MatrixBinaryCellPerf;
3536
import org.apache.sysds.performance.matrix.MatrixMulPerformance;
3637
import org.apache.sysds.performance.matrix.MatrixReplacePerf;
@@ -135,6 +136,9 @@ private static void exec(int prog, String[] args) throws Exception {
135136
case 1007:
136137
Transform.main(args);
137138
break;
139+
case 1008:
140+
MatrixAppend.main(args);
141+
break;
138142
default:
139143
break;
140144
}

src/test/java/org/apache/sysds/performance/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,10 @@ transform encode
8989
```bash
9090
java -jar -agentpath:$HOME/Programs/profiler/lib/libasyncProfiler.so=start,event=cpu,file=temp/log.html -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1007
9191
```
92+
93+
94+
append matrix sequence
95+
96+
```bash
97+
./src/test/scripts/performance/append.sh
98+
```

src/test/java/org/apache/sysds/performance/TimingUtils.java

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,51 +32,26 @@ public interface TimingUtils {
3232

3333
/** A specification enum for the type of statistics to gather from the time measurements */
3434
public enum StatsType {
35-
MEAN_STD;
35+
MEAN_STD, MEAN_STD_Q1;
3636
}
3737

3838
/** The specified measurement to use in this case. Can be set from any of the programs */
39-
public static StatsType st = StatsType.MEAN_STD;
40-
41-
// /**
42-
// * Time the given function call
43-
// *
44-
// * @param f The function to execute
45-
// * @return The time it took
46-
// */
47-
// public static double time(F f) {
48-
// Timing time = new Timing(true);
49-
// f.run();
50-
// return time.stop();
51-
// }
52-
53-
// /**
54-
// * Time the function and print using the string given prepended.
55-
// *
56-
// * @param f The function to time
57-
// * @param p The print statement
58-
// */
59-
// public static void time(F f, String p) {
60-
// Timing time = new Timing(true);
61-
// f.run();
62-
// System.out.print(p);
63-
// System.out.println(time.stop());
64-
// }
39+
// public static StatsType st = StatsType.MEAN_STD;
6540

66-
/**
41+
/**
6742
* Time the function given assuming that it should put result into the given time array at index i.
6843
*
69-
* @param f The function to time
44+
* @param f The function to time
7045
* @param rep the number of repetitions
7146
*/
7247
public static double[] time(F f, int rep) {
7348
double[] times = new double[rep];
74-
for(int i = 0; i < rep; i ++)
49+
for(int i = 0; i < rep; i++)
7550
time(f, times, i);
76-
51+
7752
return times;
7853
}
79-
54+
8055
/**
8156
* Time the function given assuming that it should put result into the given time array at index i.
8257
*
@@ -116,14 +91,31 @@ public static double[] time(F f, F c, F b, int rep, IGenerate<?> bq) throws Inte
11691
}
11792

11893
/**
119-
* Calculate the statistics of the times executed The default is to calculate the mean and standard deviation and
120-
* return that as a string
94+
* Calculate the statistics of the times executed
95+
* <p>
96+
* The default is to calculate the mean and standard deviation and return that as a string
12197
*
122-
* @param v The times observed
98+
* @param v The times observed
99+
* @param st The type of stats to print
123100
* @return The status string.
124101
*/
125102
public static String stats(double[] v) {
103+
return statsMeanSTD(v);
104+
}
105+
106+
/**
107+
* Calculate the statistics of the times executed, given the stats type provided
108+
* <p>
109+
* The default is to calculate the mean and standard deviation and return that as a string
110+
*
111+
* @param v The times observed
112+
* @param st The type of stats to print
113+
* @return The status string.
114+
*/
115+
public static String stats(double[] v, StatsType st) {
126116
switch(st) {
117+
case MEAN_STD_Q1:
118+
return statsMeanSTDQ1(v);
127119
case MEAN_STD:
128120
default:
129121
return statsMeanSTD(v);
@@ -151,6 +143,32 @@ private static String statsMeanSTD(double[] v) {
151143
return String.format("%8.3f+-%7.3f ms", mean, std);
152144
}
153145

146+
private static String statsMeanSTDQ1(double[] v) {
147+
final int l = v.length;
148+
final int remove = (int) Math.floor(l * 0.05);
149+
Arrays.sort(v);
150+
151+
double q1 = v[v.length - 1 - (int) (Math.floor((double) v.length / 100))];
152+
double q2p5 = v[v.length - 1 - (int) (Math.floor((double) v.length / 40))];
153+
double q5 = v[v.length - 1 - (int) (Math.floor((double) v.length / 20))];
154+
double q10 = v[v.length - 1 - (int) (Math.floor((double) v.length / 10))];
155+
156+
double total = 0;
157+
final int el = v.length - remove * 2;
158+
for(int i = remove; i < l - remove; i++)
159+
total += v[i];
160+
161+
double mean = total / el;
162+
163+
double var = 0;
164+
for(int i = remove; i < l - remove; i++)
165+
var += Math.pow(Math.abs(v[i] - mean), 2);
166+
167+
double std = Math.sqrt(var / el);
168+
169+
return String.format("%8.3f+-%7.3f ms [q1:%7.3f, q2.5:%7.3f, q5:%7.3f, q10:%7.3f]", mean, std, q1, q2p5, q5, q10);
170+
}
171+
154172
/**
155173
* Interface method to enable timed calling from other Classes
156174
*/

src/test/java/org/apache/sysds/performance/compression/APerfTest.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.apache.sysds.performance.TimingUtils;
2525
import org.apache.sysds.performance.TimingUtils.F;
26+
import org.apache.sysds.performance.TimingUtils.StatsType;
2627
import org.apache.sysds.performance.generators.IGenerate;
2728

2829
public abstract class APerfTest<T, G> {
@@ -39,19 +40,27 @@ public abstract class APerfTest<T, G> {
3940
/** Warmup iterations */
4041
protected final int W;
4142

43+
/** The type of statistics to use */
44+
protected final StatsType st;
45+
4246
protected APerfTest(int N, IGenerate<G> gen) {
43-
ret = new ArrayList<>(N);
44-
this.gen = gen;
45-
this.N = N;
46-
this.W = 10;
47+
this(N, 10, gen, StatsType.MEAN_STD);
4748
}
4849

50+
protected APerfTest(int N, IGenerate<G> gen, StatsType st) {
51+
this(N, 10, gen, st);
52+
}
4953

5054
protected APerfTest(int N, int W, IGenerate<G> gen) {
55+
this(N, W, gen, StatsType.MEAN_STD);
56+
}
57+
58+
protected APerfTest(int N, int W, IGenerate<G> gen, StatsType st) {
5159
ret = new ArrayList<>(N);
5260
this.gen = gen;
5361
this.N = N;
54-
this.W = 10;
62+
this.W = W;
63+
this.st = st;
5564
}
5665

5766
protected void execute(F f, String name) throws InterruptedException {
@@ -70,7 +79,7 @@ protected void execute(F f, F c, F b, String name) throws InterruptedException {
7079
ret.clear();
7180
double[] times = TimingUtils.time(f, c, b, N, gen);
7281
String retS = makeResString(times);
73-
System.out.println(String.format("%35s, %s, %10s", name, TimingUtils.stats(times), retS));
82+
System.out.println(String.format("%35s, %s, %10s", name, TimingUtils.stats(times, st), retS));
7483
}
7584

7685
protected void warmup(F f, int n) throws InterruptedException {
@@ -92,7 +101,7 @@ protected void execute(F f, F c, F b, String name, int N) throws InterruptedExce
92101
ret.clear();
93102
double[] times = TimingUtils.time(f, c, b, N, gen);
94103
String retS = makeResString(times);
95-
System.out.println(String.format("%35s, %s, %10s", name, TimingUtils.stats(times), retS));
104+
System.out.println(String.format("%35s, %s, %10s", name, TimingUtils.stats(times, st), retS));
96105
}
97106

98107
protected abstract String makeResString();
@@ -106,7 +115,7 @@ public String toString() {
106115
StringBuilder sb = new StringBuilder();
107116
sb.append(String.format("%20s ", this.getClass().getSimpleName()));
108117
sb.append(" Repetitions: ").append(N).append("\n");
109-
sb.append(String.format("%20s ","Generator:"));
118+
sb.append(String.format("%20s ", "Generator:"));
110119
sb.append(gen);
111120
sb.append("\n");
112121
return sb.toString();
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.sysds.performance.matrix;
21+
22+
import org.apache.sysds.performance.TimingUtils.StatsType;
23+
import org.apache.sysds.performance.compression.APerfTest;
24+
import org.apache.sysds.performance.generators.ConstMatrix;
25+
import org.apache.sysds.performance.generators.GenMatrices;
26+
import org.apache.sysds.performance.generators.IGenerate;
27+
import org.apache.sysds.runtime.matrix.data.MatrixBlock;
28+
29+
public class MatrixAppend extends APerfTest<Object, MatrixBlock> {
30+
31+
final boolean cbind;
32+
33+
final MatrixBlock base;
34+
final MatrixBlock[] others;
35+
final int n;
36+
37+
public MatrixAppend(int N, int n, IGenerate<MatrixBlock> gen, boolean cbind) {
38+
super(N, 0, new ConstMatrix(gen.take()), StatsType.MEAN_STD_Q1);
39+
this.cbind = cbind;
40+
this.n = n;
41+
base = gen.take();
42+
43+
others = new MatrixBlock[n];
44+
for(int i = 0; i < n; i++) {
45+
others[i] = gen.take();
46+
}
47+
48+
}
49+
50+
public void run() throws Exception {
51+
52+
execute(() -> append(base, others), //
53+
String.format("appending: rows:%5d cols:%5d sp:%3.1f Blocks:%4d rep:%6d ", //
54+
base.getNumRows(), base.getNumColumns(), base.getSparsity(), n, N));
55+
56+
}
57+
58+
private void append(MatrixBlock a, MatrixBlock[] others) {
59+
a.append(others, null, cbind);
60+
}
61+
62+
@Override
63+
protected String makeResString() {
64+
return "";
65+
}
66+
67+
public static void main(String[] args) throws Exception {
68+
IGenerate<MatrixBlock> in;
69+
int nBlocks;
70+
int nRepeats;
71+
if(args.length == 0) {
72+
in = new GenMatrices(1000, 10, 10, 1.0);
73+
nBlocks = 10;
74+
nRepeats = 100;
75+
}
76+
else {
77+
in = new GenMatrices(Integer.parseInt(args[1]), Integer.parseInt(args[2]), 10, Double.parseDouble(args[3]));
78+
nBlocks = Integer.parseInt(args[4]);
79+
nRepeats = Integer.parseInt(args[5]);
80+
}
81+
in.generate(nBlocks + 2);
82+
83+
new MatrixAppend(nRepeats, nBlocks, in, false).run();
84+
}
85+
86+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
#-------------------------------------------------------------
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one
5+
# or more contributor license agreements. See the NOTICE file
6+
# distributed with this work for additional information
7+
# regarding copyright ownership. The ASF licenses this file
8+
# to you under the Apache License, Version 2.0 (the
9+
# "License"); you may not use this file except in compliance
10+
# with the License. You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing,
15+
# software distributed under the License is distributed on an
16+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
# KIND, either express or implied. See the License for the
18+
# specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
#-------------------------------------------------------------
22+
23+
mvn package > /dev/null
24+
java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 100 100 1.0 1 30000
25+
java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 1000 100 1.0 1 3000
26+
java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 1000 1000 1.0 1 3000
27+
java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 100 100 0.3 1 30000
28+
java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 1000 100 0.3 1 3000
29+
java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 1000 1000 0.3 1 3000
30+
31+
# java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 100 100 1.0 10 30000
32+
# java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 1000 100 1.0 10 3000
33+
# java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 1000 1000 1.0 10 1000
34+
# java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 100 100 0.3 10 30000
35+
# java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 1000 100 0.3 10 3000
36+
# java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 1000 1000 0.3 10 1000
37+
38+
# java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 100 100 1.0 100 3000
39+
# java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 1000 100 1.0 100 300
40+
# java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 1000 1000 1.0 100 200
41+
# java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 100 100 0.3 100 3000
42+
# java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 1000 100 0.3 100 2000
43+
# java -jar -XX:+UseNUMA target/systemds-3.3.0-SNAPSHOT-perf.jar 1008 1000 1000 0.3 100 1000

0 commit comments

Comments
 (0)