Repository: systemml Updated Branches: refs/heads/master 4d1ee8e19 -> cc90a0e59
http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/BinaryMatrixBVectorSPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/BinaryMatrixBVectorSPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/BinaryMatrixBVectorSPInstruction.java new file mode 100644 index 0000000..4317be5 --- /dev/null +++ b/src/main/java/org/apache/sysml/runtime/instructions/spark/BinaryMatrixBVectorSPInstruction.java @@ -0,0 +1,44 @@ +/* + * 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.sysml.runtime.instructions.spark; + +import org.apache.sysml.lops.BinaryM.VectorType; +import org.apache.sysml.runtime.DMLRuntimeException; +import org.apache.sysml.runtime.controlprogram.context.ExecutionContext; +import org.apache.sysml.runtime.instructions.cp.CPOperand; +import org.apache.sysml.runtime.matrix.operators.Operator; + +public class BinaryMatrixBVectorSPInstruction extends BinarySPInstruction { + private VectorType _vtype = null; + + protected BinaryMatrixBVectorSPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, + VectorType vtype, String opcode, String istr) throws DMLRuntimeException { + super(SPType.Binary, op, in1, in2, out, opcode, istr); + _vtype = vtype; + } + + @Override + public void processInstruction(ExecutionContext ec) + throws DMLRuntimeException + { + //common binary matrix-broadcast vector process instruction + super.processMatrixBVectorBinaryInstruction(ec, _vtype); + } +} http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/BinaryMatrixMatrixSPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/BinaryMatrixMatrixSPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/BinaryMatrixMatrixSPInstruction.java new file mode 100644 index 0000000..8a122af --- /dev/null +++ b/src/main/java/org/apache/sysml/runtime/instructions/spark/BinaryMatrixMatrixSPInstruction.java @@ -0,0 +1,41 @@ +/* + * 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.sysml.runtime.instructions.spark; + +import org.apache.sysml.runtime.DMLRuntimeException; +import org.apache.sysml.runtime.controlprogram.context.ExecutionContext; +import org.apache.sysml.runtime.instructions.cp.CPOperand; +import org.apache.sysml.runtime.matrix.operators.Operator; + +public class BinaryMatrixMatrixSPInstruction extends BinarySPInstruction { + + protected BinaryMatrixMatrixSPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, + String opcode, String istr) throws DMLRuntimeException { + super(SPType.Binary, op, in1, in2, out, opcode, istr); + } + + @Override + public void processInstruction(ExecutionContext ec) + throws DMLRuntimeException + { + //common binary matrix-matrix process instruction + super.processMatrixMatrixBinaryInstruction(ec); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/BinaryMatrixScalarSPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/BinaryMatrixScalarSPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/BinaryMatrixScalarSPInstruction.java new file mode 100644 index 0000000..cbce94e --- /dev/null +++ b/src/main/java/org/apache/sysml/runtime/instructions/spark/BinaryMatrixScalarSPInstruction.java @@ -0,0 +1,41 @@ +/* + * 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.sysml.runtime.instructions.spark; + +import org.apache.sysml.runtime.DMLRuntimeException; +import org.apache.sysml.runtime.controlprogram.context.ExecutionContext; +import org.apache.sysml.runtime.instructions.cp.CPOperand; +import org.apache.sysml.runtime.matrix.operators.Operator; + +public class BinaryMatrixScalarSPInstruction extends BinarySPInstruction { + + protected BinaryMatrixScalarSPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, + String opcode, String istr) { + super(SPType.Binary, op, in1, in2, out, opcode, istr); + } + + @Override + public void processInstruction(ExecutionContext ec) + throws DMLRuntimeException + { + //common binary matrix-scalar process instruction + super.processMatrixScalarBinaryInstruction(ec); + } +} http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/BinarySPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/BinarySPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/BinarySPInstruction.java index 5c1d21f..afcd7af 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/BinarySPInstruction.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/spark/BinarySPInstruction.java @@ -20,9 +20,10 @@ package org.apache.sysml.runtime.instructions.spark; import org.apache.spark.api.java.JavaPairRDD; - +import org.apache.sysml.lops.Lop; import org.apache.sysml.lops.BinaryM.VectorType; import org.apache.sysml.parser.Expression.DataType; +import org.apache.sysml.parser.Expression.ValueType; import org.apache.sysml.runtime.DMLRuntimeException; import org.apache.sysml.runtime.controlprogram.context.ExecutionContext; import org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext; @@ -47,6 +48,49 @@ public abstract class BinarySPInstruction extends ComputationSPInstruction { protected BinarySPInstruction(SPType type, Operator op, CPOperand in1, CPOperand in2, CPOperand out, String opcode, String istr) { super(type, op, in1, in2, out, opcode, istr); } + + public static BinarySPInstruction parseInstruction ( String str ) + throws DMLRuntimeException + { + CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN); + CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN); + CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN); + String opcode = null; + boolean isBroadcast = false; + VectorType vtype = null; + + if(str.startsWith("SPARK"+Lop.OPERAND_DELIMITOR+"map")) { + String[] parts = InstructionUtils.getInstructionPartsWithValueType(str); + InstructionUtils.checkNumFields ( parts, 5 ); + + opcode = parts[0]; + in1.split(parts[1]); + in2.split(parts[2]); + out.split(parts[3]); + vtype = VectorType.valueOf(parts[5]); + isBroadcast = true; + } + else { + opcode = parseBinaryInstruction(str, in1, in2, out); + } + + DataType dt1 = in1.getDataType(); + DataType dt2 = in2.getDataType(); + + Operator operator = InstructionUtils.parseExtendedBinaryOrBuiltinOperator(opcode, in1, in2); + + if (dt1 == DataType.MATRIX || dt2 == DataType.MATRIX) { + if(dt1 == DataType.MATRIX && dt2 == DataType.MATRIX) { + if(isBroadcast) + return new BinaryMatrixBVectorSPInstruction(operator, in1, in2, out, vtype, opcode, str); + else + return new BinaryMatrixMatrixSPInstruction(operator, in1, in2, out, opcode, str); + } + else + return new BinaryMatrixScalarSPInstruction(operator, in1, in2, out, opcode, str); + } + return null; + } protected static String parseBinaryInstruction(String instr, CPOperand in1, CPOperand in2, CPOperand out) throws DMLRuntimeException http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/BuiltinBinarySPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/BuiltinBinarySPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/BuiltinBinarySPInstruction.java deleted file mode 100644 index 1fe3530..0000000 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/BuiltinBinarySPInstruction.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.sysml.runtime.instructions.spark; - -import org.apache.sysml.lops.Lop; -import org.apache.sysml.lops.BinaryM.VectorType; -import org.apache.sysml.parser.Expression.DataType; -import org.apache.sysml.parser.Expression.ValueType; -import org.apache.sysml.runtime.DMLRuntimeException; -import org.apache.sysml.runtime.functionobjects.Builtin; -import org.apache.sysml.runtime.functionobjects.ValueFunction; -import org.apache.sysml.runtime.instructions.InstructionUtils; -import org.apache.sysml.runtime.instructions.cp.CPOperand; -import org.apache.sysml.runtime.matrix.operators.BinaryOperator; -import org.apache.sysml.runtime.matrix.operators.Operator; -import org.apache.sysml.runtime.matrix.operators.RightScalarOperator; - -public abstract class BuiltinBinarySPInstruction extends BinarySPInstruction { - - protected BuiltinBinarySPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, String opcode, String istr) { - super(SPType.BuiltinBinary, op, in1, in2, out, opcode, istr); - } - - public static BuiltinBinarySPInstruction parseInstruction ( String str ) - throws DMLRuntimeException - { - CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN); - CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN); - CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN); - String opcode = null; - boolean isBroadcast = false; - VectorType vtype = null; - - ValueFunction func = null; - if(str.startsWith("SPARK"+Lop.OPERAND_DELIMITOR+"map")) //map builtin function - { - String[] parts = InstructionUtils.getInstructionPartsWithValueType(str); - InstructionUtils.checkNumFields ( parts, 5 ); - - opcode = parts[0]; - in1.split(parts[1]); - in2.split(parts[2]); - out.split(parts[3]); - func = Builtin.getBuiltinFnObject(opcode.substring(3)); - vtype = VectorType.valueOf(parts[5]); - isBroadcast = true; - } - else //default builtin function - { - opcode = parseBinaryInstruction(str, in1, in2, out); - func = Builtin.getBuiltinFnObject(opcode); - } - - //sanity check value function - if( func == null ) - throw new DMLRuntimeException("Failed to create builtin value function for opcode: "+opcode); - - // Determine appropriate Function Object based on opcode - if (in1.getDataType() != in2.getDataType()) //MATRIX-SCALAR - { - return new MatrixScalarBuiltinSPInstruction(new RightScalarOperator(func, 0), in1, in2, out, opcode, str); - } - else //MATRIX-MATRIX - { - if( isBroadcast ) - return new MatrixBVectorBuiltinSPInstruction(new BinaryOperator(func), in1, in2, out, vtype, opcode, str); - else - return new MatrixMatrixBuiltinSPInstruction(new BinaryOperator(func), in1, in2, out, opcode, str); - } - } -} http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixBVectorArithmeticSPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixBVectorArithmeticSPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixBVectorArithmeticSPInstruction.java deleted file mode 100644 index 51545c0..0000000 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixBVectorArithmeticSPInstruction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.sysml.runtime.instructions.spark; - -import org.apache.sysml.lops.BinaryM.VectorType; -import org.apache.sysml.runtime.DMLRuntimeException; -import org.apache.sysml.runtime.controlprogram.context.ExecutionContext; -import org.apache.sysml.runtime.instructions.cp.CPOperand; -import org.apache.sysml.runtime.matrix.operators.Operator; - -public class MatrixBVectorArithmeticSPInstruction extends ArithmeticBinarySPInstruction { - private VectorType _vtype = null; - - protected MatrixBVectorArithmeticSPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, - VectorType vtype, String opcode, String istr) throws DMLRuntimeException { - super(op, in1, in2, out, opcode, istr); - _vtype = vtype; - // sanity check opcodes - if (!(opcode.equalsIgnoreCase("map+") || opcode.equalsIgnoreCase("map-") || opcode.equalsIgnoreCase("map*") - || opcode.equalsIgnoreCase("map/") || opcode.equalsIgnoreCase("map%%") - || opcode.equalsIgnoreCase("map%/%") || opcode.equalsIgnoreCase("map^") - || opcode.equalsIgnoreCase("map1-*"))) { - throw new DMLRuntimeException("Unknown opcode in MatrixBVectorArithmeticSPInstruction: " + toString()); - } - } - - @Override - public void processInstruction(ExecutionContext ec) - throws DMLRuntimeException - { - //common binary matrix-broadcast vector process instruction - super.processMatrixBVectorBinaryInstruction(ec, _vtype); - } -} http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixBVectorBuiltinSPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixBVectorBuiltinSPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixBVectorBuiltinSPInstruction.java deleted file mode 100644 index 76b40e0..0000000 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixBVectorBuiltinSPInstruction.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.sysml.runtime.instructions.spark; - - -import org.apache.sysml.lops.BinaryM.VectorType; -import org.apache.sysml.runtime.DMLRuntimeException; -import org.apache.sysml.runtime.controlprogram.context.ExecutionContext; -import org.apache.sysml.runtime.instructions.cp.CPOperand; -import org.apache.sysml.runtime.matrix.operators.Operator; - -public class MatrixBVectorBuiltinSPInstruction extends BuiltinBinarySPInstruction { - private VectorType _vtype = null; - - protected MatrixBVectorBuiltinSPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, - VectorType vtype, String opcode, String istr) throws DMLRuntimeException { - super(op, in1, in2, out, opcode, istr); - _vtype = vtype; - // sanity check opcodes - if (!(opcode.equalsIgnoreCase("mapmax") || opcode.equalsIgnoreCase("mapmin"))) { - throw new DMLRuntimeException("Unknown opcode in MatrixBVectorBuiltinSPInstruction: " + toString()); - } - } - - @Override - public void processInstruction(ExecutionContext ec) - throws DMLRuntimeException - { - //common binary matrix-broadcast vector process instruction - super.processMatrixBVectorBinaryInstruction(ec, _vtype); - } -} http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixBVectorRelationalSPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixBVectorRelationalSPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixBVectorRelationalSPInstruction.java deleted file mode 100644 index 27cb813..0000000 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixBVectorRelationalSPInstruction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.sysml.runtime.instructions.spark; - -import org.apache.sysml.lops.BinaryM.VectorType; -import org.apache.sysml.runtime.DMLRuntimeException; -import org.apache.sysml.runtime.controlprogram.context.ExecutionContext; -import org.apache.sysml.runtime.instructions.cp.CPOperand; -import org.apache.sysml.runtime.matrix.operators.Operator; - -public class MatrixBVectorRelationalSPInstruction extends RelationalBinarySPInstruction { - private VectorType _vtype = null; - - protected MatrixBVectorRelationalSPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, - VectorType vtype, String opcode, String istr) throws DMLRuntimeException { - super(op, in1, in2, out, opcode, istr); - _vtype = vtype; - // sanity check opcodes - if (!(opcode.equalsIgnoreCase("map==") || opcode.equalsIgnoreCase("map!=") || opcode.equalsIgnoreCase("map<") - || opcode.equalsIgnoreCase("map>") || opcode.equalsIgnoreCase("map<=") - || opcode.equalsIgnoreCase("map>="))) { - throw new DMLRuntimeException("Unknown opcode in MatrixBVectorRelationalSPInstruction: " + toString()); - } - } - - @Override - public void processInstruction(ExecutionContext ec) - throws DMLRuntimeException - { - //common binary matrix-broadcast vector process instruction - super.processMatrixBVectorBinaryInstruction(ec, _vtype); - } -} http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixArithmeticSPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixArithmeticSPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixArithmeticSPInstruction.java deleted file mode 100644 index 95a355d..0000000 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixArithmeticSPInstruction.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.sysml.runtime.instructions.spark; - -import org.apache.sysml.runtime.DMLRuntimeException; -import org.apache.sysml.runtime.controlprogram.context.ExecutionContext; -import org.apache.sysml.runtime.instructions.cp.CPOperand; -import org.apache.sysml.runtime.matrix.operators.Operator; - -public class MatrixMatrixArithmeticSPInstruction extends ArithmeticBinarySPInstruction { - - protected MatrixMatrixArithmeticSPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, - String opcode, String istr) throws DMLRuntimeException { - super(op, in1, in2, out, opcode, istr); - } - - @Override - public void processInstruction(ExecutionContext ec) - throws DMLRuntimeException - { - //common binary matrix-matrix process instruction - super.processMatrixMatrixBinaryInstruction(ec); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixBuiltinSPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixBuiltinSPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixBuiltinSPInstruction.java deleted file mode 100644 index 147f24e..0000000 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixBuiltinSPInstruction.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.sysml.runtime.instructions.spark; - -import org.apache.sysml.runtime.DMLRuntimeException; -import org.apache.sysml.runtime.controlprogram.context.ExecutionContext; -import org.apache.sysml.runtime.instructions.cp.CPOperand; -import org.apache.sysml.runtime.matrix.operators.Operator; - -public class MatrixMatrixBuiltinSPInstruction extends BuiltinBinarySPInstruction { - - protected MatrixMatrixBuiltinSPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, String opcode, - String istr) { - super(op, in1, in2, out, opcode, istr); - } - - @Override - public void processInstruction(ExecutionContext ec) - throws DMLRuntimeException - { - //common binary matrix-matrix process instruction - super.processMatrixMatrixBinaryInstruction(ec); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixRelationalSPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixRelationalSPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixRelationalSPInstruction.java deleted file mode 100644 index 0494ecd..0000000 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixRelationalSPInstruction.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.sysml.runtime.instructions.spark; - -import org.apache.sysml.runtime.DMLRuntimeException; -import org.apache.sysml.runtime.controlprogram.context.ExecutionContext; -import org.apache.sysml.runtime.instructions.cp.CPOperand; -import org.apache.sysml.runtime.matrix.operators.Operator; - -public class MatrixMatrixRelationalSPInstruction extends RelationalBinarySPInstruction { - - protected MatrixMatrixRelationalSPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, - String opcode, String istr) throws DMLRuntimeException { - super(op, in1, in2, out, opcode, istr); - - // sanity check opcodes - if (!(opcode.equalsIgnoreCase("==") || opcode.equalsIgnoreCase("!=") || opcode.equalsIgnoreCase("<") - || opcode.equalsIgnoreCase(">") || opcode.equalsIgnoreCase("<=") || opcode.equalsIgnoreCase(">="))) { - throw new DMLRuntimeException("Unknown opcode in MatrixMatrixRelationalSPInstruction: " + toString()); - } - } - - @Override - public void processInstruction(ExecutionContext ec) - throws DMLRuntimeException - { - //common binary matrix-matrix process instruction - super.processMatrixMatrixBinaryInstruction(ec); - } -} http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixScalarArithmeticSPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixScalarArithmeticSPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixScalarArithmeticSPInstruction.java deleted file mode 100644 index 5b51893..0000000 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixScalarArithmeticSPInstruction.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.sysml.runtime.instructions.spark; - -import org.apache.sysml.runtime.DMLRuntimeException; -import org.apache.sysml.runtime.controlprogram.context.ExecutionContext; -import org.apache.sysml.runtime.instructions.cp.CPOperand; -import org.apache.sysml.runtime.matrix.operators.Operator; - -public class MatrixScalarArithmeticSPInstruction extends ArithmeticBinarySPInstruction { - - protected MatrixScalarArithmeticSPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, - String opcode, String istr) { - super(op, in1, in2, out, opcode, istr); - } - - @Override - public void processInstruction(ExecutionContext ec) - throws DMLRuntimeException - { - //sanity check opcode - String opcode = getOpcode(); - if ( !(opcode.equalsIgnoreCase("+") || opcode.equalsIgnoreCase("-") || opcode.equalsIgnoreCase("*") - || opcode.equalsIgnoreCase("/") || opcode.equalsIgnoreCase("%%") || opcode.equalsIgnoreCase("%/%") - || opcode.equalsIgnoreCase("^") || opcode.equalsIgnoreCase("^2") - || opcode.equalsIgnoreCase("*2") || opcode.equalsIgnoreCase("1-*")) ) - { - throw new DMLRuntimeException("Unknown opcode in instruction: " + opcode); - } - - //common binary matrix-scalar process instruction - super.processMatrixScalarBinaryInstruction(ec); - } -} http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixScalarBuiltinSPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixScalarBuiltinSPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixScalarBuiltinSPInstruction.java deleted file mode 100644 index 6077d42..0000000 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixScalarBuiltinSPInstruction.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.sysml.runtime.instructions.spark; - -import org.apache.sysml.runtime.DMLRuntimeException; -import org.apache.sysml.runtime.controlprogram.context.ExecutionContext; -import org.apache.sysml.runtime.instructions.cp.CPOperand; -import org.apache.sysml.runtime.matrix.operators.Operator; - -public class MatrixScalarBuiltinSPInstruction extends BuiltinBinarySPInstruction { - - protected MatrixScalarBuiltinSPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, String opcode, - String instr) { - super(op, in1, in2, out, opcode, instr); - } - - @Override - public void processInstruction(ExecutionContext ec) - throws DMLRuntimeException - { - //sanity check opcode - String opcode = getOpcode(); - if (!(opcode.equalsIgnoreCase("max") || opcode.equalsIgnoreCase("min") - ||opcode.equalsIgnoreCase("log") || opcode.equalsIgnoreCase("log_nz")) ) - { - throw new DMLRuntimeException("Unknown opcode in instruction: " + opcode); - } - - //common binary matrix-scalar process instruction - super.processMatrixScalarBinaryInstruction(ec); - } -} http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixScalarRelationalSPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixScalarRelationalSPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixScalarRelationalSPInstruction.java deleted file mode 100644 index a7f5392..0000000 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixScalarRelationalSPInstruction.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.sysml.runtime.instructions.spark; - -import org.apache.sysml.runtime.DMLRuntimeException; -import org.apache.sysml.runtime.controlprogram.context.ExecutionContext; -import org.apache.sysml.runtime.instructions.cp.CPOperand; -import org.apache.sysml.runtime.matrix.operators.Operator; - -public class MatrixScalarRelationalSPInstruction extends RelationalBinarySPInstruction { - - protected MatrixScalarRelationalSPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, - String opcode, String istr) { - super(op, in1, in2, out, opcode, istr); - } - - @Override - public void processInstruction(ExecutionContext ec) - throws DMLRuntimeException - { - String opcode = getOpcode(); - if ( !(opcode.equalsIgnoreCase("==") || opcode.equalsIgnoreCase("!=") || opcode.equalsIgnoreCase("<") - || opcode.equalsIgnoreCase(">") || opcode.equalsIgnoreCase("<=") || opcode.equalsIgnoreCase(">=")) ) - { - throw new DMLRuntimeException("Unknown opcode in instruction: " + opcode); - } - - //common binary matrix-scalar process instruction - super.processMatrixScalarBinaryInstruction(ec); - } -} http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/PlusMultSPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/PlusMultSPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/PlusMultSPInstruction.java index 9504551..e12cd3e 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/PlusMultSPInstruction.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/spark/PlusMultSPInstruction.java @@ -30,10 +30,10 @@ import org.apache.sysml.runtime.instructions.cp.CPOperand; import org.apache.sysml.runtime.instructions.cp.ScalarObject; import org.apache.sysml.runtime.matrix.operators.BinaryOperator; -public class PlusMultSPInstruction extends ArithmeticBinarySPInstruction { +public class PlusMultSPInstruction extends BinarySPInstruction { private PlusMultSPInstruction(BinaryOperator op, CPOperand in1, CPOperand in2, CPOperand in3, CPOperand out, String opcode, String str) throws DMLRuntimeException { - super(op, in1, in2, out, opcode, str); + super(SPType.Binary, op, in1, in2, out, opcode, str); input3 = in3; // sanity check opcodes @@ -52,7 +52,7 @@ public class PlusMultSPInstruction extends ArithmeticBinarySPInstruction { CPOperand outOperand = new CPOperand(parts[4]); BinaryOperator bOperator = new BinaryOperator(opcode.equals("+*") ? PlusMultiply.getPlusMultiplyFnObject():MinusMultiply.getMinusMultiplyFnObject()); - return new PlusMultSPInstruction(bOperator,operand1, operand2, operand3, outOperand, opcode,str); + return new PlusMultSPInstruction(bOperator,operand1, operand2, operand3, outOperand, opcode,str); } @Override http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/RelationalBinarySPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/RelationalBinarySPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/RelationalBinarySPInstruction.java deleted file mode 100644 index da07620..0000000 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/RelationalBinarySPInstruction.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.sysml.runtime.instructions.spark; - -import org.apache.sysml.lops.Lop; -import org.apache.sysml.lops.BinaryM.VectorType; -import org.apache.sysml.parser.Expression.DataType; -import org.apache.sysml.parser.Expression.ValueType; -import org.apache.sysml.runtime.DMLRuntimeException; -import org.apache.sysml.runtime.instructions.InstructionUtils; -import org.apache.sysml.runtime.instructions.cp.CPOperand; -import org.apache.sysml.runtime.matrix.operators.Operator; - -public abstract class RelationalBinarySPInstruction extends BinarySPInstruction { - - protected RelationalBinarySPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, String opcode, String istr) { - super(SPType.RelationalBinary, op, in1, in2, out, opcode, istr); - } - - public static RelationalBinarySPInstruction parseInstruction ( String str ) - throws DMLRuntimeException - { - CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN); - CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN); - CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN); - String opcode = null; - boolean isBroadcast = false; - VectorType vtype = null; - - if(str.startsWith("SPARK"+Lop.OPERAND_DELIMITOR+"map")) { - String[] parts = InstructionUtils.getInstructionPartsWithValueType(str); - InstructionUtils.checkNumFields ( parts, 5 ); - - opcode = parts[0]; - in1.split(parts[1]); - in2.split(parts[2]); - out.split(parts[3]); - vtype = VectorType.valueOf(parts[5]); - isBroadcast = true; - } - else { - InstructionUtils.checkNumFields (str, 3); - opcode = parseBinaryInstruction(str, in1, in2, out); - } - - DataType dt1 = in1.getDataType(); - DataType dt2 = in2.getDataType(); - - Operator operator = (dt1 != dt2) ? - InstructionUtils.parseScalarBinaryOperator(opcode, (dt1 == DataType.SCALAR)) - : InstructionUtils.parseExtendedBinaryOperator(opcode); - - if (dt1 == DataType.MATRIX || dt2 == DataType.MATRIX){ - if(dt1 == DataType.MATRIX && dt2 == DataType.MATRIX) { - if(isBroadcast) - return new MatrixBVectorRelationalSPInstruction(operator, in1, in2, out, vtype, opcode, str); - else - return new MatrixMatrixRelationalSPInstruction(operator, in1, in2, out, opcode, str); - } - else - return new MatrixScalarRelationalSPInstruction(operator, in1, in2, out, opcode, str); - } - - return null; - } -} http://git-wip-us.apache.org/repos/asf/systemml/blob/cc90a0e5/src/main/java/org/apache/sysml/runtime/instructions/spark/SPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/SPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/SPInstruction.java index 09cb78a..8ff4640 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/SPInstruction.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/spark/SPInstruction.java @@ -31,9 +31,9 @@ public abstract class SPInstruction extends Instruction { public enum SPType { MAPMM, MAPMMCHAIN, CPMM, RMM, TSMM, TSMM2, PMM, ZIPMM, PMAPMM, //matrix multiplication instructions - MatrixIndexing, Reorg, ArithmeticBinary, RelationalBinary, + MatrixIndexing, Reorg, Binary, AggregateUnary, AggregateTernary, Reblock, CSVReblock, - Builtin, BuiltinUnary, BuiltinBinary, BuiltinNary, MultiReturnBuiltin, Checkpoint, Compression, Cast, + Builtin, BuiltinUnary, BuiltinNary, MultiReturnBuiltin, Checkpoint, Compression, Cast, CentralMoment, Covariance, QSort, QPick, ParameterizedBuiltin, MAppend, RAppend, GAppend, GAlignedAppend, Rand, MatrixReshape, Ternary, Quaternary, CumsumAggregate, CumsumOffset, BinUaggChain, UaggOuterChain,
