You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ch...@apache.org on 2017/12/29 12:27:21 UTC

ignite git commit: IGNITE-7097: performance measurement for SparseDistributedMatrix multiplication

Repository: ignite
Updated Branches:
  refs/heads/master 63a312518 -> 6efc4d9aa


IGNITE-7097: performance measurement for SparseDistributedMatrix multiplication

this closes #3241


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6efc4d9a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6efc4d9a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6efc4d9a

Branch: refs/heads/master
Commit: 6efc4d9aacb5ae71994b1bd4ac4bb4bc6765e5be
Parents: 63a3125
Author: Oleg Ignatenko <oi...@gridgain.com>
Authored: Fri Dec 29 15:27:10 2017 +0300
Committer: Yury Babak <yb...@gridgain.com>
Committed: Fri Dec 29 15:27:10 2017 +0300

----------------------------------------------------------------------
 .../impls/matrix/SparseDistributedMatrix.java   |  3 +
 .../yardstick/config/benchmark-ml.properties    |  2 +
 .../math/IgniteAbstractMatrixMulBenchmark.java  | 29 +++++---
 ...iteSparseDistributedMatrixMul2Benchmark.java | 74 ++++++++++++++++++++
 ...niteSparseDistributedMatrixMulBenchmark.java | 20 +++++-
 5 files changed, 117 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6efc4d9a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrix.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrix.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrix.java
index 3288724..026138b 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrix.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/impls/matrix/SparseDistributedMatrix.java
@@ -44,6 +44,9 @@ import org.apache.ignite.ml.math.impls.vector.SparseDistributedVector;
  * You also need to call {@link #destroy()} to remove the underlying cache when you no longer need this
  * matrix.</p>
  * <p>
+ * This class is not intended for fast calculations (for example, matrix multiplication). If better performance
+ * is needed, {@link SparseBlockDistributedMatrix} should be used instead.</p>
+ * <p>
  * <b>Currently fold supports only commutative operations.<b/></p>
  */
 public class SparseDistributedMatrix extends AbstractMatrix implements StorageConstants {

http://git-wip-us.apache.org/repos/asf/ignite/blob/6efc4d9a/modules/yardstick/config/benchmark-ml.properties
----------------------------------------------------------------------
diff --git a/modules/yardstick/config/benchmark-ml.properties b/modules/yardstick/config/benchmark-ml.properties
index 4867c0f..5992665 100644
--- a/modules/yardstick/config/benchmark-ml.properties
+++ b/modules/yardstick/config/benchmark-ml.properties
@@ -85,6 +85,8 @@ CONFIGS="\
 -cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteDenseLocalOffHeapMatrixMulBenchmark -sn IgniteNode -ds ${ver}dense-local-offheap-matrix-mul-${b}-backup,\
 -cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteSparseLocalMatrixMulBenchmark -sn IgniteNode -ds ${ver}sparse-local-matrix-mul-${b}-backup,\
 -cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteSparseBlockDistributedMatrixMulBenchmark -sn IgniteNode -ds ${ver}sparse-block-distributed-matrix-mul-${b}-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteSparseDistributedMatrixMulBenchmark -sn IgniteNode -ds ${ver}sparse-distributed-matrix-mul-${b}-backup,\
+-cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteSparseDistributedMatrixMul2Benchmark -sn IgniteNode -ds ${ver}sparse-distributed-matrix-mul2-${b}-backup,\
 -cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteColumnDecisionTreeVarianceBenchmark -sn IgniteNode -ds ${ver}column-decision-tree-variance-${b}-backup,\
 -cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteColumnDecisionTreeGiniBenchmark -sn IgniteNode -ds ${ver}column-decision-tree-gini-${b}-backup,\
 "

http://git-wip-us.apache.org/repos/asf/ignite/blob/6efc4d9a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteAbstractMatrixMulBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteAbstractMatrixMulBenchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteAbstractMatrixMulBenchmark.java
index 9921e36..6cb2200 100644
--- a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteAbstractMatrixMulBenchmark.java
+++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteAbstractMatrixMulBenchmark.java
@@ -26,11 +26,11 @@ import org.apache.ignite.yardstick.IgniteAbstractBenchmark;
 import org.apache.ignite.yardstick.ml.DataChanger;
 
 /**
- * Ignite benchmark that performs ML Grid operations.
+ * Ignite benchmark that performs ML Grid operations of matrix multiplication.
  */
 abstract class IgniteAbstractMatrixMulBenchmark extends IgniteAbstractBenchmark {
     /** */
-    private static final int SIZE = 1 << 8;
+    private static final int SIZE = 1 << 7;
 
     /** */
     private double[][] dataSquare = createAndFill(SIZE, SIZE);
@@ -58,9 +58,9 @@ abstract class IgniteAbstractMatrixMulBenchmark extends IgniteAbstractBenchmark
             @Override public void run() {
                 Matrix m1, m2, m3, m4, m5, m6;
 
-                Matrix m7 = (m1 = createAndFill(dataSquare, scale)).times((m2 = createAndFill(dataSquare, scale)));
-                Matrix m8 = (m3 = createAndFill(dataRect1, scale)).times((m4 = createAndFill(dataRect2, scale)));
-                Matrix m9 = (m5 = createAndFill(dataRect2, scale)).times((m6 = createAndFill(dataRect1, scale)));
+                Matrix m7 = times(m1 = createAndFill(dataSquare, scale), m2 = createAndFill(dataSquare, scale));
+                Matrix m8 = times(m3 = createAndFill(dataRect1, scale), m4 = createAndFill(dataRect2, scale));
+                Matrix m9 = times(m5 = createAndFill(dataRect2, scale), m6 = createAndFill(dataRect1, scale));
 
                 m1.destroy();
                 m2.destroy();
@@ -81,11 +81,24 @@ abstract class IgniteAbstractMatrixMulBenchmark extends IgniteAbstractBenchmark
         return true;
     }
 
-    /** Override in subclasses with specific type Matrix. */
+    /**
+     * Override in subclasses with specific type Matrix. Note that size of result matrix may be smaller than requested.
+     *
+     * @param rowSize Requested row size.
+     * @param colSize Requested column size.
+     * @return Matrix of desired type of size that doesn't exceed requested.
+     */
     abstract Matrix newMatrix(int rowSize, int colSize);
 
-    /** */
-    private Matrix createAndFill(double[][] data, double scale) {
+    /** Override in subclasses if needed. */
+    Matrix times(Matrix m1, Matrix m2) {
+        return m1.times(m2);
+    }
+
+    /** Override in subclasses if needed to account for smaller matrix size. */
+    Matrix createAndFill(double[][] data, double scale) {
+        // IMPL NOTE yardstick 0.8.3 fails to discover benchmark if we try to account for smaller size
+        //  matrix by using method with lambda parameter here: assign((row, col) -> data[row][col]).
         Matrix res = newMatrix(data.length, data[0].length).assign(data);
 
         for (int i = 0; i < data.length && i < data[0].length; i++)

http://git-wip-us.apache.org/repos/asf/ignite/blob/6efc4d9a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseDistributedMatrixMul2Benchmark.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseDistributedMatrixMul2Benchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseDistributedMatrixMul2Benchmark.java
new file mode 100644
index 0000000..e1afc34
--- /dev/null
+++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseDistributedMatrixMul2Benchmark.java
@@ -0,0 +1,74 @@
+/*
+ * 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.ignite.yardstick.ml.math;
+
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.impls.matrix.SparseBlockDistributedMatrix;
+import org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix;
+
+/**
+ * Ignite benchmark that performs trivially optimized matrix multiplication of {@link SparseDistributedMatrix} that
+ * uses delegating to {@link SparseBlockDistributedMatrix}. For unoptimized benchmark refer
+ * {@link IgniteSparseDistributedMatrixMulBenchmark}.
+ */
+@SuppressWarnings("unused")
+public class IgniteSparseDistributedMatrixMul2Benchmark extends IgniteAbstractMatrixMulBenchmark {
+    /** {@inheritDoc} */
+    @Override Matrix newMatrix(int rowSize, int colSize) {
+        return new SparseDistributedMatrix(rowSize, colSize,
+            StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Matrix times(Matrix m1, Matrix m2) {
+        return new OptimisedTimes(m1, m2).times();
+    }
+
+    /** */
+    private static class OptimisedTimes {
+        /** */
+        private final Matrix m1;
+
+        /** */
+        private final Matrix m2;
+
+        /** */
+        OptimisedTimes(Matrix m1, Matrix m2) {
+            this.m1 = m1;
+            this.m2 = m2;
+        }
+
+        /** */
+        Matrix times() {
+            Matrix m1Block = new SparseBlockDistributedMatrix(m1.rowSize(), m1.columnSize()).assign(m1);
+            Matrix m2Block = new SparseBlockDistributedMatrix(m2.rowSize(), m2.columnSize()).assign(m2);
+
+            Matrix m3Block = m1Block.times(m2Block);
+
+            Matrix res = new SparseDistributedMatrix(m3Block.rowSize(), m3Block.columnSize(),
+                StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE).assign(m3Block);
+
+            m1Block.destroy();
+            m2Block.destroy();
+            m3Block.destroy();
+
+            return res;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6efc4d9a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseDistributedMatrixMulBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseDistributedMatrixMulBenchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseDistributedMatrixMulBenchmark.java
index d02ce88..0f9d288 100644
--- a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseDistributedMatrixMulBenchmark.java
+++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseDistributedMatrixMulBenchmark.java
@@ -22,14 +22,28 @@ import org.apache.ignite.ml.math.StorageConstants;
 import org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix;
 
 /**
- * Ignite benchmark that performs ML Grid operations.
- * Todo: IGNITE-7097, complete implementation of this benchmark.
+ * Ignite benchmark that performs unoptimized matrix multiplication of {@link SparseDistributedMatrix}.
+ * For optimized benchmark refer {@link IgniteSparseBlockDistributedMatrixMulBenchmark}.
  */
 @SuppressWarnings("unused")
 public class IgniteSparseDistributedMatrixMulBenchmark extends IgniteAbstractMatrixMulBenchmark {
+    /** This benchmark is unacceptably slow without scaling down, see IGNITE-7097. */
+    private static final int SCALE_DOWN = 2;
+
     /** {@inheritDoc} */
     @Override Matrix newMatrix(int rowSize, int colSize) {
-        return new SparseDistributedMatrix(rowSize, colSize,
+        return new SparseDistributedMatrix(rowSize >> SCALE_DOWN, colSize >> SCALE_DOWN,
             StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
     }
+
+    /** {@inheritDoc} */
+    @Override Matrix createAndFill(double[][] data, double scale) {
+        Matrix res = newMatrix(data.length, data[0].length);
+
+        for (int row = 0; row < res.rowSize(); row++)
+            for (int col = 0; col < res.columnSize(); col++)
+                res.set(row, col, row == col ? data[row][col] * scale : data[row][col]);
+
+        return res;
+    }
 }