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);
}
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;
}
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;
}
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);
}
}
}
}
}
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;
}
Aggregations