Search in sources :

Example 1 with MatrixObject

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

the class ExecutionContext method getDenseMatrixOutputForGPUInstruction.

/**
	 * Allocates a dense matrix on the GPU (for output)
	 * @param varName	name of the output matrix (known by this {@link ExecutionContext})
	 * @return a pair containing the wrapping {@link MatrixObject} and a boolean indicating whether a cuda memory allocation took place (as opposed to the space already being allocated)
	 * @throws DMLRuntimeException
	 */
public Pair<MatrixObject, Boolean> getDenseMatrixOutputForGPUInstruction(String varName) throws DMLRuntimeException {
    MatrixObject mo = allocateGPUMatrixObject(varName);
    boolean allocated = mo.getGPUObject(getGPUContext()).acquireDeviceModifyDense();
    mo.getMatrixCharacteristics().setNonZeros(-1);
    return new Pair<MatrixObject, Boolean>(mo, allocated);
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) Pair(org.apache.sysml.runtime.matrix.data.Pair)

Example 2 with MatrixObject

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

the class ExecutionContext method allocateGPUMatrixObject.

/**
	 * Allocates the {@link GPUObject} for a given LOPS Variable (eg. _mVar3)
	 * @param varName variable name
	 * @return matrix object
	 * @throws DMLRuntimeException if DMLRuntimeException occurs
	 */
public MatrixObject allocateGPUMatrixObject(String varName) throws DMLRuntimeException {
    MatrixObject mo = getMatrixObject(varName);
    if (mo.getGPUObject(getGPUContext()) == null) {
        GPUObject newGObj = getGPUContext().createGPUObject(mo);
        // The lock is added here for an output block
        // so that any block currently in use is not deallocated by eviction on the GPU
        newGObj.addLock();
        mo.setGPUObject(getGPUContext(), newGObj);
    }
    return mo;
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) GPUObject(org.apache.sysml.runtime.instructions.gpu.context.GPUObject)

Example 3 with MatrixObject

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

the class ExecutionContext method pinVariables.

/**
	 * Pin a given list of variables i.e., set the "clean up" state in 
	 * corresponding matrix objects, so that the cached data inside these
	 * objects is not cleared and the corresponding HDFS files are not 
	 * deleted (through rmvar instructions). 
	 * 
	 * This is necessary for: function input variables, parfor result variables, 
	 * parfor shared inputs that are passed to functions.
	 * 
	 * The function returns the OLD "clean up" state of matrix objects.
	 * 
	 * @param varList variable list
	 * @return map of old cleanup state of matrix objects
	 */
public HashMap<String, Boolean> pinVariables(ArrayList<String> varList) {
    //2-pass approach since multiple vars might refer to same matrix object
    HashMap<String, Boolean> varsState = new HashMap<String, Boolean>();
    //step 1) get current information
    for (String var : varList) {
        Data dat = _variables.get(var);
        if (dat instanceof MatrixObject) {
            MatrixObject mo = (MatrixObject) dat;
            varsState.put(var, mo.isCleanupEnabled());
        //System.out.println("pre-pin "+var+" ("+mo.isCleanupEnabled()+")");
        }
    }
    //step 2) pin variables
    for (String var : varList) {
        Data dat = _variables.get(var);
        if (dat instanceof MatrixObject) {
            MatrixObject mo = (MatrixObject) dat;
            mo.enableCleanup(false);
        //System.out.println("pin "+var);
        }
    }
    return varsState;
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) HashMap(java.util.HashMap) CacheableData(org.apache.sysml.runtime.controlprogram.caching.CacheableData) MatrixDimensionsMetaData(org.apache.sysml.runtime.matrix.MatrixDimensionsMetaData) Data(org.apache.sysml.runtime.instructions.cp.Data) MetaData(org.apache.sysml.runtime.matrix.MetaData) MatrixFormatMetaData(org.apache.sysml.runtime.matrix.MatrixFormatMetaData)

Example 4 with MatrixObject

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

the class InterProceduralAnalysis method populateLocalVariableMapForFunctionCall.

private void populateLocalVariableMapForFunctionCall(FunctionStatement fstmt, FunctionOp fop, LocalVariableMap callvars, LocalVariableMap vars, Set<Long> inputSafeNNZ, Integer numCalls) throws HopsException {
    ArrayList<DataIdentifier> inputVars = fstmt.getInputParams();
    ArrayList<Hop> inputOps = fop.getInput();
    for (int i = 0; i < inputVars.size(); i++) {
        //create mapping between input hops and vars
        DataIdentifier dat = inputVars.get(i);
        Hop input = inputOps.get(i);
        if (input.getDataType() == DataType.MATRIX) {
            //propagate matrix characteristics
            MatrixObject mo = new MatrixObject(ValueType.DOUBLE, null);
            MatrixCharacteristics mc = new MatrixCharacteristics(input.getDim1(), input.getDim2(), ConfigurationManager.getBlocksize(), ConfigurationManager.getBlocksize(), inputSafeNNZ.contains(input.getHopID()) ? input.getNnz() : -1);
            MatrixFormatMetaData meta = new MatrixFormatMetaData(mc, null, null);
            mo.setMetaData(meta);
            vars.put(dat.getName(), mo);
        } else if (input.getDataType() == DataType.SCALAR) {
            //(for multiple calls, literal equivalence already checked)
            if (input instanceof LiteralOp) {
                vars.put(dat.getName(), ScalarObjectFactory.createScalarObject(input.getValueType(), (LiteralOp) input));
            } else //and input scalar is existing variable in symbol table
            if (PROPAGATE_SCALAR_VARS_INTO_FUN && numCalls != null && numCalls == 1 && input instanceof DataOp) {
                Data scalar = callvars.get(input.getName());
                if (scalar != null && scalar instanceof ScalarObject) {
                    vars.put(dat.getName(), scalar);
                }
            }
        }
    }
}
Also used : ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) DataIdentifier(org.apache.sysml.parser.DataIdentifier) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) Hop(org.apache.sysml.hops.Hop) Data(org.apache.sysml.runtime.instructions.cp.Data) MatrixFormatMetaData(org.apache.sysml.runtime.matrix.MatrixFormatMetaData) LiteralOp(org.apache.sysml.hops.LiteralOp) DataOp(org.apache.sysml.hops.DataOp) MatrixFormatMetaData(org.apache.sysml.runtime.matrix.MatrixFormatMetaData) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics)

Example 5 with MatrixObject

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

the class Recompiler method checkCPTransform.

public static boolean checkCPTransform(MRJobInstruction inst, MatrixObject[] inputs) throws DMLRuntimeException, IOException {
    boolean ret = true;
    // there can only be one input in TRANSFORM job
    MatrixObject input = inputs[0];
    Path path = new Path(input.getFileName());
    long sizeOnHDFS = MapReduceTool.getFilesizeOnHDFS(path);
    if (sizeOnHDFS > CP_TRANSFORM_UNKNOWN_THRESHOLD_SIZE || sizeOnHDFS * 4 > OptimizerUtils.getLocalMemBudget())
        ret = false;
    LOG.info("checkCPTransform(): size = " + sizeOnHDFS + ", recompile to CP = " + ret);
    return ret;
}
Also used : Path(org.apache.hadoop.fs.Path) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject)

Aggregations

MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)370 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)141 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)81 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)75 Data (org.apache.sysml.runtime.instructions.cp.Data)64 MetaDataFormat (org.apache.sysml.runtime.matrix.MetaDataFormat)52 Pointer (jcuda.Pointer)37 CSRPointer (org.apache.sysml.runtime.instructions.gpu.context.CSRPointer)37 IOException (java.io.IOException)33 ArrayList (java.util.ArrayList)28 ScalarObject (org.apache.sysml.runtime.instructions.cp.ScalarObject)25 OutputInfo (org.apache.sysml.runtime.matrix.data.OutputInfo)25 CacheableData (org.apache.sysml.runtime.controlprogram.caching.CacheableData)22 Hop (org.apache.sysml.hops.Hop)20 RDDObject (org.apache.sysml.runtime.instructions.spark.data.RDDObject)20 Test (org.junit.Test)20 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)19 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)18 DataOp (org.apache.sysml.hops.DataOp)17 LiteralOp (org.apache.sysml.hops.LiteralOp)17