-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] First implementation for a pipeline-aware linearization algorithm.
Includes initial steps for approaching testing. Includes helper class for debugging.
- Loading branch information
1 parent
02d4b01
commit c134ed7
Showing
6 changed files
with
320 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/org/apache/sysds/lops/compile/linearization/DEVPrintDAG.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.apache.sysds.lops.compile.linearization; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
import org.apache.sysds.lops.Lop; | ||
|
||
//DEBUGGING PURPOSES WHILE DEVELOPING | ||
public class DEVPrintDAG { | ||
|
||
static void asGraphviz(String filePrefix, List<Lop> v) { | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
sb.append("digraph G {\n"); | ||
|
||
for (int i = 0; i < v.size(); i++) { | ||
Lop l = v.get(i); | ||
|
||
String cutted_l = l.toString().substring(0, Math.min(l.toString().length(), 75)); | ||
String toString[] = cutted_l.replaceAll("((.*?\\s){" + (2) + "})", "$1@").split("@"); | ||
String toString2 = String.join("\n", toString); | ||
sb.append(l.getID() + " [label=\"" + l.getID() + "::" + i + "::" + l.getPipelineID() + " " + l.getType() + " " + l.getLevel() + ":\n " + toString2 +"\", style=filled, color="+ DEVPrintDAG.getColorName(l.getPipelineID()) +"];\n"); | ||
|
||
for (Lop in : l.getInputs()) { | ||
sb.append(in.getID() + " -> " + l.getID() + ";\n"); | ||
//sb.append(l.getID() + " -> " + in.getID() + ";\n"); | ||
} | ||
} | ||
|
||
sb.append("}\n"); | ||
|
||
String currentProcessId = String.valueOf(ProcessHandle.current().pid()); | ||
|
||
String folderName = "graphs/graphs_" + currentProcessId; | ||
File folder = new File(folderName); | ||
|
||
if (!folder.exists()) { | ||
folder.mkdirs(); | ||
} | ||
|
||
String filename = folderName + "/" + filePrefix + "_" + v.size() + "_" + System.currentTimeMillis() + ".dot"; | ||
try { | ||
Files.write(Paths.get(filename), sb.toString().getBytes()); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
//Colors only correctly work with VSCode extension: Graphviz Interactive Preview | ||
private static String getColorName(int value) { | ||
String[] colors = { | ||
"red", "orange", "yellow", "green", "blue", "indigo", "violet", | ||
"teal", "purple", "pink", "brown", "beige", "cyan", "turquoise", | ||
"lime", "olive", "mediumseagreen", "azure", "aquamarine", "magenta", | ||
"silver", "gold", "goldenrod4", "sienna2", "deeppink3", "darkolivegreen", "grey52", | ||
"darkslateblue", "darkkhaki", "cornflowerblue", "yellowgreen", "chartreuse2", "navyblue" | ||
}; | ||
|
||
if (value < 0) { | ||
return "lightgrey"; | ||
} | ||
|
||
return colors[value % 32]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/test/java/org/apache/sysds/test/functions/linearization/ILinearizeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.apache.sysds.test.functions.linearization; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.stream.Collector; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.sysds.runtime.matrix.data.MatrixValue; | ||
import org.apache.sysds.test.AutomatedTestBase; | ||
import org.apache.sysds.test.TestConfiguration; | ||
import org.apache.sysds.test.TestUtils; | ||
import org.junit.Test; | ||
|
||
//additional imports | ||
import org.apache.sysds.lops.compile.linearization.ILinearize; | ||
import org.apache.sysds.lops.Lop; | ||
import org.apache.sysds.conf.ConfigurationManager; | ||
import org.apache.sysds.conf.DMLConfig; | ||
import org.apache.sysds.lops.BinaryScalar; | ||
import org.apache.sysds.lops.Data; | ||
|
||
public class ILinearizeTest extends AutomatedTestBase { | ||
|
||
private final String testDir = "functions/linearization/"; | ||
|
||
@Override | ||
public void setUp() { | ||
setOutputBuffering(true); | ||
disableConfigFile = true; | ||
TestUtils.clearAssertionInformation(); | ||
|
||
addTestConfiguration("test", new TestConfiguration(testDir, "test")); | ||
} | ||
|
||
@Test | ||
public void testLinearize_Pipeline() { | ||
|
||
try { | ||
//DMLConfig dmlconf = DMLConfig.readConfigurationFile("/home/niklas/systemds/src/test/scripts/functions/linearization/SystemDS-config-na-pipeline.xml"); | ||
DMLConfig dmlconf = DMLConfig.readConfigurationFile("/home/niklas/systemds/src/test/scripts/functions/linearization/SystemDS-config-default.xml"); | ||
ConfigurationManager.setGlobalConfig(dmlconf); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
System.out.println("testLinearize_Pipeline"); | ||
|
||
List<Lop> lops = new ArrayList<>(); | ||
|
||
//lops.add(new Data(org.apache.sysds.common.Types.OpOpData.PERSISTENTREAD, null, null, "test", null, org.apache.sysds.common.Types.DataType.SCALAR, org.apache.sysds.common.Types.ValueType.INT32, null)); | ||
Lop lop1 = Data.createLiteralLop(org.apache.sysds.common.Types.ValueType.INT32, "1"); | ||
Lop lop2 = Data.createLiteralLop(org.apache.sysds.common.Types.ValueType.INT32, "2"); | ||
lops.add(lop1); | ||
lops.add(lop2); | ||
lops.add(new BinaryScalar(lop1, lop2, org.apache.sysds.common.Types.OpOp2.PLUS, org.apache.sysds.common.Types.DataType.SCALAR, org.apache.sysds.common.Types.ValueType.INT32)); | ||
|
||
List<Lop> result = ILinearize.linearize(lops); | ||
|
||
List<Lop> filtered = result.stream().filter(l -> l.getPipelineID() == -1).collect(Collectors.toList()); | ||
if (filtered.size() > 0) { | ||
fail("Pipeline ID not set correctly"); | ||
} | ||
|
||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/test/scripts/functions/linearization/SystemDS-config-na-pipeline.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!-- | ||
* 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. | ||
--> | ||
|
||
<root> | ||
<sysds.compile.linearization>na_pipeline</sysds.compile.linearization> | ||
</root> |