Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite Discovery and Generation Framework #2198

Closed
wants to merge 291 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
291 commits
Select commit Hold shift + click to select a range
2dcb143
Better equality matching
Jaybit0 Oct 23, 2024
f223e4e
Update RewriterAssertions.java
Jaybit0 Oct 24, 2024
9c527b7
FIX
Jaybit0 Oct 25, 2024
3337477
FIXXXX
Jaybit0 Oct 25, 2024
ecd2e59
Some improvements
Jaybit0 Oct 28, 2024
0e15664
Some more improvements (probably expensive)
Jaybit0 Oct 29, 2024
31f8029
Some major performance improvements
Jaybit0 Oct 29, 2024
f4a6ec6
Begin of finding minimal difference
Jaybit0 Oct 29, 2024
ccf1e01
Some first minimal difference implementation
Jaybit0 Oct 29, 2024
5bda100
Better match filtering
Jaybit0 Oct 30, 2024
522c46b
Bugfix
Jaybit0 Nov 3, 2024
e84eb00
Bugfix
Jaybit0 Nov 3, 2024
8ee7431
Minor bugfix updating types
Jaybit0 Nov 3, 2024
143b68a
Bugfix
Jaybit0 Nov 4, 2024
3a90482
Bugfix
Jaybit0 Nov 5, 2024
6e7c77e
Fix
Jaybit0 Nov 5, 2024
c57aa33
Constant folding
Jaybit0 Nov 5, 2024
ac83c66
Some more fixes
Jaybit0 Nov 5, 2024
7f0e47e
Some more cost estimates
Jaybit0 Nov 5, 2024
e63f5e9
Cost estimator
Jaybit0 Nov 6, 2024
ba8d1b7
Some fixes
Jaybit0 Nov 7, 2024
0286e48
Checkpoint
Jaybit0 Nov 7, 2024
4990f9b
Rule generator
Jaybit0 Nov 7, 2024
44c85c3
First RuleCreator implementation
Jaybit0 Nov 7, 2024
60436f3
Some more improvements
Jaybit0 Nov 7, 2024
497465d
Some more improvements
Jaybit0 Nov 8, 2024
8cbddbf
Assertion breaking changes
Jaybit0 Nov 11, 2024
cb05568
Some improvements
Jaybit0 Nov 11, 2024
5219001
Some more improvements
Jaybit0 Nov 11, 2024
d12aab1
Major improvements
Jaybit0 Nov 12, 2024
a8da7cf
First CodeGen implementation
Jaybit0 Nov 12, 2024
0961998
Some more codegen
Jaybit0 Nov 13, 2024
8514192
Update RewriterCodeGen.java
Jaybit0 Nov 13, 2024
eeec2c1
Some bugfixes
Jaybit0 Nov 13, 2024
09692e7
Some more changes
Jaybit0 Nov 13, 2024
b7c5943
Some more stuff
Jaybit0 Nov 13, 2024
8877e03
Some improvements
Jaybit0 Nov 13, 2024
e153ae1
Some changes
Jaybit0 Nov 14, 2024
8b866c6
Validation script implementation
Jaybit0 Nov 14, 2024
d5fe2cf
AlphabetEncoder
Jaybit0 Nov 14, 2024
4da4c8a
Some more improvements
Jaybit0 Nov 14, 2024
61bb3bf
Some improvements
Jaybit0 Nov 15, 2024
3cddac5
Some debugging
Jaybit0 Nov 15, 2024
b858f93
Some changes
Jaybit0 Nov 15, 2024
9a5a5d6
Some changes
Jaybit0 Nov 15, 2024
6e037e2
Backup
Jaybit0 Nov 15, 2024
9c523e1
Bugfixes
Jaybit0 Nov 17, 2024
184a0df
Some more improvements
Jaybit0 Nov 17, 2024
65ef982
Some more improvements
Jaybit0 Nov 18, 2024
47c43ee
Some improvements
Jaybit0 Nov 18, 2024
642b7ac
Update DMLCodeGenTest.java
Jaybit0 Nov 18, 2024
e309e90
Backup
Jaybit0 Nov 19, 2024
f0600da
Some further improvements
Jaybit0 Nov 19, 2024
a32da49
Some more improvements
Jaybit0 Nov 19, 2024
6411b5a
Some bugfixes
Jaybit0 Nov 20, 2024
fa79b4a
Improved cost estimation
Jaybit0 Nov 20, 2024
be2d33b
Some more cost estimation functionality
Jaybit0 Nov 20, 2024
fa50fef
Some more improvements
Jaybit0 Nov 20, 2024
9c1a445
Minor bugfix
Jaybit0 Nov 20, 2024
a4e0c82
Some more improvements to the system
Jaybit0 Nov 20, 2024
29cfa20
Some improvements
Jaybit0 Nov 20, 2024
7594ae9
Some more improvements but clustering not working yet
Jaybit0 Nov 20, 2024
520ff96
Some improvements to the rules
Jaybit0 Nov 21, 2024
dd5cad5
Some bugfixes
Jaybit0 Nov 21, 2024
f11e557
Some more fixes
Jaybit0 Nov 21, 2024
99b720e
Some improvements
Jaybit0 Nov 21, 2024
4971637
Bugfix
Jaybit0 Nov 21, 2024
c9c2eda
Bugfix
Jaybit0 Nov 21, 2024
6f0115e
Some more improvements
Jaybit0 Nov 21, 2024
89f119e
Some bugfixes
Jaybit0 Nov 21, 2024
4f6587a
Some fixes
Jaybit0 Nov 21, 2024
6283cb4
Some more bugfixes
Jaybit0 Nov 22, 2024
1a0effe
Some fixes
Jaybit0 Nov 22, 2024
2522042
Some more minor fixes
Jaybit0 Nov 22, 2024
f1378e9
Test fix
Jaybit0 Nov 22, 2024
e9ff953
First fused op
Jaybit0 Nov 22, 2024
6303ca4
LogNZ support
Jaybit0 Nov 22, 2024
18f5db9
Some more fixes
Jaybit0 Nov 22, 2024
b076ad5
Some cost fixes
Jaybit0 Nov 22, 2024
969e593
Some improvements
Jaybit0 Nov 22, 2024
47ee20f
Some more fixes
Jaybit0 Nov 22, 2024
970149f
Some improvements
Jaybit0 Nov 22, 2024
52075ac
Some more improvements
Jaybit0 Nov 22, 2024
ddf6136
Some more improvements
Jaybit0 Nov 22, 2024
023d8d5
Some more improvements
Jaybit0 Nov 22, 2024
91d0086
Error handling
Jaybit0 Nov 22, 2024
58193f5
Some improvements
Jaybit0 Nov 24, 2024
0f9f5ad
Some improvements
Jaybit0 Nov 25, 2024
99e9d9a
Some more improvements
Jaybit0 Nov 25, 2024
7e50769
Some more fixes
Jaybit0 Nov 25, 2024
a3500ef
Some bugfixes
Jaybit0 Nov 25, 2024
470d1be
Some more bugfixes
Jaybit0 Nov 25, 2024
ca7d84d
Some more improvements
Jaybit0 Nov 25, 2024
c4b5a1f
Major improvements to randomized search
Jaybit0 Nov 25, 2024
3bdc6c6
Some bugfixes
Jaybit0 Nov 26, 2024
04867f3
Some bugfixes (origin still unknown)
Jaybit0 Nov 26, 2024
e354cc1
Some more changes
Jaybit0 Nov 26, 2024
9852e36
Some more improvements
Jaybit0 Nov 26, 2024
ab76040
Some more improvements
Jaybit0 Nov 26, 2024
05b39d8
Some more fixes
Jaybit0 Nov 26, 2024
b8d3424
Some more updates
Jaybit0 Nov 26, 2024
613657b
Some more fixes
Jaybit0 Nov 27, 2024
81a272e
Some better constant handling
Jaybit0 Nov 27, 2024
31a410f
Some more changes
Jaybit0 Nov 27, 2024
77f5d57
Some bugfixes
Jaybit0 Nov 27, 2024
0a641e9
Some more bugfixes
Jaybit0 Nov 27, 2024
7b4de8d
Some improvements
Jaybit0 Nov 27, 2024
0a8ed4d
Some more fixes
Jaybit0 Nov 27, 2024
d69232c
Some more improvements
Jaybit0 Nov 27, 2024
32a46d6
Backup
Jaybit0 Nov 27, 2024
a0441d8
Some more stuff
Jaybit0 Nov 28, 2024
77418ca
Some breakthroughs
Jaybit0 Nov 28, 2024
4067c7e
Some more improvements
Jaybit0 Nov 28, 2024
a94575f
Some improvements
Jaybit0 Nov 29, 2024
61248fc
Some progress
Jaybit0 Nov 29, 2024
ab0ccda
Some improvements
Jaybit0 Nov 29, 2024
bf49b52
Some bugfixes
Jaybit0 Nov 30, 2024
81c457c
Some more improvements
Jaybit0 Nov 30, 2024
1e17b4f
Some more improvements
Jaybit0 Dec 2, 2024
f7d4cb4
Some more improvements
Jaybit0 Dec 2, 2024
edc3f17
NNZ estimatior
Jaybit0 Dec 2, 2024
5bbda9a
Sparsity esimtation
Jaybit0 Dec 2, 2024
feecf16
Some more improvements
Jaybit0 Dec 3, 2024
6e93733
Bugfix
Jaybit0 Dec 3, 2024
ed84ce7
Some improvements
Jaybit0 Dec 3, 2024
e1848ce
Bugfix
Jaybit0 Dec 3, 2024
838fe93
Update RewriterCostEstimator.java
Jaybit0 Dec 3, 2024
4511349
Some more improvements
Jaybit0 Dec 3, 2024
d51f5ed
Some more improvements
Jaybit0 Dec 4, 2024
8e72578
Some improvements
Jaybit0 Dec 4, 2024
cb48d35
Some more improvements
Jaybit0 Dec 5, 2024
0322c60
Some more improvements
Jaybit0 Dec 5, 2024
1235236
Some cleanup (TODO: Check if something broke)
Jaybit0 Dec 5, 2024
616c199
Some changes
Jaybit0 Dec 5, 2024
5f9be9e
Some improvements
Jaybit0 Dec 6, 2024
3988817
Bugfix
Jaybit0 Dec 6, 2024
76fa4ed
Update CodeGenTests.java
Jaybit0 Dec 7, 2024
a68d6b6
Backup
Jaybit0 Dec 7, 2024
a012b32
Bugfix
Jaybit0 Dec 9, 2024
55702af
Update GeneratedRewriteClass.java
Jaybit0 Dec 10, 2024
c4075cd
Bugfix
Jaybit0 Dec 10, 2024
f8250c1
Some fixes
Jaybit0 Dec 10, 2024
4751581
Some progress
Jaybit0 Dec 10, 2024
26414e8
Bugfix
Jaybit0 Dec 11, 2024
605d1bd
Update RewriterRuleCollection.java
Jaybit0 Dec 11, 2024
b90a4a4
Fix
Jaybit0 Dec 11, 2024
927eb2b
Some more improvements
Jaybit0 Dec 11, 2024
0709da3
More improvements
Jaybit0 Dec 11, 2024
abfc8b4
Benchmarking infrastructure
Jaybit0 Dec 12, 2024
ecd9e80
Backup
Jaybit0 Dec 13, 2024
b34d73e
Bugfix type casting
Jaybit0 Dec 13, 2024
0346da1
Some more bug-fixes
Jaybit0 Dec 14, 2024
511efac
Some more changes
Jaybit0 Dec 14, 2024
d885d53
Several bugfixes
Jaybit0 Dec 14, 2024
0d5651f
Update TopologicalSort.java
Jaybit0 Dec 14, 2024
bfcbe44
Some improvements
Jaybit0 Dec 16, 2024
26eaead
Some more bugfixes
Jaybit0 Dec 16, 2024
f74b7f8
Some more updates
Jaybit0 Dec 16, 2024
b5ec813
Some more fixes
Jaybit0 Dec 16, 2024
2520d16
Some bugfixes
Jaybit0 Dec 18, 2024
d98a93b
Update RewriterAlphabetEncoder.java
Jaybit0 Dec 18, 2024
08898c7
Backup
Jaybit0 Dec 21, 2024
2439b0f
Some more bugfixes
Jaybit0 Jan 4, 2025
78a5561
Some more bugfixes
Jaybit0 Jan 4, 2025
e5d16ba
Update
Jaybit0 Jan 5, 2025
7058b26
Some bugfixes
Jaybit0 Jan 6, 2025
a8bb0d4
Some more cleanup
Jaybit0 Jan 6, 2025
a26ea8c
Some more improvements
Jaybit0 Jan 6, 2025
95de6b8
Some more fixes
Jaybit0 Jan 6, 2025
927dedc
Further bugfixes
Jaybit0 Jan 7, 2025
53e5853
Some more fancy stuff
Jaybit0 Jan 7, 2025
549d456
Multirule parsing
Jaybit0 Jan 7, 2025
a8244ef
Various fixes
Jaybit0 Jan 8, 2025
0c25af4
Some improvements and fixes
Jaybit0 Jan 9, 2025
5aa69ea
Fix build
Jaybit0 Jan 9, 2025
2851b1f
Some more updates
Jaybit0 Jan 11, 2025
8023606
Some tests for experiments
Jaybit0 Jan 12, 2025
13cb5d1
Normal Form Tests
Jaybit0 Jan 12, 2025
2dc44c4
Update RewriterNormalFormTests.java
Jaybit0 Jan 12, 2025
62647fb
Update RewriterNormalFormTests.java
Jaybit0 Jan 12, 2025
e3c42ad
Update RewriterNormalFormTests.java
Jaybit0 Jan 12, 2025
7d6299d
Update RewriterNormalFormTests.java
Jaybit0 Jan 12, 2025
4078d34
Some more fixes
Jaybit0 Jan 13, 2025
4f3a9b7
Backup
Jaybit0 Jan 13, 2025
3bdc01c
Some more fixes
Jaybit0 Jan 13, 2025
4b6d103
Some fixes
Jaybit0 Jan 13, 2025
b6b8cb5
Update
Jaybit0 Jan 14, 2025
d46e983
Some bugfixes
Jaybit0 Jan 16, 2025
a9c61d7
Update TopologicalSort.java
Jaybit0 Jan 16, 2025
ad3c079
Add licenses
Jaybit0 Jan 16, 2025
a4ca40a
Better literal support
Jaybit0 Jan 16, 2025
a22f3dd
Update
Jaybit0 Jan 16, 2025
ff36f12
Some updates
Jaybit0 Jan 16, 2025
81f1b0f
Some fixes
Jaybit0 Jan 16, 2025
61f26c9
Some updates
Jaybit0 Jan 16, 2025
bda5cb9
Update
Jaybit0 Jan 16, 2025
32dd096
Update
Jaybit0 Jan 17, 2025
adc21e7
Bugfix for BinaryOp construction
Jaybit0 Jan 18, 2025
74d5235
Some updates
Jaybit0 Jan 19, 2025
a1650c5
Various bugfixes
Jaybit0 Jan 20, 2025
e30fac5
Update
Jaybit0 Jan 20, 2025
edc93d9
Update
Jaybit0 Jan 23, 2025
8fca8e6
Bugfix
Jaybit0 Jan 28, 2025
ef49168
Bugfix fix
Jaybit0 Jan 28, 2025
2f6de8f
Bugfix: Diag
Jaybit0 Jan 28, 2025
0abd378
Increased stability of our sort algorithm
Jaybit0 Jan 28, 2025
4a58174
Cleanup
Jaybit0 Jan 28, 2025
966db93
Add License to Tests
Jaybit0 Jan 28, 2025
3b07f75
Code Cleanup and add Licenses
Jaybit0 Jan 28, 2025
c13a1a8
Further Code Cleanup
Jaybit0 Jan 28, 2025
ab82249
More Code Cleanup
Jaybit0 Jan 28, 2025
4117aa4
Update TopologicalSort.java
Jaybit0 Jan 29, 2025
95e440b
Bugfix CostEstimator
Jaybit0 Jan 29, 2025
efb805d
Create RewriterFramework.java
Jaybit0 Jan 29, 2025
994bfdb
Update log4j.properties
Jaybit0 Jan 29, 2025
d077f93
Fix rowVec/colVec
Jaybit0 Jan 29, 2025
259696e
Better error handling
Jaybit0 Jan 29, 2025
d741902
Some improvements
Jaybit0 Jan 29, 2025
313d8de
Minor bugfixes
Jaybit0 Jan 29, 2025
ab03423
Reverting some changes
Jaybit0 Jan 29, 2025
811d82a
Cleanup TestBase
Jaybit0 Jan 29, 2025
1d316f2
Remove additional files
Jaybit0 Jan 29, 2025
54bc0b5
More Code Cleanup
Jaybit0 Jan 29, 2025
d44ec2b
Update RewriterFramework.java
Jaybit0 Jan 29, 2025
e97e140
More extensive stats for n-grams
Jaybit0 Jul 1, 2024
f85071e
Some more bugfixes
Jaybit0 Jul 4, 2024
e6bdcc4
NGrams now use lineage per default
Jaybit0 Aug 2, 2024
8181a01
Workaround to avoid increasing object size of LineageItem
Jaybit0 Aug 4, 2024
c3ddfbf
Update ProgramBlock.java
Jaybit0 Aug 15, 2024
3647c74
Merge branch 'RewriterRebase'
Jaybit0 Jan 29, 2025
cd43150
Merge branch 'main' of https://github.com/Jaybit0/systemds
Jaybit0 Jan 29, 2025
f85493a
Disable all (knowingly) failing tests
Jaybit0 Jan 30, 2025
13db978
Logging via log4j
Jaybit0 Jan 30, 2025
ce97d7a
Some more bugfixes
Jaybit0 Jan 30, 2025
2d0fb82
Bugfix
Jaybit0 Jan 30, 2025
d8292c9
Disable Logs
Jaybit0 Jan 30, 2025
66350ba
Remove debug log
Jaybit0 Jan 30, 2025
94d46a8
Various small bugfixes
Jaybit0 Jan 30, 2025
98090c0
Bugfix
Jaybit0 Jan 30, 2025
fa6d98b
Update RewriterFramework.java
Jaybit0 Jan 30, 2025
8beb9b3
Update MetaPropagator.java
Jaybit0 Jan 30, 2025
4c447db
Update ProgramRewriter.java
Jaybit0 Jan 30, 2025
27cebd5
Code Cleanup
Jaybit0 Jan 30, 2025
976eb8f
Revert change from OptUtils
Jaybit0 Jan 30, 2025
6f9f59a
Some more cleanup
Jaybit0 Jan 30, 2025
7db72d6
Cleanup
Jaybit0 Jan 30, 2025
98ef774
Revert changes in ApplyTransformTest
Jaybit0 Jan 30, 2025
8bd1499
Remove Legacy Test
Jaybit0 Jan 30, 2025
39af800
Minor fixes for documentation and legacy test removal
Jaybit0 Jan 31, 2025
21758a8
Documentation fix
Jaybit0 Jan 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/org/apache/sysds/api/DMLOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class DMLOptions {
public int[] statsNGramSizes = { 3 }; // Default n-gram tuple sizes
public int statsTopKNGrams = 10; // How many of the most heavy hitting n-grams are displayed
public boolean statsNGramsUseLineage = true; // If N-Grams use lineage for data-dependent tracking
public boolean applyGeneratedRewrites = false; // If generated rewrites should be applied
public boolean fedStats = false; // Whether to record and print the federated statistics
public int fedStatsCount = 10; // Default federated statistics count
public boolean memStats = false; // max memory statistics
Expand Down Expand Up @@ -246,6 +247,8 @@ else if (lineageType.equalsIgnoreCase("debugger"))
}
}

dmlOptions.applyGeneratedRewrites = line.hasOption("applyGeneratedRewrites");

dmlOptions.fedStats = line.hasOption("fedStats");
if (dmlOptions.fedStats) {
String fedStatsCount = line.getOptionValue("fedStats");
Expand Down Expand Up @@ -372,6 +375,7 @@ private static Options createCLIOptions() {
Option ngramsOpt = OptionBuilder//.withArgName("ngrams")
.withDescription("monitors and reports the most occurring n-grams; -ngrams <comma separated n's> <topK>")
.hasOptionalArgs(2).create("ngrams");
Option applyGeneratedRewritesOpt = OptionBuilder.withArgName("applyGeneratedRewrites").withDescription("if automatically generated rewrites should be applied").create("applyGeneratedRewrites");
Option fedStatsOpt = OptionBuilder.withArgName("count")
.withDescription("monitors and reports summary execution statistics of federated workers; heavy hitter <count> is 10 unless overridden; default off")
.hasOptionalArg().create("fedStats");
Expand Down Expand Up @@ -434,6 +438,7 @@ private static Options createCLIOptions() {
options.addOption(cleanOpt);
options.addOption(statsOpt);
options.addOption(ngramsOpt);
options.addOption(applyGeneratedRewritesOpt);
options.addOption(fedStatsOpt);
options.addOption(memOpt);
options.addOption(explainOpt);
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/org/apache/sysds/api/DMLScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.util.Date;
import java.util.Map;
import java.util.Scanner;
import java.util.function.BiConsumer;
import java.util.function.Function;

import org.apache.commons.cli.AlreadySelectedException;
import org.apache.commons.cli.HelpFormatter;
Expand Down Expand Up @@ -106,6 +108,7 @@ public class DMLScript
public static int STATISTICS_TOP_K_NGRAMS = DMLOptions.defaultOptions.statsTopKNGrams;
// Set if N-Grams use lineage for data-dependent tracking
public static boolean STATISTICS_NGRAMS_USE_LINEAGE = DMLOptions.defaultOptions.statsNGramsUseLineage;
public static boolean APPLY_GENERATED_REWRITES = DMLOptions.defaultOptions.applyGeneratedRewrites;
// Set statistics maximum wrap length
public static int STATISTICS_MAX_WRAP_LEN = 30;
// Enable/disable to print federated statistics
Expand Down Expand Up @@ -168,6 +171,9 @@ public class DMLScript
public static String _uuid = IDHandler.createDistributedUniqueID();
private static final Log LOG = LogFactory.getLog(DMLScript.class.getName());

public static Function<DMLProgram, Boolean> preHopInterceptor = null; // Intercepts HOPs before they are rewritten
public static Function<DMLProgram, Boolean> hopInterceptor = null; // Intercepts HOPs after they are rewritten

///////////////////////////////
// public external interface
////////
Expand Down Expand Up @@ -261,6 +267,7 @@ public static boolean executeScript( String[] args )
STATISTICS_NGRAMS = dmlOptions.statsNGrams;
STATISTICS_NGRAM_SIZES = dmlOptions.statsNGramSizes;
STATISTICS_TOP_K_NGRAMS = dmlOptions.statsTopKNGrams;
APPLY_GENERATED_REWRITES = dmlOptions.applyGeneratedRewrites;
FED_STATISTICS = dmlOptions.fedStats;
FED_STATISTICS_COUNT = dmlOptions.fedStatsCount;
JMLC_MEM_STATISTICS = dmlOptions.memStats;
Expand Down Expand Up @@ -456,9 +463,15 @@ private static void execute(String dmlScriptStr, String fnameOptConfig, Map<Stri

//init working directories (before usage by following compilation steps)
initHadoopExecution( ConfigurationManager.getDMLConfig() );


if (preHopInterceptor != null && !preHopInterceptor.apply(prog))
return;

//Step 5: rewrite HOP DAGs (incl IPA and memory estimates)
dmlt.rewriteHopsDAG(prog);

if (hopInterceptor != null && !hopInterceptor.apply(prog))
return;

//Step 6: construct lops (incl exec type and op selection)
dmlt.constructLops(prog);
Expand Down
102 changes: 102 additions & 0 deletions src/main/java/org/apache/sysds/hops/rewrite/HopRewriteUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,30 @@ public static DataGenOp copyDataGenOp( DataGenOp inputGen, double scale, double

return datagen;
}

public static Hop createDataGenOpFromDims( Hop rows, Hop cols, double value ) {
Hop val = new LiteralOp(value);

HashMap<String, Hop> params = new HashMap<>();
params.put(DataExpression.RAND_ROWS, rows);
params.put(DataExpression.RAND_COLS, cols);
params.put(DataExpression.RAND_MIN, val);
params.put(DataExpression.RAND_MAX, val);
params.put(DataExpression.RAND_PDF, new LiteralOp(DataExpression.RAND_PDF_UNIFORM));
params.put(DataExpression.RAND_LAMBDA, new LiteralOp(-1.0));
params.put(DataExpression.RAND_SPARSITY, new LiteralOp(1.0));
params.put(DataExpression.RAND_SEED, new LiteralOp(DataGenOp.UNSPECIFIED_SEED) );

//note internal refresh size information
Hop datagen = new DataGenOp(OpOpDG.RAND, new DataIdentifier("tmp"), params);
datagen.setBlocksize(1000);
//copyLineNumbers(rowInput, datagen);

if( value==0 )
datagen.setNnz(0);

return datagen;
}

public static Hop createDataGenOp( Hop rowInput, Hop colInput, double value )
{
Expand Down Expand Up @@ -660,6 +684,84 @@ public static BinaryOp createBinary(Hop input1, Hop input2, OpOp2 op, boolean ou
bop.refreshSizeInformation();
return bop;
}

// To fix issues with createBinary, which does not always correctly set value types (e.g. INT-MATRIX+FLOAT-SCALAR -> bop(+)::INT)
public static BinaryOp createAutoGeneratedBinary(Hop input1, Hop input2, OpOp2 op) {
Hop mainInput = input1.getDataType().isMatrix() ? input1 :
input2.getDataType().isMatrix() ? input2 : input1;
BinaryOp bop = new BinaryOp(mainInput.getName(), getImplicitDataType(input1, input2),
getImplicitValueType(input1, input2), op, input1, input2);
//cleanup value type for relational operations
if( bop.isPPredOperation() && bop.getDataType().isScalar() )
bop.setValueType(ValueType.BOOLEAN);
bop.setOuterVectorOperation(false);
bop.setBlocksize(mainInput.getBlocksize());
copyLineNumbers(mainInput, bop);
bop.refreshSizeInformation();
return bop;
}

public static DataType getImplicitDataType(Hop... inputs) {
for (int i = 0; i < inputs.length; i++)
if (inputs[i].getDataType().isMatrix())
return inputs[i].getDataType();

return inputs[0].getDataType();
}

public static ValueType getImplicitValueType(Hop... inputs) {
ValueType out = null;
for (int i = 0; i < inputs.length; i++) {
switch (inputs[i].getValueType()) {
case FP64:
return inputs[i].getValueType();
case FP32:
out = inputs[i].getValueType();
break;
case INT64:
out = implicitValueType(out, ValueType.INT64);
break;
case INT32:
out = implicitValueType(out, ValueType.INT32);
break;
case BOOLEAN:
out = implicitValueType(out, ValueType.BOOLEAN);
break;
}
}

return out == null ? inputs[0].getValueType() : out;
}

private static ValueType implicitValueType(ValueType type1, ValueType type2) {
int rank1 = getTypeRank(type1);
int rank2 = getTypeRank(type2);

if (rank1 == Integer.MIN_VALUE && rank2 == Integer.MIN_VALUE)
return null;

return rank1 > rank2 ? type1 : type2;
}

private static int getTypeRank(ValueType vt) {
if (vt == null)
return Integer.MIN_VALUE;

switch (vt) {
case FP64:
return 5;
case FP32:
return 4;
case INT64:
return 3;
case INT32:
return 2;
case BOOLEAN:
return 1;
}

return Integer.MIN_VALUE;
}

public static AggUnaryOp createSum( Hop input ) {
return createAggUnaryOp(input, AggOp.SUM, Direction.RowCol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import org.apache.sysds.conf.CompilerConfig.ConfigType;
import org.apache.sysds.hops.Hop;
import org.apache.sysds.hops.OptimizerUtils;
import org.apache.sysds.hops.rewriter.generated.GeneratedRewriteClass;
import org.apache.sysds.hops.rewriter.generated.RewriteAutomaticallyGenerated;
import org.apache.sysds.hops.rewriter.dml.DMLExecutor;
import org.apache.sysds.parser.DMLProgram;
import org.apache.sysds.parser.ForStatement;
import org.apache.sysds.parser.ForStatementBlock;
Expand Down Expand Up @@ -83,6 +86,9 @@ public ProgramRewriter(boolean staticRewrites, boolean dynamicRewrites)
_dagRuleSet.add( new RewriteCommonSubexpressionElimination() );
if( OptimizerUtils.ALLOW_CONSTANT_FOLDING )
_dagRuleSet.add( new RewriteConstantFolding() ); //dependency: cse
if ( DMLScript.APPLY_GENERATED_REWRITES ) {
_dagRuleSet.add(new RewriteAutomaticallyGenerated(new GeneratedRewriteClass()));
}
if( OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION )
_dagRuleSet.add( new RewriteAlgebraicSimplificationStatic() ); //dependencies: cse
if( OptimizerUtils.ALLOW_COMMON_SUBEXPRESSION_ELIMINATION ) //dependency: simplifications (no need to merge leafs again)
Expand Down Expand Up @@ -124,6 +130,9 @@ public ProgramRewriter(boolean staticRewrites, boolean dynamicRewrites)
if ( DMLScript.USE_ACCELERATOR ){
_dagRuleSet.add( new RewriteGPUSpecificOps() ); // gpu-specific rewrites
}
if ( DMLScript.APPLY_GENERATED_REWRITES ) {
_dagRuleSet.add(new RewriteAutomaticallyGenerated(new GeneratedRewriteClass()));
}
if ( OptimizerUtils.ALLOW_SUM_PRODUCT_REWRITES) {
_dagRuleSet.add( new RewriteMatrixMultChainOptimization() ); //dependency: cse
if( OptimizerUtils.ALLOW_SUM_PRODUCT_REWRITES2 )
Expand Down
Loading
Loading