From f6c3ccec8538c747de70c5dc1d236311740ea3cb Mon Sep 17 00:00:00 2001 From: Frxms Date: Tue, 21 Jan 2025 18:18:21 +0100 Subject: [PATCH 1/6] implement new colProd and rowProd tests make tests runnable test rowProd and colPord add operators to test implement denseColProd and denseRowProd. Sparsity not yet fully implemented and tested set PROD as supported ROW and COL aggregation functions so that hops and lops can be turned into SpoofFused operators correct function fix lnnz value new test matrix input minor adjustments new test types delete todo fix executeSparseColRowProd() debug executeSparseColRowProd() performance improvement colProd change fix transpose in tests lnnz fix new tests rewrite to a more readable code thorough test make tests readable final adjustments and debugging --- .../hops/codegen/template/TemplateCell.java | 2 +- .../hops/codegen/template/TemplateRow.java | 2 +- .../sysds/runtime/codegen/SpoofCellwise.java | 219 +++++++++++++++++- .../functions/codegen/CellwiseTmplTest.java | 18 +- .../functions/codegen/cellwisetmpl28.R | 38 +++ .../functions/codegen/cellwisetmpl28.dml | 32 +++ .../functions/codegen/cellwisetmpl29.R | 38 +++ .../functions/codegen/cellwisetmpl29.dml | 32 +++ 8 files changed, 375 insertions(+), 6 deletions(-) create mode 100644 src/test/scripts/functions/codegen/cellwisetmpl28.R create mode 100644 src/test/scripts/functions/codegen/cellwisetmpl28.dml create mode 100644 src/test/scripts/functions/codegen/cellwisetmpl29.R create mode 100644 src/test/scripts/functions/codegen/cellwisetmpl29.dml diff --git a/src/main/java/org/apache/sysds/hops/codegen/template/TemplateCell.java b/src/main/java/org/apache/sysds/hops/codegen/template/TemplateCell.java index 8d0dc273eb3..c909d86cd18 100644 --- a/src/main/java/org/apache/sysds/hops/codegen/template/TemplateCell.java +++ b/src/main/java/org/apache/sysds/hops/codegen/template/TemplateCell.java @@ -66,7 +66,7 @@ public class TemplateCell extends TemplateBase { private static final AggOp[] SUPPORTED_AGG = - new AggOp[]{AggOp.SUM, AggOp.SUM_SQ, AggOp.MIN, AggOp.MAX}; + new AggOp[]{AggOp.SUM, AggOp.SUM_SQ, AggOp.MIN, AggOp.MAX, AggOp.PROD}; public TemplateCell() { super(TemplateType.CELL); diff --git a/src/main/java/org/apache/sysds/hops/codegen/template/TemplateRow.java b/src/main/java/org/apache/sysds/hops/codegen/template/TemplateRow.java index 4ac38b1487c..c42ea6c8580 100644 --- a/src/main/java/org/apache/sysds/hops/codegen/template/TemplateRow.java +++ b/src/main/java/org/apache/sysds/hops/codegen/template/TemplateRow.java @@ -67,7 +67,7 @@ public class TemplateRow extends TemplateBase { - private static final AggOp[] SUPPORTED_ROW_AGG = new AggOp[]{AggOp.SUM, AggOp.MIN, AggOp.MAX, AggOp.MEAN}; + private static final AggOp[] SUPPORTED_ROW_AGG = new AggOp[]{AggOp.SUM, AggOp.MIN, AggOp.MAX, AggOp.MEAN, AggOp.PROD}; private static final OpOp1[] SUPPORTED_VECT_UNARY = new OpOp1[]{ OpOp1.EXP, OpOp1.SQRT, OpOp1.LOG, OpOp1.ABS, OpOp1.ROUND, OpOp1.CEIL, OpOp1.FLOOR, OpOp1.SIGN, OpOp1.SIN, OpOp1.COS, OpOp1.TAN, OpOp1.ASIN, OpOp1.ACOS, OpOp1.ATAN, OpOp1.SINH, OpOp1.COSH, OpOp1.TANH, diff --git a/src/main/java/org/apache/sysds/runtime/codegen/SpoofCellwise.java b/src/main/java/org/apache/sysds/runtime/codegen/SpoofCellwise.java index 6c3986bd93c..d59f50a0e85 100644 --- a/src/main/java/org/apache/sysds/runtime/codegen/SpoofCellwise.java +++ b/src/main/java/org/apache/sysds/runtime/codegen/SpoofCellwise.java @@ -84,6 +84,7 @@ public enum AggOp { SUM_SQ, MIN, MAX, + PROD } protected final CellType _type; @@ -332,12 +333,16 @@ private long executeDense(DenseBlock a, SideInput[] b, double[] scalars, else if( _type == CellType.ROW_AGG ) { if( _aggOp == AggOp.SUM || _aggOp == AggOp.SUM_SQ ) return executeDenseRowAggSum(a, lb, scalars, c, m, n, sparseSafe, rl, ru, rix); + else if(_aggOp == AggOp.PROD) + return executeDenseRowProd(a, lb, scalars, c, m, n, sparseSafe, rl, ru, rix); else return executeDenseRowAggMxx(a, lb, scalars, c, m, n, sparseSafe, rl, ru, rix); } else if( _type == CellType.COL_AGG ) { if( _aggOp == AggOp.SUM || _aggOp == AggOp.SUM_SQ ) return executeDenseColAggSum(a, lb, scalars, c, m, n, sparseSafe, rl, ru, rix); + else if(_aggOp == AggOp.PROD) + return executeDenseColProd(a, lb, scalars, c, m, n, sparseSafe, rl, ru, rix); else return executeDenseColAggMxx(a, lb, scalars, c, m, n, sparseSafe, rl, ru, rix); } @@ -372,12 +377,16 @@ private long executeSparse(SparseBlock sblock, SideInput[] b, double[] scalars, else if( _type == CellType.ROW_AGG ) { if( _aggOp == AggOp.SUM || _aggOp == AggOp.SUM_SQ ) return executeSparseRowAggSum(sblock, lb, scalars, out, m, n, sparseSafe, rl, ru, rix); + else if( _aggOp == AggOp.PROD) + return executeSparseRowProd(sblock, lb, scalars, out, m, n, sparseSafe, rl, ru, rix); else return executeSparseRowAggMxx(sblock, lb, scalars, out, m, n, sparseSafe, rl, ru, rix); } else if( _type == CellType.COL_AGG ) { if( _aggOp == AggOp.SUM || _aggOp == AggOp.SUM_SQ ) return executeSparseColAggSum(sblock, lb, scalars, out, m, n, sparseSafe, rl, ru, rix); + else if( _aggOp == AggOp.PROD) + return executeSparseColProd(sblock, lb, scalars, out, m, n, sparseSafe, rl, ru, rix); else return executeSparseColAggMxx(sblock, lb, scalars, out, m, n, sparseSafe, rl, ru, rix); } @@ -930,7 +939,215 @@ private double executeSparseAggMxx(SparseBlock sblock, SideInput[] b, double[] s } return ret; } - + + private long executeDenseRowProd(DenseBlock a, SideInput[] b, double[] scalars, + DenseBlock c, int m, int n, boolean sparseSafe, int rl, int ru, long rix) + { + // single block output + double[] lc = c.valuesAt(0); + long lnnz = 0; + if(a == null && !sparseSafe) { + for(int i = rl; i < ru; i++) { + for(int j = 0; j < n; j++) { + if(j == 0) { + lc[i] = genexec(0, b, scalars, m, n, rix+i, i, j); + } else if(lc[i] != 0) { + lc[i] *= genexec(0, b, scalars, m, n, rix+i, i, j); + } else { + break; + } + } + lnnz += (lc[i]!=0) ? 1 : 0; + } + } + else if( a != null ) { + for(int i = rl; i < ru; i++) { + double[] avals = a.values(i); + int aix = a.pos(i); + for(int j = 0; j < n; j++) { + double aval = avals[aix + j]; + if(aval != 0 || !sparseSafe) { + if(j == 0) { + lc[i] = genexec(aval, b, scalars, m, n, rix+i, i, j); + } else if(lc[i] != 0) { + lc[i] *= genexec(aval, b, scalars, m, n, rix+i, i, j); + } else { + break; + } + } else { + break; + } + } + lnnz += (lc[i] != 0) ? 1 : 0; + } + } + return lnnz; + } + + private long executeDenseColProd(DenseBlock a, SideInput[] b, double[] scalars, + DenseBlock c, int m, int n, boolean sparseSafe, int rl, int ru, long rix) + { + double[] lc = c.valuesAt(0); + //track the cols that have a zero + boolean[] zeroFlag = new boolean[n]; + if(a == null && !sparseSafe) { + for(int i = rl; i < ru; i++) { + for(int j = 0; j < n; j++) { + if(!zeroFlag[j]) { + if(i == 0) { + lc[j] = genexec(0, b, scalars, m, n, rix+i, i, j); + } else if(lc[j] != 0) { + lc[j] *= genexec(0, b, scalars, m, n, rix+i, i, j); + } else { + zeroFlag[j] = true; + } + } + } + } + } + else if(a != null) { + for(int i = rl; i < ru; i++) { + double[] avals = a.values(i); + int aix = a.pos(i); + for(int j = 0; j < n; j++) { + if(!zeroFlag[j]) { + double aval = avals[aix + j]; + if(aval != 0 || !sparseSafe) { + if(i == 0) { + lc[j] = genexec(aval, b, scalars, m, n, rix + i, i, j); + } else if(lc[j] != 0) { + lc[j] *= genexec(aval, b, scalars, m, n, rix + i, i, j); + } else { + zeroFlag[j] = true; + } + } + } else { + zeroFlag[j] = true; + } + } + } + } + return -1; + } + + private long executeSparseRowProd(SparseBlock sblock, SideInput[] b, double[] scalars, + MatrixBlock out, int m, int n, boolean sparseSafe, int rl, int ru, long rix) + { + double[] c = out.getDenseBlockValues(); + long lnnz = 0; + for(int i = rl; i < ru; i++) { + int lastj = -1; + if(sblock != null && !sblock.isEmpty(i)) { + int apos = sblock.pos(i); + int alen = sblock.size(i); + int[] aix = sblock.indexes(i); + double[] avals = sblock.values(i); + for(int k = apos; k < apos+alen; k++) { + if(!sparseSafe) { + for(int j=lastj+1; j Date: Mon, 3 Mar 2025 17:22:12 +0100 Subject: [PATCH 2/6] add new tests --- .../functions/codegen/CellwiseTmplTest.java | 18 +++++++-- .../functions/codegen/cellwisetmpl28.R | 4 +- .../functions/codegen/cellwisetmpl29.R | 14 +++---- .../functions/codegen/cellwisetmpl29.dml | 12 +++--- .../functions/codegen/cellwisetmpl30.R | 38 +++++++++++++++++++ .../functions/codegen/cellwisetmpl30.dml | 32 ++++++++++++++++ .../functions/codegen/cellwisetmpl31.R | 34 +++++++++++++++++ .../functions/codegen/cellwisetmpl31.dml | 28 ++++++++++++++ 8 files changed, 160 insertions(+), 20 deletions(-) create mode 100644 src/test/scripts/functions/codegen/cellwisetmpl30.R create mode 100644 src/test/scripts/functions/codegen/cellwisetmpl30.dml create mode 100644 src/test/scripts/functions/codegen/cellwisetmpl31.R create mode 100644 src/test/scripts/functions/codegen/cellwisetmpl31.dml diff --git a/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java b/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java index 346f352f7aa..c3f8dba3b80 100644 --- a/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java +++ b/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java @@ -67,8 +67,10 @@ public class CellwiseTmplTest extends AutomatedTestBase private static final String TEST_NAME25 = TEST_NAME+25; //bias_add private static final String TEST_NAME26 = TEST_NAME+26; //bias_mult private static final String TEST_NAME27 = TEST_NAME+27; //outer < +7 negative - private static final String TEST_NAME28 = TEST_NAME+28; //colProd(X) - private static final String TEST_NAME29 = TEST_NAME+29; //rowProd(X) + private static final String TEST_NAME28 = TEST_NAME+28; //colProds(X^2 + 1) + private static final String TEST_NAME29 = TEST_NAME+29; + private static final String TEST_NAME30 = TEST_NAME+30; //rowProds(X^2 + 1) + private static final String TEST_NAME31 = TEST_NAME+31; private static final String TEST_DIR = "functions/codegen/"; private static final String TEST_CLASS_DIR = TEST_DIR + CellwiseTmplTest.class.getSimpleName() + "/"; @@ -81,7 +83,7 @@ public class CellwiseTmplTest extends AutomatedTestBase @Override public void setUp() { TestUtils.clearAssertionInformation(); - for( int i=1; i<=29; i++ ) { + for( int i=1; i<=31; i++ ) { addTestConfiguration( TEST_NAME+i, new TestConfiguration( TEST_CLASS_DIR, TEST_NAME+i, new String[] {String.valueOf(i)}) ); } @@ -471,6 +473,16 @@ public void testCodegenCellwise29() { testCodegenIntegration( TEST_NAME29, false, ExecType.CP ); } + @Test + public void testCodegenCellwise30() { + testCodegenIntegration( TEST_NAME30, false, ExecType.CP ); + } + + @Test + public void testCodegenCellwise31() { + testCodegenIntegration( TEST_NAME31, false, ExecType.CP ); + } + private void testCodegenIntegration( String testname, boolean rewrites, ExecType instType ) { boolean oldRewrites = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION; diff --git a/src/test/scripts/functions/codegen/cellwisetmpl28.R b/src/test/scripts/functions/codegen/cellwisetmpl28.R index 915e936a34b..f92c27c2cb3 100644 --- a/src/test/scripts/functions/codegen/cellwisetmpl28.R +++ b/src/test/scripts/functions/codegen/cellwisetmpl28.R @@ -23,7 +23,7 @@ args<-commandArgs(TRUE) options(digits=22) library("Matrix") -colProd <- function(X) { +colProds <- function(X) { apply(X, 2, prod) } @@ -33,6 +33,6 @@ A = rbind(Y, Z) B = matrix(0, 10, 10) X = cbind(B, A, B) -R = t(colProd(X^2 + 1)); +R = t(colProds(X^2 + 1)); writeMM(as(R,"CsparseMatrix"), paste(args[2], "S", sep="")); diff --git a/src/test/scripts/functions/codegen/cellwisetmpl29.R b/src/test/scripts/functions/codegen/cellwisetmpl29.R index ed93477af2b..8dd46df498a 100644 --- a/src/test/scripts/functions/codegen/cellwisetmpl29.R +++ b/src/test/scripts/functions/codegen/cellwisetmpl29.R @@ -23,16 +23,14 @@ args<-commandArgs(TRUE) options(digits=22) library("Matrix") -rowProd <- function(X) { - apply(X, 1, prod) +colProds <- function(X) { + apply(X, 2, prod) } -Z = matrix(0, 1, 5) -Y = matrix(2, 1, 5) -A = cbind(Y, Z) -B = matrix(0, 10, 10) -X = rbind(B, A, B) +X = matrix(seq(9, 100*50+8), 100, 50, byrow=TRUE); +# F = matrix(3, 10, 10) +# X = matrix(seq(2, 10*20+1), 10, 20) -R = rowProd(X^2 + 1) +R = t(colProds(2*log(X))) writeMM(as(R,"CsparseMatrix"), paste(args[2], "S", sep="")); diff --git a/src/test/scripts/functions/codegen/cellwisetmpl29.dml b/src/test/scripts/functions/codegen/cellwisetmpl29.dml index ed023ce6691..51634a1b791 100644 --- a/src/test/scripts/functions/codegen/cellwisetmpl29.dml +++ b/src/test/scripts/functions/codegen/cellwisetmpl29.dml @@ -19,14 +19,12 @@ # #------------------------------------------------------------- -Z = matrix(0, 1, 5) -Y = matrix(2, 1, 5) -A = cbind(Y, Z) -B = matrix(0, 10, 10) -X = rbind(B, A, B) +X = matrix(seq(9, 100*50+8), 100, 50); +#F = matrix(3, 10, 10) +#X = matrix(seq(2, 10*20+1), 10, 20) while(FALSE){} -R = rowProds(X^2 + 1) +R = colProds(2*log(X)) -write(R, $1) +write(R, $1) \ No newline at end of file diff --git a/src/test/scripts/functions/codegen/cellwisetmpl30.R b/src/test/scripts/functions/codegen/cellwisetmpl30.R new file mode 100644 index 00000000000..9f24a57feab --- /dev/null +++ b/src/test/scripts/functions/codegen/cellwisetmpl30.R @@ -0,0 +1,38 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +args<-commandArgs(TRUE) +options(digits=22) +library("Matrix") + +rowProds <- function(X) { + apply(X, 1, prod) +} + +Z = matrix(0, 1, 5) +Y = matrix(2, 1, 5) +A = cbind(Y, Z) +B = matrix(0, 10, 10) +X = rbind(B, A, B) + +R = rowProds(X^2 + 1) + +writeMM(as(R,"CsparseMatrix"), paste(args[2], "S", sep="")); diff --git a/src/test/scripts/functions/codegen/cellwisetmpl30.dml b/src/test/scripts/functions/codegen/cellwisetmpl30.dml new file mode 100644 index 00000000000..ed023ce6691 --- /dev/null +++ b/src/test/scripts/functions/codegen/cellwisetmpl30.dml @@ -0,0 +1,32 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +Z = matrix(0, 1, 5) +Y = matrix(2, 1, 5) +A = cbind(Y, Z) +B = matrix(0, 10, 10) +X = rbind(B, A, B) + +while(FALSE){} + +R = rowProds(X^2 + 1) + +write(R, $1) diff --git a/src/test/scripts/functions/codegen/cellwisetmpl31.R b/src/test/scripts/functions/codegen/cellwisetmpl31.R new file mode 100644 index 00000000000..4c6d5e4a250 --- /dev/null +++ b/src/test/scripts/functions/codegen/cellwisetmpl31.R @@ -0,0 +1,34 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +args<-commandArgs(TRUE) +options(digits=22) +library("Matrix") + +rowProds <- function(X) { + apply(X, 1, prod) +} + +X = matrix(seq(9, 1000*150+8), 1000, 150, byrow=TRUE); + +R = rowProds(2*log(X)); + +writeMM(as(R,"CsparseMatrix"), paste(args[2], "S", sep="")); diff --git a/src/test/scripts/functions/codegen/cellwisetmpl31.dml b/src/test/scripts/functions/codegen/cellwisetmpl31.dml new file mode 100644 index 00000000000..6665e6d5d1f --- /dev/null +++ b/src/test/scripts/functions/codegen/cellwisetmpl31.dml @@ -0,0 +1,28 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +X = matrix(seq(9, 1000*150+8), 1000, 150); + +while(FALSE){} + +R = rowProds(2*log(X)) + +write(R, $1) \ No newline at end of file From b7235def432042ca075cd3737e836899f71b38af Mon Sep 17 00:00:00 2001 From: Frxms Date: Wed, 5 Mar 2025 16:10:12 +0100 Subject: [PATCH 3/6] final tests --- .../sysds/test/functions/codegen/CellwiseTmplTest.java | 4 ++-- src/test/scripts/functions/codegen/cellwisetmpl29.R | 7 +++++-- src/test/scripts/functions/codegen/cellwisetmpl29.dml | 5 ++++- src/test/scripts/functions/codegen/cellwisetmpl31.R | 3 ++- src/test/scripts/functions/codegen/cellwisetmpl31.dml | 3 ++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java b/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java index c3f8dba3b80..f7cbf5ddc99 100644 --- a/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java +++ b/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java @@ -68,9 +68,9 @@ public class CellwiseTmplTest extends AutomatedTestBase private static final String TEST_NAME26 = TEST_NAME+26; //bias_mult private static final String TEST_NAME27 = TEST_NAME+27; //outer < +7 negative private static final String TEST_NAME28 = TEST_NAME+28; //colProds(X^2 + 1) - private static final String TEST_NAME29 = TEST_NAME+29; + private static final String TEST_NAME29 = TEST_NAME+29; //colProds(2*log(X)) private static final String TEST_NAME30 = TEST_NAME+30; //rowProds(X^2 + 1) - private static final String TEST_NAME31 = TEST_NAME+31; + private static final String TEST_NAME31 = TEST_NAME+31; //colProds(2*log(X)) private static final String TEST_DIR = "functions/codegen/"; private static final String TEST_CLASS_DIR = TEST_DIR + CellwiseTmplTest.class.getSimpleName() + "/"; diff --git a/src/test/scripts/functions/codegen/cellwisetmpl29.R b/src/test/scripts/functions/codegen/cellwisetmpl29.R index 8dd46df498a..bb5f8d9270d 100644 --- a/src/test/scripts/functions/codegen/cellwisetmpl29.R +++ b/src/test/scripts/functions/codegen/cellwisetmpl29.R @@ -27,10 +27,13 @@ colProds <- function(X) { apply(X, 2, prod) } -X = matrix(seq(9, 100*50+8), 100, 50, byrow=TRUE); +X = matrix(3, 10, 10) +# X = matrix(seq(9, 100*100+8), 100, 100, byrow=TRUE); # F = matrix(3, 10, 10) -# X = matrix(seq(2, 10*20+1), 10, 20) +# X = matrix(seq(from = 1, to = 10, by = 2), 10, 20) +# X = matrix(1.3109348721, 10, 10) R = t(colProds(2*log(X))) +# R = t(colProds(X*min(F))); writeMM(as(R,"CsparseMatrix"), paste(args[2], "S", sep="")); diff --git a/src/test/scripts/functions/codegen/cellwisetmpl29.dml b/src/test/scripts/functions/codegen/cellwisetmpl29.dml index 51634a1b791..9140fc06af9 100644 --- a/src/test/scripts/functions/codegen/cellwisetmpl29.dml +++ b/src/test/scripts/functions/codegen/cellwisetmpl29.dml @@ -19,12 +19,15 @@ # #------------------------------------------------------------- -X = matrix(seq(9, 100*50+8), 100, 50); +X = matrix(3, 10, 10) +#X = matrix(seq(9, 100*100+8), 100, 100); #F = matrix(3, 10, 10) #X = matrix(seq(2, 10*20+1), 10, 20) +#X = matrix(1.3109348721, 10, 10) while(FALSE){} R = colProds(2*log(X)) +#R = colProds(X*min(F)) write(R, $1) \ No newline at end of file diff --git a/src/test/scripts/functions/codegen/cellwisetmpl31.R b/src/test/scripts/functions/codegen/cellwisetmpl31.R index 4c6d5e4a250..41903bde8fa 100644 --- a/src/test/scripts/functions/codegen/cellwisetmpl31.R +++ b/src/test/scripts/functions/codegen/cellwisetmpl31.R @@ -27,7 +27,8 @@ rowProds <- function(X) { apply(X, 1, prod) } -X = matrix(seq(9, 1000*150+8), 1000, 150, byrow=TRUE); +X = matrix(3, 10, 10) +# X = matrix(seq(9, 100*100+8), 100, 100, byrow=TRUE); R = rowProds(2*log(X)); diff --git a/src/test/scripts/functions/codegen/cellwisetmpl31.dml b/src/test/scripts/functions/codegen/cellwisetmpl31.dml index 6665e6d5d1f..c203bca306d 100644 --- a/src/test/scripts/functions/codegen/cellwisetmpl31.dml +++ b/src/test/scripts/functions/codegen/cellwisetmpl31.dml @@ -19,7 +19,8 @@ # #------------------------------------------------------------- -X = matrix(seq(9, 1000*150+8), 1000, 150); +X = matrix(3, 10, 10) +#X = matrix(seq(9, 100*100+8), 100, 100); while(FALSE){} From c9f4f04a60baac0e06d8f947f471961a524315d8 Mon Sep 17 00:00:00 2001 From: Frxms Date: Tue, 11 Mar 2025 20:04:21 +0100 Subject: [PATCH 4/6] add bigger matrices --- src/test/scripts/functions/codegen/cellwisetmpl29.R | 2 +- src/test/scripts/functions/codegen/cellwisetmpl29.dml | 2 +- src/test/scripts/functions/codegen/cellwisetmpl31.R | 2 ++ src/test/scripts/functions/codegen/cellwisetmpl31.dml | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/test/scripts/functions/codegen/cellwisetmpl29.R b/src/test/scripts/functions/codegen/cellwisetmpl29.R index bb5f8d9270d..ba315739517 100644 --- a/src/test/scripts/functions/codegen/cellwisetmpl29.R +++ b/src/test/scripts/functions/codegen/cellwisetmpl29.R @@ -29,7 +29,7 @@ colProds <- function(X) { X = matrix(3, 10, 10) # X = matrix(seq(9, 100*100+8), 100, 100, byrow=TRUE); -# F = matrix(3, 10, 10) +# F = matrix(0.1, 10, 10) # X = matrix(seq(from = 1, to = 10, by = 2), 10, 20) # X = matrix(1.3109348721, 10, 10) diff --git a/src/test/scripts/functions/codegen/cellwisetmpl29.dml b/src/test/scripts/functions/codegen/cellwisetmpl29.dml index 9140fc06af9..72a38870a33 100644 --- a/src/test/scripts/functions/codegen/cellwisetmpl29.dml +++ b/src/test/scripts/functions/codegen/cellwisetmpl29.dml @@ -21,7 +21,7 @@ X = matrix(3, 10, 10) #X = matrix(seq(9, 100*100+8), 100, 100); -#F = matrix(3, 10, 10) +#F = matrix(0.1, 10, 10) #X = matrix(seq(2, 10*20+1), 10, 20) #X = matrix(1.3109348721, 10, 10) diff --git a/src/test/scripts/functions/codegen/cellwisetmpl31.R b/src/test/scripts/functions/codegen/cellwisetmpl31.R index 41903bde8fa..31b518964ab 100644 --- a/src/test/scripts/functions/codegen/cellwisetmpl31.R +++ b/src/test/scripts/functions/codegen/cellwisetmpl31.R @@ -29,7 +29,9 @@ rowProds <- function(X) { X = matrix(3, 10, 10) # X = matrix(seq(9, 100*100+8), 100, 100, byrow=TRUE); +# F = matrix(0.1, 10, 10) R = rowProds(2*log(X)); +# R = rowProds(X*min(F)) writeMM(as(R,"CsparseMatrix"), paste(args[2], "S", sep="")); diff --git a/src/test/scripts/functions/codegen/cellwisetmpl31.dml b/src/test/scripts/functions/codegen/cellwisetmpl31.dml index c203bca306d..77f2e84ebee 100644 --- a/src/test/scripts/functions/codegen/cellwisetmpl31.dml +++ b/src/test/scripts/functions/codegen/cellwisetmpl31.dml @@ -21,9 +21,11 @@ X = matrix(3, 10, 10) #X = matrix(seq(9, 100*100+8), 100, 100); +#F = matrix(0.1, 10, 10) while(FALSE){} R = rowProds(2*log(X)) +#R = rowProds(X*min(F)) write(R, $1) \ No newline at end of file From 533302fecd242540c11bfa3e7c771ba11985cbf5 Mon Sep 17 00:00:00 2001 From: Frxms Date: Tue, 18 Mar 2025 17:02:05 +0100 Subject: [PATCH 5/6] create more test cases --- .../functions/codegen/CellwiseTmplTest.java | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java b/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java index f7cbf5ddc99..f7dcefd1645 100644 --- a/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java +++ b/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java @@ -448,7 +448,7 @@ public void testCodegenCellwise26() { public void testCodegenCellwiseRewrite26_sp() { testCodegenIntegration( TEST_NAME26, true, ExecType.SPARK ); } - + @Test public void testCodegenCellwiseRewrite27() { testCodegenIntegration( TEST_NAME27, true, ExecType.CP ); @@ -459,30 +459,71 @@ public void testCodegenCellwise27() { testCodegenIntegration( TEST_NAME27, false, ExecType.CP ); } + @Test public void testCodegenCellwiseRewrite27_sp() { testCodegenIntegration( TEST_NAME27, true, ExecType.SPARK ); } + @Test + public void testCodegenCellwiseRewrite28() { + testCodegenIntegration( TEST_NAME28, true, ExecType.CP ); + } + @Test public void testCodegenCellwise28() { testCodegenIntegration( TEST_NAME28, false, ExecType.CP ); } + @Test + public void testCodegenCellwiseRewrite28_sp() { + testCodegenIntegration( TEST_NAME28, true, ExecType.SPARK ); + } + + @Test + public void testCodegenCellwiseRewrite29() { + testCodegenIntegration( TEST_NAME29, true, ExecType.CP ); + } + @Test public void testCodegenCellwise29() { testCodegenIntegration( TEST_NAME29, false, ExecType.CP ); } + @Test + public void testCodegenCellwiseRewrite29_sp() { + testCodegenIntegration( TEST_NAME29, true, ExecType.SPARK ); + } + + @Test + public void testCodegenCellwiseRewrite30() { + testCodegenIntegration( TEST_NAME30, true, ExecType.CP ); + } + @Test public void testCodegenCellwise30() { testCodegenIntegration( TEST_NAME30, false, ExecType.CP ); } + @Test + public void testCodegenCellwiseRewrite30_sp() { + testCodegenIntegration( TEST_NAME30, true, ExecType.SPARK ); + } + + @Test + public void testCodegenCellwiseRewrite31() { + testCodegenIntegration( TEST_NAME31, true, ExecType.CP ); + } + @Test public void testCodegenCellwise31() { testCodegenIntegration( TEST_NAME31, false, ExecType.CP ); } + @Test + public void testCodegenCellwiseRewrite31_sp() { + testCodegenIntegration( TEST_NAME31, true, ExecType.SPARK ); + } + private void testCodegenIntegration( String testname, boolean rewrites, ExecType instType ) { boolean oldRewrites = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION; From 6a80405acc40af83fd117dcb34bd5d73d021e5c5 Mon Sep 17 00:00:00 2001 From: Frxms Date: Tue, 18 Mar 2025 17:26:11 +0100 Subject: [PATCH 6/6] adjust test type --- .../sysds/test/functions/codegen/CellwiseTmplTest.java | 2 +- src/test/scripts/functions/codegen/cellwisetmpl28.R | 7 ++++--- src/test/scripts/functions/codegen/cellwisetmpl29.R | 7 ++++--- src/test/scripts/functions/codegen/cellwisetmpl30.R | 7 ++++--- src/test/scripts/functions/codegen/cellwisetmpl31.R | 7 ++++--- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java b/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java index f7dcefd1645..62ab375f2ae 100644 --- a/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java +++ b/src/test/java/org/apache/sysds/test/functions/codegen/CellwiseTmplTest.java @@ -70,7 +70,7 @@ public class CellwiseTmplTest extends AutomatedTestBase private static final String TEST_NAME28 = TEST_NAME+28; //colProds(X^2 + 1) private static final String TEST_NAME29 = TEST_NAME+29; //colProds(2*log(X)) private static final String TEST_NAME30 = TEST_NAME+30; //rowProds(X^2 + 1) - private static final String TEST_NAME31 = TEST_NAME+31; //colProds(2*log(X)) + private static final String TEST_NAME31 = TEST_NAME+31; //rowProds(2*log(X)) private static final String TEST_DIR = "functions/codegen/"; private static final String TEST_CLASS_DIR = TEST_DIR + CellwiseTmplTest.class.getSimpleName() + "/"; diff --git a/src/test/scripts/functions/codegen/cellwisetmpl28.R b/src/test/scripts/functions/codegen/cellwisetmpl28.R index f92c27c2cb3..05e31d0f19b 100644 --- a/src/test/scripts/functions/codegen/cellwisetmpl28.R +++ b/src/test/scripts/functions/codegen/cellwisetmpl28.R @@ -22,10 +22,11 @@ args<-commandArgs(TRUE) options(digits=22) library("Matrix") +library("matrixStats") -colProds <- function(X) { - apply(X, 2, prod) -} +# colProds <- function(X) { +# apply(X, 2, prod) +# } Z = matrix(0, 5, 1) Y = matrix(2, 5, 1) diff --git a/src/test/scripts/functions/codegen/cellwisetmpl29.R b/src/test/scripts/functions/codegen/cellwisetmpl29.R index ba315739517..08c255f617f 100644 --- a/src/test/scripts/functions/codegen/cellwisetmpl29.R +++ b/src/test/scripts/functions/codegen/cellwisetmpl29.R @@ -22,10 +22,11 @@ args<-commandArgs(TRUE) options(digits=22) library("Matrix") +library("matrixStats") -colProds <- function(X) { - apply(X, 2, prod) -} +# colProds <- function(X) { +# apply(X, 2, prod) +# } X = matrix(3, 10, 10) # X = matrix(seq(9, 100*100+8), 100, 100, byrow=TRUE); diff --git a/src/test/scripts/functions/codegen/cellwisetmpl30.R b/src/test/scripts/functions/codegen/cellwisetmpl30.R index 9f24a57feab..7ef70860097 100644 --- a/src/test/scripts/functions/codegen/cellwisetmpl30.R +++ b/src/test/scripts/functions/codegen/cellwisetmpl30.R @@ -22,10 +22,11 @@ args<-commandArgs(TRUE) options(digits=22) library("Matrix") +library("matrixStats") -rowProds <- function(X) { - apply(X, 1, prod) -} +# rowProds <- function(X) { +# apply(X, 1, prod) +# } Z = matrix(0, 1, 5) Y = matrix(2, 1, 5) diff --git a/src/test/scripts/functions/codegen/cellwisetmpl31.R b/src/test/scripts/functions/codegen/cellwisetmpl31.R index 31b518964ab..24a7ed759f4 100644 --- a/src/test/scripts/functions/codegen/cellwisetmpl31.R +++ b/src/test/scripts/functions/codegen/cellwisetmpl31.R @@ -22,10 +22,11 @@ args<-commandArgs(TRUE) options(digits=22) library("Matrix") +library("matrixStats") -rowProds <- function(X) { - apply(X, 1, prod) -} +# rowProds <- function(X) { +# apply(X, 1, prod) +# } X = matrix(3, 10, 10) # X = matrix(seq(9, 100*100+8), 100, 100, byrow=TRUE);