Search in sources :

Example 51 with MatrixObject

use of org.apache.sysml.runtime.controlprogram.caching.MatrixObject in project incubator-systemml by apache.

the class ScalarMatrixBuiltinGPUInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) {
    GPUStatistics.incrementNoOfExecutedGPUInst();
    String opcode = getOpcode();
    CPOperand mat = (input1.getDataType() == DataType.MATRIX) ? input1 : input2;
    CPOperand scalar = (input1.getDataType() == DataType.MATRIX) ? input2 : input1;
    MatrixObject in1 = getMatrixInputForGPUInstruction(ec, mat.getName());
    ScalarObject constant = (ScalarObject) ec.getScalarInput(scalar.getName(), scalar.getValueType(), scalar.isLiteral());
    if (opcode.equals("max")) {
        ec.setMetaData(output.getName(), in1.getNumRows(), in1.getNumColumns());
        double constVal = constant.getDoubleValue();
        if (constVal == 0)
            LibMatrixCuDNN.relu(ec, ec.getGPUContext(0), getExtendedOpcode(), in1, output.getName());
        else
            LibMatrixCUDA.matrixScalarOp(ec, ec.getGPUContext(0), getExtendedOpcode(), in1, output.getName(), false, InstructionUtils.parseScalarBinaryOperator(opcode, false, constVal));
    } else if (opcode.equals("min")) {
        ec.setMetaData(output.getName(), in1.getNumRows(), in1.getNumColumns());
        double constVal = constant.getDoubleValue();
        LibMatrixCUDA.matrixScalarOp(ec, ec.getGPUContext(0), getExtendedOpcode(), in1, output.getName(), false, InstructionUtils.parseScalarBinaryOperator(opcode, false, constVal));
    } else {
        throw new DMLRuntimeException("Unsupported GPU operator:" + opcode);
    }
    ec.releaseMatrixInputForGPUInstruction(mat.getName());
    ec.releaseMatrixOutputForGPUInstruction(output.getName());
}
Also used : ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 52 with MatrixObject

use of org.apache.sysml.runtime.controlprogram.caching.MatrixObject in project incubator-systemml by apache.

the class OptimizerRuleBased method computeTotalSizeResultVariables.

private static double computeTotalSizeResultVariables(ArrayList<ResultVar> retVars, LocalVariableMap vars, int k) {
    double sum = 1;
    for (ResultVar var : retVars) {
        Data dat = vars.get(var._name);
        if (!(dat instanceof MatrixObject))
            continue;
        MatrixObject mo = (MatrixObject) dat;
        if (mo.getNnz() == 0)
            sum += OptimizerUtils.estimateSizeExactSparsity(mo.getNumRows(), mo.getNumColumns(), 1.0);
        else {
            // Every worker will consume memory for (MatrixSize/k + nnz) data.
            // This is applicable only when there is non-zero nnz.
            sum += (k + 1) * (OptimizerUtils.estimateSizeExactSparsity(mo.getNumRows(), mo.getNumColumns(), Math.min((1.0 / k) + mo.getSparsity(), 1.0)));
        }
    }
    return sum;
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) ResultVar(org.apache.sysml.parser.ParForStatementBlock.ResultVar) Data(org.apache.sysml.runtime.instructions.cp.Data)

Example 53 with MatrixObject

use of org.apache.sysml.runtime.controlprogram.caching.MatrixObject in project incubator-systemml by apache.

the class OptimizerRuleBased method hasResultMRLeftIndexing.

protected boolean hasResultMRLeftIndexing(OptNode n, ArrayList<ResultVar> resultVars, LocalVariableMap vars, boolean checkSize) {
    boolean ret = false;
    if (n.isLeaf()) {
        String opName = n.getParam(ParamType.OPSTRING);
        // check opstring and exec type
        if (opName != null && opName.equals(LeftIndexingOp.OPSTRING) && n.getExecType() == getRemoteExecType()) {
            LeftIndexingOp hop = (LeftIndexingOp) OptTreeConverter.getAbstractPlanMapping().getMappedHop(n.getID());
            // check agains set of varname
            String varName = hop.getInput().get(0).getName();
            if (ResultVar.contains(resultVars, varName)) {
                ret = true;
                if (checkSize && vars.keySet().contains(varName)) {
                    // dims of result vars must be known at this point in time
                    MatrixObject mo = (MatrixObject) vars.get(hop.getInput().get(0).getName());
                    long rows = mo.getNumRows();
                    long cols = mo.getNumColumns();
                    ret = !isInMemoryResultMerge(rows, cols, OptimizerUtils.getRemoteMemBudgetMap(false));
                }
            }
        }
    } else {
        for (OptNode c : n.getChilds()) ret |= hasResultMRLeftIndexing(c, resultVars, vars, checkSize);
    }
    return ret;
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) LeftIndexingOp(org.apache.sysml.hops.LeftIndexingOp)

Example 54 with MatrixObject

use of org.apache.sysml.runtime.controlprogram.caching.MatrixObject in project incubator-systemml by apache.

the class OptimizerRuleBased method hasLargeTotalResults.

/**
 * Heuristically compute total result sizes, if larger than local mem budget assumed to be large.
 *
 * @param pn internal representation of a plan alternative for program blocks and instructions
 * @param resultVars list of result variables
 * @param vars local variable map
 * @param checkSize ?
 * @return true if result sizes larger than local memory budget
 */
protected boolean hasLargeTotalResults(OptNode pn, ArrayList<ResultVar> resultVars, LocalVariableMap vars, boolean checkSize) {
    double totalSize = 0;
    // get num tasks according to task partitioning
    PTaskPartitioner tp = PTaskPartitioner.valueOf(pn.getParam(ParamType.TASK_PARTITIONER));
    int k = pn.getK();
    long W = estimateNumTasks(tp, _N, k);
    for (ResultVar var : resultVars) {
        // Potential unknowns: for local result var of child parfor (but we're only interested in top level)
        // Potential scalars: for disabled dependency analysis and unbounded scoping
        Data dat = vars.get(var._name);
        if (dat != null && dat instanceof MatrixObject) {
            MatrixObject mo = (MatrixObject) dat;
            long rows = mo.getNumRows();
            long cols = mo.getNumColumns();
            long nnz = mo.getNnz();
            if (// w/ compare
            nnz > 0) {
                totalSize += W * OptimizerUtils.estimateSizeExactSparsity(rows, cols, 1.0);
            } else // in total at most as dimensions (due to disjoint results)
            {
                totalSize += OptimizerUtils.estimateSizeExactSparsity(rows, cols, 1.0);
            }
        }
    }
    // heuristic:  large if >= local mem budget
    return (totalSize >= _lm);
}
Also used : PTaskPartitioner(org.apache.sysml.runtime.controlprogram.ParForProgramBlock.PTaskPartitioner) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) ResultVar(org.apache.sysml.parser.ParForStatementBlock.ResultVar) Data(org.apache.sysml.runtime.instructions.cp.Data)

Example 55 with MatrixObject

use of org.apache.sysml.runtime.controlprogram.caching.MatrixObject in project incubator-systemml by apache.

the class OptimizerRuleBased method getNewRIXMemoryEstimate.

/**
 * TODO consolidate mem estimation with Indexing Hop
 *
 * NOTE: Using the dimensions without sparsity is a conservative worst-case consideration.
 *
 * @param n internal representation of a plan alternative for program blocks and instructions
 * @param varName variable name
 * @param dpf data partition format
 * @param vars local variable map
 * @return memory estimate
 */
protected double getNewRIXMemoryEstimate(OptNode n, String varName, PartitionFormat dpf, LocalVariableMap vars) {
    double mem = -1;
    // not all intermediates need to be known on optimize
    Data dat = vars.get(varName);
    if (dat != null) {
        MatrixObject mo = (MatrixObject) dat;
        // those are worst-case (dense) estimates
        switch(dpf._dpf) {
            case COLUMN_WISE:
                mem = OptimizerUtils.estimateSize(mo.getNumRows(), 1);
                break;
            case ROW_WISE:
                mem = OptimizerUtils.estimateSize(1, mo.getNumColumns());
                break;
            case COLUMN_BLOCK_WISE_N:
                mem = OptimizerUtils.estimateSize(mo.getNumRows(), dpf._N);
                break;
            case ROW_BLOCK_WISE_N:
                mem = OptimizerUtils.estimateSize(dpf._N, mo.getNumColumns());
                break;
            default:
        }
    }
    return mem;
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) Data(org.apache.sysml.runtime.instructions.cp.Data)

Aggregations

MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)201 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)74 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)45 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)39 Data (org.apache.sysml.runtime.instructions.cp.Data)37 MetaDataFormat (org.apache.sysml.runtime.matrix.MetaDataFormat)26 Pointer (jcuda.Pointer)20 CSRPointer (org.apache.sysml.runtime.instructions.gpu.context.CSRPointer)20 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)16 ScalarObject (org.apache.sysml.runtime.instructions.cp.ScalarObject)14 OutputInfo (org.apache.sysml.runtime.matrix.data.OutputInfo)13 CacheableData (org.apache.sysml.runtime.controlprogram.caching.CacheableData)12 RDDObject (org.apache.sysml.runtime.instructions.spark.data.RDDObject)12 Hop (org.apache.sysml.hops.Hop)11 MatrixFormatMetaData (org.apache.sysml.runtime.matrix.MatrixFormatMetaData)11 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)10 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)10 Path (org.apache.hadoop.fs.Path)9 LongWritable (org.apache.hadoop.io.LongWritable)9