This is an automated email from the ASF dual-hosted git repository.

baunsgaard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git


The following commit(s) were added to refs/heads/main by this push:
     new bbdbb1a781 [MINOR] Append perf
bbdbb1a781 is described below

commit bbdbb1a7814d58da15cdd0bd35a08811a635d869
Author: Sebastian Baunsgaard <[email protected]>
AuthorDate: Thu Apr 4 18:08:27 2024 +0200

    [MINOR] Append perf
    
    This commit adds a perf script for MCSR appending.
    It is manly ment as an example of how to execute a perf script.
    
    ````
    Me:~/github/systemds$ java -jar target/systemds-3.3.0-SNAPSHOT-perf.jar 
1004 1000 100000
    Appending rep: 1000 of 100000 distinct append calls (including random and 
allocations)
    Append all dense:             4.262+-  0.164 ms
    Append all zero on empty:     0.198+-  0.004 ms
    Append all zero on Scalar:    0.197+-  0.004 ms
    Append all zero on Array:     0.203+-  0.013 ms
    Append half zero on Array:    4.422+-  0.170 ms
    ```
    
    Closes #2011
---
 .../apache/sysds/runtime/data/SparseBlockMCSR.java |  5 +-
 .../java/org/apache/sysds/performance/Main.java    |  8 ++
 .../java/org/apache/sysds/performance/README.md    | 10 +--
 .../org/apache/sysds/performance/TimingUtils.java  | 14 ++++
 .../performance/matrix/MatrixMulPerformance.java   |  4 +-
 .../sysds/performance/matrix/SparseAppend.java     | 89 ++++++++++++++++++++++
 6 files changed, 121 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/sysds/runtime/data/SparseBlockMCSR.java 
b/src/main/java/org/apache/sysds/runtime/data/SparseBlockMCSR.java
index 025da10394..52b5d2e338 100644
--- a/src/main/java/org/apache/sysds/runtime/data/SparseBlockMCSR.java
+++ b/src/main/java/org/apache/sysds/runtime/data/SparseBlockMCSR.java
@@ -378,12 +378,13 @@ public class SparseBlockMCSR extends SparseBlock
        
        @Override
        public final void append(final int r, final int c, final double v) {
+               // Perf verified in java -jar 
target/systemds-3.3.0-SNAPSHOT-perf.jar 1004 1000 100000
                if(v == 0)
                        return;
                else if(_rows[r] == null)
                        _rows[r] = new SparseRowScalar(c, v);
-               else 
-                       _rows[r] = _rows[r].append(c, v); 
+               else
+                       _rows[r] = _rows[r].append(c, v);
        }
 
        @Override
diff --git a/src/test/java/org/apache/sysds/performance/Main.java 
b/src/test/java/org/apache/sysds/performance/Main.java
index 2fed0d7144..9959192188 100644
--- a/src/test/java/org/apache/sysds/performance/Main.java
+++ b/src/test/java/org/apache/sysds/performance/Main.java
@@ -32,6 +32,7 @@ import org.apache.sysds.performance.generators.IGenerate;
 import org.apache.sysds.performance.generators.MatrixFile;
 import org.apache.sysds.performance.matrix.MatrixMulPerformance;
 import org.apache.sysds.performance.matrix.MatrixStorage;
+import org.apache.sysds.performance.matrix.SparseAppend;
 import org.apache.sysds.runtime.data.SparseBlock;
 import org.apache.sysds.runtime.frame.data.FrameBlock;
 import org.apache.sysds.runtime.matrix.data.MatrixBlock;
@@ -115,6 +116,9 @@ public class Main {
                        case 1003:
                                run1003(args);
                                break;
+                       case 1004:
+                               run1004(args);
+                               break;
                        default:
                                break;
                }
@@ -319,6 +323,10 @@ public class Main {
                ms.testBalancedDims(SparseBlock.Type.DCSR, sparsity, 
numEntries, resolution, maxRowColRatio, repetitions);
        }
 
+       private static void run1004(String[] args){
+               new SparseAppend(args);
+       }
+
        public static void main(String[] args) {
                try {
                        exec(Integer.parseInt(args[0]), args);
diff --git a/src/test/java/org/apache/sysds/performance/README.md 
b/src/test/java/org/apache/sysds/performance/README.md
index 7e7edbb805..7129757f34 100644
--- a/src/test/java/org/apache/sysds/performance/README.md
+++ b/src/test/java/org/apache/sysds/performance/README.md
@@ -28,7 +28,7 @@ mvn package
 Example of running it:
 
 ```bash
-java -jar target/systemds-3.2.0-SNAPSHOT-perf.jar 1
+java -jar target/systemds-3.3.0-SNAPSHOT-perf.jar 1
 ```
 
 example result of the above job:
@@ -49,24 +49,24 @@ Running Steam Compression Test
 With profiler:
 
 ```bash
-java -jar 
-agentpath:$HOME/Programs/profiler/lib/libasyncProfiler.so=start,event=cpu,file=temp/log.html
 target/systemds-3.2.0-SNAPSHOT-perf.jar 12 10000 100 4 1.0 16 1000 -1
+java -jar 
-agentpath:$HOME/Programs/profiler/lib/libasyncProfiler.so=start,event=cpu,file=temp/log.html
 target/systemds-3.3.0-SNAPSHOT-perf.jar 12 10000 100 4 1.0 16 1000 -1
 ```
 
 Take a Matrix and perform serialization
 
 ```bash 
-java -jar 
-agentpath:$HOME/Programs/profiler/lib/libasyncProfiler.so=start,event=cpu,file=temp/log.html
 target/systemds-3.2.0-SNAPSHOT-perf.jar 13 16 100 "temp/test.csv" -1
+java -jar 
-agentpath:$HOME/Programs/profiler/lib/libasyncProfiler.so=start,event=cpu,file=temp/log.html
 target/systemds-3.3.0-SNAPSHOT-perf.jar 13 16 100 "temp/test.csv" -1
 ```
 
 Take a Frame and transform into a Matrix and perform serialization.
 
 ```bash 
-java -jar 
-agentpath:$HOME/Programs/profiler/lib/libasyncProfiler.so=start,event=cpu,file=temp/log.html
 target/systemds-3.2.0-SNAPSHOT-perf.jar 14 16 1000 
"src/test/resources/datasets/titanic/titanic.csv" 
"src/test/resources/datasets/titanic/tfspec.json" -1
+java -jar 
-agentpath:$HOME/Programs/profiler/lib/libasyncProfiler.so=start,event=cpu,file=temp/log.html
 target/systemds-3.3.0-SNAPSHOT-perf.jar 14 16 1000 
"src/test/resources/datasets/titanic/titanic.csv" 
"src/test/resources/datasets/titanic/tfspec.json" -1
 ```
 
 Frame Operation timings
 
 ```bash
-java -jar 
-agentpath:$HOME/Programs/profiler/lib/libasyncProfiler.so=start,event=cpu,file=temp/log.html
 target/systemds-3.2.0-SNAPSHOT-perf.jar 15 16 10 
"src/test/resources/datasets/titanic/titanic.csv" 
"src/test/resources/datasets/titanic/tfspec.json"
+java -jar 
-agentpath:$HOME/Programs/profiler/lib/libasyncProfiler.so=start,event=cpu,file=temp/log.html
 target/systemds-3.3.0-SNAPSHOT-perf.jar 15 16 10 
"src/test/resources/datasets/titanic/titanic.csv" 
"src/test/resources/datasets/titanic/tfspec.json"
 ```
 
diff --git a/src/test/java/org/apache/sysds/performance/TimingUtils.java 
b/src/test/java/org/apache/sysds/performance/TimingUtils.java
index 0faf01c9b0..7d055d9afc 100644
--- a/src/test/java/org/apache/sysds/performance/TimingUtils.java
+++ b/src/test/java/org/apache/sysds/performance/TimingUtils.java
@@ -63,6 +63,20 @@ public interface TimingUtils {
        // 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 rep the number of repetitions
+        */
+       public static double[] time(F f, int rep) {
+               double[] times = new double[rep];
+               for(int i = 0; i < rep; i ++)
+                       time(f, times, i);
+               
+               return times;
+       }
+       
        /**
         * Time the function given assuming that it should put result into the 
given time array at index i.
         * 
diff --git 
a/src/test/java/org/apache/sysds/performance/matrix/MatrixMulPerformance.java 
b/src/test/java/org/apache/sysds/performance/matrix/MatrixMulPerformance.java
index 05b91d0ebe..fea49cfb72 100644
--- 
a/src/test/java/org/apache/sysds/performance/matrix/MatrixMulPerformance.java
+++ 
b/src/test/java/org/apache/sysds/performance/matrix/MatrixMulPerformance.java
@@ -19,6 +19,8 @@
 
 package org.apache.sysds.performance.matrix;
 
+import java.util.Arrays;
+
 import org.apache.sysds.runtime.data.SparseBlock;
 import org.apache.sysds.runtime.data.SparseBlockCOO;
 import org.apache.sysds.runtime.data.SparseBlockCSR;
@@ -29,8 +31,6 @@ import org.apache.sysds.runtime.matrix.data.MatrixBlock;
 import org.apache.sysds.runtime.util.DataConverter;
 import org.apache.sysds.test.TestUtils;
 
-import java.util.Arrays;
-
 public class MatrixMulPerformance {
 
        private final int _rl;
diff --git 
a/src/test/java/org/apache/sysds/performance/matrix/SparseAppend.java 
b/src/test/java/org/apache/sysds/performance/matrix/SparseAppend.java
new file mode 100644
index 0000000000..7930fd3275
--- /dev/null
+++ b/src/test/java/org/apache/sysds/performance/matrix/SparseAppend.java
@@ -0,0 +1,89 @@
+package org.apache.sysds.performance.matrix;
+
+import java.util.Random;
+
+import org.apache.sysds.performance.TimingUtils;
+import org.apache.sysds.runtime.data.SparseBlockMCSR;
+
+public class SparseAppend {
+
+       public SparseAppend(String[] args) {
+               // Ignore args 1 it is containing the Id to run this test.
+
+               final int rep = Integer.parseInt(args[1]);
+               final int size = Integer.parseInt(args[2]);
+               final Random r = new Random(42);
+
+               System.out.println("Appending rep: " + rep + " of " + size + " 
distinct append calls (including random and allocations)");
+               double[] times;
+               // Warmup 
+               times = TimingUtils.time(() -> {
+                       SparseBlockMCSR sb = new SparseBlockMCSR(100);
+                       for(int i = 0; i < size; i++) {
+                               sb.append(i % 100, i, r.nextDouble());
+                       }
+               }, rep);
+
+               times = TimingUtils.time(() -> {
+                       SparseBlockMCSR sb = new SparseBlockMCSR(100);
+                       for(int i = 0; i < size; i++) {
+                               sb.append(i % 100, i, r.nextDouble());
+                       }
+               }, rep);
+
+               System.out.println("Append all dense:          " + 
TimingUtils.stats(times));
+
+               times = TimingUtils.time(() -> {
+                       SparseBlockMCSR sb = new SparseBlockMCSR(100);
+                       for(int i = 0; i < size; i++) {
+                               sb.append(i % 100, i, 0);
+                       }
+               }, rep);
+
+               System.out.println("Append all zero on empty:  " + 
TimingUtils.stats(times));
+
+               times = TimingUtils.time(() -> {
+                       SparseBlockMCSR sb = new SparseBlockMCSR(100);
+                       for(int i = 0; i < 100; i ++){
+                               sb.append(i, i, 1);
+                       }
+                       for(int i = 0; i < size; i++) {
+                               sb.append(i % 100, i, 0);
+                       }
+               }, rep);
+
+               System.out.println("Append all zero on Scalar: " + 
TimingUtils.stats(times));
+
+               times = TimingUtils.time(() -> {
+                       SparseBlockMCSR sb = new SparseBlockMCSR(100);
+                       for(int i = 0; i < 100; i ++){
+                               sb.append(i, i, 1);
+                               sb.append(i, i, 1);
+                       }
+                       for(int i = 0; i < size; i++) {
+                               sb.append(i % 100, i, 0);
+                       }
+               }, rep);
+
+               System.out.println("Append all zero on Array:  " + 
TimingUtils.stats(times));
+
+               times = TimingUtils.time(() -> {
+                       SparseBlockMCSR sb = new SparseBlockMCSR(100);
+                       for(int i = 0; i < 100; i ++){
+                               sb.append(i, i, 1);
+                               sb.append(i, i, 1);
+                       }
+                       for(int i = 0; i < size; i++) {
+                               double d = r.nextDouble();
+                               d = d > 0.5 ? d : 0;
+                               sb.append(i % 100, i, d);
+                       }
+               }, rep);
+
+               System.out.println("Append half zero on Array: " + 
TimingUtils.stats(times));
+       }
+
+       public static void main(String[] args) {
+               new SparseAppend(new String[] {"1004", "10000", "10000"});
+       }
+}

Reply via email to