Repository: systemml Updated Branches: refs/heads/master cd1ae5b42 -> 4e47b5e10
http://git-wip-us.apache.org/repos/asf/systemml/blob/4e47b5e1/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixCUDA.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixCUDA.java b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixCUDA.java index f47c15c..17f6b22 100644 --- a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixCUDA.java +++ b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixCUDA.java @@ -2466,15 +2466,15 @@ public class LibMatrixCUDA { /** * Performs elementwise arithmetic operation specified by op of two input matrices in1 and in2 * - * @param ec execution context - * @param gCtx a valid {@link GPUContext} - * @param instName the invoking instruction's name for record {@link Statistics}. - * @param in1 input matrix 1 - * @param in2 input matrix 2 - * @param outputName output matrix name - * @param isLeftTransposed true if left-transposed + * @param ec execution context + * @param gCtx a valid {@link GPUContext} + * @param instName the invoking instruction's name for record {@link Statistics}. + * @param in1 input matrix 1 + * @param in2 input matrix 2 + * @param outputName output matrix name + * @param isLeftTransposed true if left-transposed * @param isRightTransposed true if right-transposed - * @param op binary operator + * @param op binary operator * @throws DMLRuntimeException if DMLRuntimeException occurs */ public static void matrixMatrixArithmetic(ExecutionContext ec, GPUContext gCtx, String instName, MatrixObject in1, MatrixObject in2, @@ -2506,13 +2506,14 @@ public class LibMatrixCUDA { /** * Utility to do matrix-scalar operation kernel - * @param gCtx a valid {@link GPUContext} - * @param instName the invoking instruction's name for record {@link Statistics}. - * @param ec execution context - * @param in input matrix - * @param outputName output variable name + * + * @param gCtx a valid {@link GPUContext} + * @param instName the invoking instruction's name for record {@link Statistics}. + * @param ec execution context + * @param in input matrix + * @param outputName output variable name * @param isInputTransposed true if input is transposed - * @param op operator + * @param op operator * @throws DMLRuntimeException if DMLRuntimeException occurs */ private static void matrixScalarOp(ExecutionContext ec, GPUContext gCtx, String instName, MatrixObject in, String outputName, boolean isInputTransposed, @@ -2703,9 +2704,9 @@ public class LibMatrixCUDA { /** * Performs a deep device copy of a matrix on the GPU * - * @param ec execution context - * @param instName the invoking instruction's name for record {@link Statistics}. - * @param src source matrix + * @param ec execution context + * @param instName the invoking instruction's name for record {@link Statistics}. + * @param src source matrix * @param outputName destination variable name * @throws DMLRuntimeException if DMLRuntimeException occurs */ @@ -2974,6 +2975,80 @@ public class LibMatrixCUDA { //********************************************************************/ + //********************************************************************/ + //**************** Matrix Manipulation Functions *********************/ + //********************************************************************/ + + + public static void cbind(ExecutionContext ec, GPUContext gCtx, String instName, MatrixObject in1, MatrixObject in2, String outputName) throws DMLRuntimeException { + if (ec.getGPUContext(0) != gCtx) + throw new DMLRuntimeException("GPU : Invalid internal state, the GPUContext set with the ExecutionContext is not the same used to run this LibMatrixCUDA function"); + LOG.trace("GPU : cbind" + ", GPUContext=" + gCtx); + + long t1 = 0; + + // only Dense supported + MatrixObject out = getDenseMatrixOutputForGPUInstruction(ec, instName, outputName); + Pointer C = getDensePointer(gCtx, out, instName); + Pointer A = getDensePointer(gCtx, in1, instName); + Pointer B = getDensePointer(gCtx, in2, instName); + + int rowsA = (int) in1.getNumRows(); + int colsA = (int) in1.getNumColumns(); + int rowsB = (int) in2.getNumRows(); + int colsB = (int) in2.getNumColumns(); + + if (rowsA != rowsB){ + throw new DMLRuntimeException("GPU : Invalid internal state - the rows must match up for a cbind operation"); + } + int maxRows = Math.max(rowsA, rowsB); + int maxCols = Math.max(colsA, colsB); + + if (GPUStatistics.DISPLAY_STATISTICS) t1 = System.nanoTime(); + getCudaKernels(gCtx) + .launchKernel("cbind", ExecutionConfig.getConfigForSimpleMatrixOperations(maxRows, maxCols), A, B, C, + rowsA, colsA, rowsB, colsB); + if (GPUStatistics.DISPLAY_STATISTICS) GPUStatistics.maintainCPMiscTimes(instName, GPUInstruction.MISC_TIMER_CBIND_KERNEL, System.nanoTime() - t1); + + } + + public static void rbind(ExecutionContext ec, GPUContext gCtx, String instName, MatrixObject in1, MatrixObject in2, String outputName) throws DMLRuntimeException { + if (ec.getGPUContext(0) != gCtx) + throw new DMLRuntimeException("GPU : Invalid internal state, the GPUContext set with the ExecutionContext is not the same used to run this LibMatrixCUDA function"); + LOG.trace("GPU : rbind" + ", GPUContext=" + gCtx); + + long t1 = 0; + + // only Dense supported + MatrixObject out = getDenseMatrixOutputForGPUInstruction(ec, instName, outputName); + Pointer C = getDensePointer(gCtx, out, instName); + Pointer A = getDensePointer(gCtx, in1, instName); + Pointer B = getDensePointer(gCtx, in2, instName); + + int rowsA = (int) in1.getNumRows(); + int colsA = (int) in1.getNumColumns(); + int rowsB = (int) in2.getNumRows(); + int colsB = (int) in2.getNumColumns(); + + if (colsA != colsB){ + throw new DMLRuntimeException("GPU : Invalid internal state - the columns must match up for a rbind operation"); + } + int maxRows = Math.max(rowsA, rowsB); + int maxCols = Math.max(colsA, colsB); + + if (GPUStatistics.DISPLAY_STATISTICS) t1 = System.nanoTime(); + getCudaKernels(gCtx) + .launchKernel("rbind", ExecutionConfig.getConfigForSimpleMatrixOperations(maxRows, maxCols), A, B, C, + rowsA, colsA, rowsB, colsB); + if (GPUStatistics.DISPLAY_STATISTICS) GPUStatistics.maintainCPMiscTimes(instName, GPUInstruction.MISC_TIMER_RBIND_KERNEL, System.nanoTime() - t1); + + } + + + //********************************************************************/ + //*********** End of Matrix Manipulation Functions *******************/ + //********************************************************************/ + //********************************************************************/ //************************ Builtin Functions *************************/ http://git-wip-us.apache.org/repos/asf/systemml/blob/4e47b5e1/src/test/java/org/apache/sysml/test/gpu/AppendTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/gpu/AppendTest.java b/src/test/java/org/apache/sysml/test/gpu/AppendTest.java new file mode 100644 index 0000000..930241b --- /dev/null +++ b/src/test/java/org/apache/sysml/test/gpu/AppendTest.java @@ -0,0 +1,108 @@ +/* + * 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.test.gpu; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +import org.apache.sysml.api.mlcontext.Matrix; +import org.apache.sysml.test.utils.TestUtils; +import org.junit.Test; + +/** + * Tests rbind & cbind + */ +public class AppendTest extends GPUTests { + + private final static String TEST_NAME = "BinaryOpTests"; + private final int seed = 42; + + private final int[] rowSizes = new int[] { 1, 64, 2049 }; + private final int[] columnSizes = new int[] { 1, 64, 2049 }; + private final double[] sparsities = new double[] { 0.0, 0.3, 0.9 }; + + @Override + public void setUp() { + TestUtils.clearAssertionInformation(); + addTestConfiguration(TEST_DIR, TEST_NAME); + getAndLoadTestConfiguration(TEST_NAME); + } + + @Test + public void testRbind() { + String scriptStr = "C = rbind(A, B)"; + + for (int i = 0; i < rowSizes.length; i++) { + for (int j = 0; j < columnSizes.length; j++) { + for (int k = 0; k < rowSizes.length; k++) { + for (int s = 0; s < sparsities.length; s++) { + int m1 = rowSizes[i]; + int n1 = columnSizes[j]; + int m2 = rowSizes[k]; + int n2 = n1; // for rbind number of columns in both matrices need to be the same + double sparsity = sparsities[s]; + + System.out.println("In rbind, A[" + m1 + ", " + n1 + "], B[" + m2 + "," + n2 + "]"); + Matrix A = generateInputMatrix(spark, m1, n1, sparsity, seed); + Matrix B = generateInputMatrix(spark, m2, n2, sparsity, seed); + HashMap<String, Object> inputs = new HashMap<>(); + inputs.put("A", A); + inputs.put("B", B); + List<Object> outCPU = runOnCPU(spark, scriptStr, inputs, Arrays.asList("C")); + List<Object> outGPU = runOnGPU(spark, scriptStr, inputs, Arrays.asList("C")); + assertHeavyHitterPresent("gpu_append"); + assertEqualObjects(outCPU.get(0), outGPU.get(0)); + } + } + } + } + } + + @Test + public void testCbind() { + String scriptStr = "C = cbind(A, B)"; + + for (int i = 0; i < rowSizes.length; i++) { + for (int j = 0; j < columnSizes.length; j++) { + for (int k = 0; k < columnSizes.length; k++) { + for (int s = 0; s < sparsities.length; s++) { + int m1 = rowSizes[i]; + int n1 = columnSizes[j]; + int m2 = m1; // for cbind number of rows in both matrices need to be the same + int n2 = columnSizes[k]; + double sparsity = sparsities[s]; + + System.out.println("In cbind, A[" + m1 + ", " + n1 + "], B[" + m2 + "," + n2 + "]"); + Matrix A = generateInputMatrix(spark, m1, n1, sparsity, seed); + Matrix B = generateInputMatrix(spark, m2, n2, sparsity, seed); + HashMap<String, Object> inputs = new HashMap<>(); + inputs.put("A", A); + inputs.put("B", B); + List<Object> outCPU = runOnCPU(spark, scriptStr, inputs, Arrays.asList("C")); + List<Object> outGPU = runOnGPU(spark, scriptStr, inputs, Arrays.asList("C")); + assertHeavyHitterPresent("gpu_append"); + assertEqualObjects(outCPU.get(0), outGPU.get(0)); + } + } + } + } + } +} http://git-wip-us.apache.org/repos/asf/systemml/blob/4e47b5e1/src/test_suites/java/org/apache/sysml/test/integration/gpu/ZPackageSuite.java ---------------------------------------------------------------------- diff --git a/src/test_suites/java/org/apache/sysml/test/integration/gpu/ZPackageSuite.java b/src/test_suites/java/org/apache/sysml/test/integration/gpu/ZPackageSuite.java index d5e3bc0..f9a09cc 100644 --- a/src/test_suites/java/org/apache/sysml/test/integration/gpu/ZPackageSuite.java +++ b/src/test_suites/java/org/apache/sysml/test/integration/gpu/ZPackageSuite.java @@ -20,6 +20,7 @@ package org.apache.sysml.test.integration.gpu; import org.apache.sysml.test.gpu.AggregateUnaryOpTests; +import org.apache.sysml.test.gpu.AppendTest; import org.apache.sysml.test.gpu.BinaryOpTests; import org.apache.sysml.test.gpu.MatrixMatrixElementWiseOpTests; import org.apache.sysml.test.gpu.MatrixMultiplicationOpTest; @@ -33,6 +34,7 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) @SuiteClasses({ BinaryOpTests.class, + AppendTest.class, ScalarMatrixElementwiseOpTests.class, MatrixMatrixElementWiseOpTests.class, ReorgOpTests.class,
