-
Notifications
You must be signed in to change notification settings - Fork 541
[SYSTEMDS-3899] Unary out-of-core operations #2298
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
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5f0fd56
add test to invoke ooc unary op
j143 e03f630
fix dml file
j143 24598d6
ceil(X) output is empty
j143 ebaeff0
code related to unaryooc parseinstruction is called
j143 10e7617
program not reaching the threads
j143 43f997a
fix cpoperand input types
j143 9789243
input stream not yet reaching the threads
j143 44aba46
pass only the opcode for profiling
j143 ab7a585
add Future and task.get() to wait
j143 f306f69
test pass but write is not successful
j143 5459499
remove unused imports
j143 6533052
address review comments
j143 8819b62
add a basic test, verify it with aggregation
j143 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
90 changes: 90 additions & 0 deletions
90
src/main/java/org/apache/sysds/runtime/instructions/ooc/UnaryOOCInstruction.java
This file contains hidden or 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,90 @@ | ||
| /* | ||
| * 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.sysds.runtime.instructions.ooc; | ||
|
|
||
| import org.apache.sysds.runtime.DMLRuntimeException; | ||
| import org.apache.sysds.runtime.controlprogram.caching.MatrixObject; | ||
| import org.apache.sysds.runtime.controlprogram.context.ExecutionContext; | ||
| import org.apache.sysds.runtime.controlprogram.parfor.LocalTaskQueue; | ||
| import org.apache.sysds.runtime.instructions.InstructionUtils; | ||
| import org.apache.sysds.runtime.instructions.cp.CPOperand; | ||
| import org.apache.sysds.runtime.instructions.spark.data.IndexedMatrixValue; | ||
| import org.apache.sysds.runtime.matrix.data.MatrixBlock; | ||
| import org.apache.sysds.runtime.matrix.operators.UnaryOperator; | ||
| import org.apache.sysds.runtime.util.CommonThreadPool; | ||
|
|
||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.Future; | ||
|
|
||
| public class UnaryOOCInstruction extends ComputationOOCInstruction { | ||
| private UnaryOperator _uop = null; | ||
|
|
||
| protected UnaryOOCInstruction(OOCType type, UnaryOperator op, CPOperand in1, CPOperand out, String opcode, String istr) { | ||
| super(type, op, in1, out, opcode, istr); | ||
|
|
||
| _uop = op; | ||
| } | ||
|
|
||
| public static UnaryOOCInstruction parseInstruction(String str) { | ||
| String[] parts = InstructionUtils.getInstructionPartsWithValueType(str); | ||
| InstructionUtils.checkNumFields(parts, 2); | ||
| String opcode = parts[0]; | ||
| CPOperand in1 = new CPOperand(parts[1]); | ||
| CPOperand out = new CPOperand(parts[2]); | ||
|
|
||
| UnaryOperator uopcode = InstructionUtils.parseUnaryOperator(opcode); | ||
| return new UnaryOOCInstruction(OOCType.Unary, uopcode, in1, out, opcode, str); | ||
| } | ||
|
|
||
| public void processInstruction( ExecutionContext ec ) { | ||
| UnaryOperator uop = (UnaryOperator) _uop; | ||
| // Create thread and process the unary operation | ||
| MatrixObject min = ec.getMatrixObject(input1); | ||
| LocalTaskQueue<IndexedMatrixValue> qIn = min.getStreamHandle(); | ||
| LocalTaskQueue<IndexedMatrixValue> qOut = new LocalTaskQueue<>(); | ||
| ec.getMatrixObject(output).setStreamHandle(qOut); | ||
|
|
||
|
|
||
| ExecutorService pool = CommonThreadPool.get(); | ||
| try { | ||
| Future<?> task =pool.submit(() -> { | ||
| IndexedMatrixValue tmp = null; | ||
| try { | ||
| while ((tmp = qIn.dequeueTask()) != LocalTaskQueue.NO_MORE_TASKS) { | ||
| IndexedMatrixValue tmpOut = new IndexedMatrixValue(); | ||
| tmpOut.set(tmp.getIndexes(), | ||
| tmp.getValue().unaryOperations(uop, new MatrixBlock())); | ||
| qOut.enqueueTask(tmpOut); | ||
| } | ||
| qOut.closeInput(); | ||
| } | ||
| catch(Exception ex) { | ||
| throw new DMLRuntimeException(ex); | ||
| } | ||
| }); | ||
| task.get(); | ||
| } catch (ExecutionException | InterruptedException e) { | ||
| throw new RuntimeException(e); | ||
| } finally { | ||
| pool.shutdown(); | ||
| } | ||
| } | ||
| } | ||
114 changes: 114 additions & 0 deletions
114
src/test/java/org/apache/sysds/test/functions/ooc/UnaryTest.java
This file contains hidden or 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,114 @@ | ||
| /* | ||
| * 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.sysds.test.functions.ooc; | ||
|
|
||
| import org.apache.sysds.common.Opcodes; | ||
| import org.apache.sysds.common.Types; | ||
| import org.apache.sysds.common.Types.FileFormat; | ||
| import org.apache.sysds.common.Types.ValueType; | ||
| import org.apache.sysds.hops.OptimizerUtils; | ||
| import org.apache.sysds.runtime.instructions.Instruction; | ||
| import org.apache.sysds.runtime.io.MatrixWriter; | ||
| import org.apache.sysds.runtime.io.MatrixWriterFactory; | ||
| import org.apache.sysds.runtime.matrix.data.MatrixBlock; | ||
| import org.apache.sysds.runtime.matrix.data.MatrixValue; | ||
| import org.apache.sysds.runtime.meta.MatrixCharacteristics; | ||
| import org.apache.sysds.runtime.util.HDFSTool; | ||
| import org.apache.sysds.test.AutomatedTestBase; | ||
| import org.apache.sysds.test.TestConfiguration; | ||
| import org.apache.sysds.test.TestUtils; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import java.util.HashMap; | ||
|
|
||
| public class UnaryTest extends AutomatedTestBase { | ||
|
|
||
| private static final String TEST_NAME = "Unary"; | ||
| private static final String TEST_DIR = "functions/ooc/"; | ||
| private static final String TEST_CLASS_DIR = TEST_DIR + UnaryTest.class.getSimpleName() + "/"; | ||
| private static final String INPUT_NAME = "X"; | ||
| private static final String OUTPUT_NAME = "res"; | ||
|
|
||
| @Override | ||
| public void setUp() { | ||
| TestUtils.clearAssertionInformation(); | ||
| TestConfiguration config = new TestConfiguration(TEST_CLASS_DIR, TEST_NAME); | ||
| addTestConfiguration(TEST_NAME, config); | ||
| } | ||
|
|
||
| /** | ||
| * Test the sum of scalar multiplication, "sum(X*7)", with OOC backend. | ||
| */ | ||
| @Test | ||
| public void testUnary() { | ||
| testUnaryOperation(false); | ||
| } | ||
|
|
||
|
|
||
| public void testUnaryOperation(boolean rewrite) | ||
| { | ||
| Types.ExecMode platformOld = rtplatform; | ||
| rtplatform = Types.ExecMode.SINGLE_NODE; | ||
| boolean oldRewrite = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION; | ||
| OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = rewrite; | ||
|
|
||
| try { | ||
| getAndLoadTestConfiguration(TEST_NAME); | ||
| String HOME = SCRIPT_DIR + TEST_DIR; | ||
| fullDMLScriptName = HOME + TEST_NAME + ".dml"; | ||
| programArgs = new String[] {"-explain", "-stats", "-ooc", | ||
| "-args", input(INPUT_NAME), output(OUTPUT_NAME)}; | ||
|
|
||
| int rows = 1000, cols = 1000; | ||
| MatrixBlock mb = MatrixBlock.randOperations(rows, cols, 1.0, -1, 1, "uniform", 7); | ||
| MatrixWriter writer = MatrixWriterFactory.createMatrixWriter(FileFormat.BINARY); | ||
| writer.writeMatrixToHDFS(mb, input(INPUT_NAME), rows, cols, 1000, rows*cols); | ||
| HDFSTool.writeMetaDataFile(input(INPUT_NAME+".mtd"), ValueType.FP64, | ||
| new MatrixCharacteristics(rows,cols,1000,rows*cols), FileFormat.BINARY); | ||
|
|
||
| runTest(true, false, null, -1); | ||
|
|
||
| HashMap<MatrixValue.CellIndex, Double> dmlfile = readDMLMatrixFromOutputDir(OUTPUT_NAME); | ||
| Double result = dmlfile.get(new MatrixValue.CellIndex(1, 1)); | ||
| double expected = 0.0; | ||
| for(int i = 0; i < rows; i++) { | ||
| for(int j = 0; j < cols; j++) { | ||
| expected += Math.ceil(mb.get(i, j)); | ||
| } | ||
| } | ||
|
|
||
| Assert.assertEquals(expected, result, 1e-10); | ||
|
|
||
| String prefix = Instruction.OOC_INST_PREFIX; | ||
| Assert.assertTrue("OOC wasn't used for RBLK", | ||
| heavyHittersContainsString(prefix + Opcodes.RBLK)); | ||
| Assert.assertTrue("OOC wasn't used for CEIL", | ||
| heavyHittersContainsString(prefix + Opcodes.CEIL)); | ||
| } | ||
| catch(Exception ex) { | ||
| Assert.fail(ex.getMessage()); | ||
| } | ||
| finally { | ||
| OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldRewrite; | ||
| resetExecMode(platformOld); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,29 @@ | ||
| #------------------------------------------------------------- | ||
| # | ||
| # 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. | ||
| # | ||
| #------------------------------------------------------------- | ||
|
|
||
| # Read input matrix and operator from command line args | ||
| X = read($1); | ||
| #print(toString(X)) | ||
| Y = ceil(X); | ||
| #print(toString(Y)) | ||
| res = as.matrix(sum(Y)); | ||
| # Write the final matrix result | ||
| write(res, $2); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.