Repository: systemml Updated Branches: refs/heads/master 4de8d684f -> f516e4bdc
[SYSTEMML-1730] Fix correctness codegen vector primitives (abs, sm-div) Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/ea805c86 Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/ea805c86 Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/ea805c86 Branch: refs/heads/master Commit: ea805c863cacba4a4b8ac5c02d4fbf9154a93277 Parents: 4de8d68 Author: Matthias Boehm <[email protected]> Authored: Wed Jun 21 22:29:17 2017 -0700 Committer: Matthias Boehm <[email protected]> Committed: Wed Jun 21 22:29:17 2017 -0700 ---------------------------------------------------------------------- .../runtime/codegen/LibSpoofPrimitives.java | 13 ++++++------- .../sysml/runtime/matrix/data/LibMatrixMult.java | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/ea805c86/src/main/java/org/apache/sysml/runtime/codegen/LibSpoofPrimitives.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/codegen/LibSpoofPrimitives.java b/src/main/java/org/apache/sysml/runtime/codegen/LibSpoofPrimitives.java index 8e2b4b6..d9f20ef 100644 --- a/src/main/java/org/apache/sysml/runtime/codegen/LibSpoofPrimitives.java +++ b/src/main/java/org/apache/sysml/runtime/codegen/LibSpoofPrimitives.java @@ -228,7 +228,7 @@ public class LibSpoofPrimitives public static double[] vectDivWrite(double bval, double[] a, int ai, int len) { double[] c = allocVector(len, false); for( int j = 0; j < len; j++, ai++) - c[j] = bval / a[ai] / bval; + c[j] = bval / a[ai]; return c; } @@ -327,12 +327,11 @@ public class LibSpoofPrimitives //custom vector plus public static void vectPlusAdd(double[] a, double bval, double[] c, int ai, int ci, int len) { - for( int j = ai; j < ai+len; j++, ci++) - c[ci] += a[j] + bval; + LibMatrixMult.vectAdd(a, bval, c, ai, ci, len); } public static void vectPlusAdd(double bval, double[] a, double[] c, int ai, int ci, int len) { - vectPlusAdd(a, bval, c, ai, ci, len); + LibMatrixMult.vectAdd(a, bval, c, ai, ci, len); } public static void vectPlusAdd(double[] a, double bval, double[] c, int[] aix, int ai, int ci, int len) { @@ -610,20 +609,20 @@ public class LibSpoofPrimitives public static void vectAbsAdd(double[] a, double[] c, int[] aix, int ai, int ci, int len) { for( int j = ai; j < ai+len; j++ ) - c[ci + aix[j]] += Math.log(a[j]); + c[ci + aix[j]] += Math.abs(a[j]); } public static double[] vectAbsWrite(double[] a, int ai, int len) { double[] c = allocVector(len, false); for( int j = 0; j < len; j++, ai++) - c[j] = Math.log(a[ai]); + c[j] = Math.abs(a[ai]); return c; } public static double[] vectAbsWrite(double[] a, int[] aix, int ai, int len) { double[] c = allocVector(len, true); for( int j = ai; j < ai+len; j++ ) - c[aix[j]] = Math.log(a[j]); + c[aix[j]] = Math.abs(a[j]); return c; } http://git-wip-us.apache.org/repos/asf/systemml/blob/ea805c86/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixMult.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixMult.java b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixMult.java index f0f2196..0ed0090 100644 --- a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixMult.java +++ b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixMult.java @@ -3198,6 +3198,25 @@ public class LibMatrixMult } //note: public for use by codegen for consistency + public static void vectAdd( double[] a, double bval, double[] c, int ai, int ci, final int len ) { + final int bn = len%8; + //rest, not aligned to 8-blocks + for( int j = 0; j < bn; j++, ai++, ci++) + c[ ci ] += a[ ai ]; + //unrolled 8-block (for better ILP) + for( int j = bn; j < len; j+=8, ai+=8, ci+=8) { + c[ ci+0 ] += a[ ai+0 ] + bval; + c[ ci+1 ] += a[ ai+1 ] + bval; + c[ ci+2 ] += a[ ai+2 ] + bval; + c[ ci+3 ] += a[ ai+3 ] + bval; + c[ ci+4 ] += a[ ai+4 ] + bval; + c[ ci+5 ] += a[ ai+5 ] + bval; + c[ ci+6 ] += a[ ai+6 ] + bval; + c[ ci+7 ] += a[ ai+7 ] + bval; + } + } + + //note: public for use by codegen for consistency public static void vectAdd( double[] a, double[] c, int ai, int ci, final int len ) { final int bn = len%8;
