Skip to content

Commit

Permalink
[SYSTEMDS-3601] SchemaApplyPerfTests
Browse files Browse the repository at this point in the history
This commit extends the performance Jar for measuring internal functions.
In specific this commit adds functionality to measure bandwidth utilization
of individual operations.

Closes apache#1869
  • Loading branch information
Baunsgaard committed Aug 8, 2023
1 parent 89f2ad1 commit d5a49a1
Show file tree
Hide file tree
Showing 13 changed files with 1,457 additions and 286 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
<mainClass>org.apache.sysds.performance.Main</mainClass>
</manifest>
<manifestEntries>
<Class-Path>SystemDS.jar SystemDS-tests.jar</Class-Path>
<Class-Path>SystemDS.jar ${project.build.directory}/${project.artifactId}-${project.version}-tests.jar</Class-Path>
</manifestEntries>
</archive>
</configuration>
Expand Down
107 changes: 102 additions & 5 deletions src/test/java/org/apache/sysds/performance/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,114 @@

package org.apache.sysds.performance;

import org.apache.sysds.performance.compression.SteamCompressTest;
import org.apache.sysds.performance.compression.IOBandwidth;
import org.apache.sysds.performance.compression.SchemaTest;
import org.apache.sysds.performance.compression.Serialize;
import org.apache.sysds.performance.compression.StreamCompress;
import org.apache.sysds.performance.generators.ConstMatrix;
import org.apache.sysds.performance.generators.GenMatrices;
import org.apache.sysds.runtime.util.CommonThreadPool;

public class Main {

private static void exec(int prog, String[] args) throws InterruptedException, Exception {
switch(prog) {
case 1:
new StreamCompress(100, new GenMatrices(10000, 100, 32, 1.0)).run();
break;
case 2:
new SchemaTest(100, new GenMatrices(10000, 1000, 32, 1.0)).run();
break;
case 3:
new SchemaTest(100, new GenMatrices(1000, 1, 32, 1.0)).run();
new SchemaTest(100, new GenMatrices(1000, 10, 32, 1.0)).run();
new SchemaTest(100, new GenMatrices(1000, 100, 32, 1.0)).run();
new SchemaTest(100, new GenMatrices(1000, 1000, 32, 1.0)).run();
break;
case 4:
new SchemaTest(100, new GenMatrices(1000, 1000, 1, 1.0)).run();
new SchemaTest(100, new GenMatrices(1000, 1000, 2, 1.0)).run();
new SchemaTest(100, new GenMatrices(1000, 1000, 4, 1.0)).run();
new SchemaTest(100, new GenMatrices(1000, 1000, 8, 1.0)).run();
new SchemaTest(100, new GenMatrices(1000, 1000, 16, 1.0)).run();
new SchemaTest(100, new GenMatrices(1000, 1000, 32, 1.0)).run();
new SchemaTest(100, new GenMatrices(1000, 1000, 64, 1.0)).run();
new SchemaTest(100, new GenMatrices(1000, 1000, 128, 1.0)).run();
new SchemaTest(100, new GenMatrices(1000, 1000, 256, 1.0)).run();
new SchemaTest(100, new GenMatrices(1000, 1000, 512, 1.0)).run();
break;
case 5:
new SchemaTest(100, new ConstMatrix(1000, 100, 32, 1.0)).runCom();
break;
case 6:
new SchemaTest(100, new GenMatrices(1000, 1000, 32, 0.3)).run();
break;
case 7:
new SchemaTest(100, new ConstMatrix(1000, 1000, 32, 0.3)).runCom();
break;
case 8:
new IOBandwidth(100, new ConstMatrix(1000, 1000, 32, 1.0)).run();
break;
case 9:
run9(args);
break;
case 10:
run10(args);
break;
case 11:
run11(args, -1);
break;
case 12:
run11(args, Integer.parseInt(args[7]));
break;
default:
break;
}
}

private static void run9(String[] args) throws InterruptedException, Exception {
int rows = Integer.parseInt(args[1]);
int cols = Integer.parseInt(args[2]);
int unique = Integer.parseInt(args[3]);
double sparsity = Double.parseDouble(args[4]);
int k = Integer.parseInt(args[5]);
int n = Integer.parseInt(args[6]);
new IOBandwidth(n, new ConstMatrix(rows, cols, unique, sparsity), k).run();
}

private static void run10(String[] args) throws InterruptedException, Exception {
int rows = Integer.parseInt(args[1]);
int cols = Integer.parseInt(args[2]);
int unique = Integer.parseInt(args[3]);
double sparsity = Double.parseDouble(args[4]);
int k = Integer.parseInt(args[5]);
int n = Integer.parseInt(args[6]);
new IOBandwidth(n, new ConstMatrix(rows, cols, unique, sparsity), k).runVector();
}

private static void run11(String[] args, int id) throws InterruptedException, Exception {
int rows = Integer.parseInt(args[1]);
int cols = Integer.parseInt(args[2]);
int unique = Integer.parseInt(args[3]);
double sparsity = Double.parseDouble(args[4]);
int k = Integer.parseInt(args[5]);
int n = Integer.parseInt(args[6]);

Serialize s = new Serialize(n, new ConstMatrix(rows, cols, unique, sparsity), k);

if(id == -1)
s.run();
else
s.run(id);
}

public static void main(String[] args) {
try{
SteamCompressTest.P1();
try {
exec(Integer.parseInt(args[0]), args);
CommonThreadPool.get().shutdown();
}
catch(Exception e){
catch(Exception e) {
e.printStackTrace();

}
}
}
140 changes: 140 additions & 0 deletions src/test/java/org/apache/sysds/performance/TimingUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.sysds.performance;

import java.util.Arrays;

import org.apache.sysds.performance.generators.IGenerate;
import org.apache.sysds.runtime.controlprogram.parfor.stat.Timing;

/**
* Util methods for the Performance suite
*/
public interface TimingUtils {

/** A specification enum for the type of statistics to gather from the time measurements */
public enum StatsType {
MEAN_STD;
}

/** The specified measurement to use in this case. Can be set from any of the programs */
public static StatsType st = StatsType.MEAN_STD;

/**
* Time the given function call
*
* @param f The function to execute
* @return The time it took
*/
public static double time(F f) {
Timing time = new Timing(true);
f.run();
return time.stop();
}

/**
* Time the function and print using the string given prepended.
*
* @param f The function to time
* @param p The print statement
*/
public static void time(F f, String p) {
Timing time = new Timing(true);
f.run();
System.out.print(p);
System.out.println(time.stop());
}

/**
* Time the function given assuming that it should put result into the given time array at index i.
*
* @param f The function to time
* @param times The time array to put the time result into
* @param i The index to put it into
*/
public static void time(F f, double[] times, int i) {
Timing time = new Timing(true);
f.run();
times[i] = time.stop();
}

/**
* Time the given function a number of time using the generator to populate the input allocations without including
* it in the timing of the operation
*
* @param f The function to time
* @param rep The number of repetitions to make
* @param bq The generator for the input
* @return A list of the individual repetitions execution time
* @throws InterruptedException An exception in case the job gets interrupted
*/
public static double[] time(F f, int rep, IGenerate<?> bq) throws InterruptedException {
double[] times = new double[rep];
for(int i = 0; i < rep; i++) {
while(bq.isEmpty())
Thread.sleep(bq.defaultWaitTime());
time(f, times, i);
}
return times;
}

/**
* Calculate the statistics of the times executed The default is to calculate the mean and standard deviation and
* return that as a string
*
* @param v The times observed
* @return The status string.
*/
public static String stats(double[] v) {
switch(st) {
case MEAN_STD:
default:
return statsMeanSTD(v);
}
}

private static String statsMeanSTD(double[] v) {
final int l = v.length;
final int remove = (int) Math.floor((double) l * 0.05);
Arrays.sort(v);

double total = 0;
final int el = v.length - remove * 2;
for(int i = remove; i < l - remove; i++)
total += v[i];

double mean = total / el;

double var = 0;
for(int i = remove; i < l - remove; i++)
var += Math.pow(Math.abs(v[i] - mean), 2);

double std = Math.sqrt(var / el);

return String.format("%8.3f+-%7.3f ms", mean, std);
}

/**
* Interface method to enable timed calling from other Classes
*/
interface F {
void run();
}
}
74 changes: 0 additions & 74 deletions src/test/java/org/apache/sysds/performance/Util.java

This file was deleted.

Loading

0 comments on commit d5a49a1

Please sign in to comment.