use of org.apache.sysml.runtime.controlprogram.caching.MatrixObject in project incubator-systemml by apache.
the class ProgramBlock method checkSparsity.
private static void checkSparsity(Instruction lastInst, LocalVariableMap vars) {
for (String varname : vars.keySet()) {
Data dat = vars.get(varname);
if (dat instanceof MatrixObject) {
MatrixObject mo = (MatrixObject) dat;
if (mo.isDirty() && !mo.isPartitioned()) {
MatrixBlock mb = mo.acquireRead();
boolean sparse1 = mb.isInSparseFormat();
long nnz1 = mb.getNonZeros();
synchronized (mb) {
// potential state change
mb.recomputeNonZeros();
mb.examSparsity();
}
if (mb.isInSparseFormat() && mb.isAllocated()) {
mb.getSparseBlock().checkValidity(mb.getNumRows(), mb.getNumColumns(), mb.getNonZeros(), true);
}
boolean sparse2 = mb.isInSparseFormat();
long nnz2 = mb.getNonZeros();
mo.release();
if (nnz1 != nnz2)
throw new DMLRuntimeException("Matrix nnz meta data was incorrect: (" + varname + ", actual=" + nnz1 + ", expected=" + nnz2 + ", inst=" + lastInst + ")");
if (sparse1 != sparse2 && mb.isAllocated())
throw new DMLRuntimeException("Matrix was in wrong data representation: (" + varname + ", actual=" + sparse1 + ", expected=" + sparse2 + ", nrow=" + mb.getNumRows() + ", ncol=" + mb.getNumColumns() + ", nnz=" + nnz1 + ", inst=" + lastInst + ")");
}
}
}
}
use of org.apache.sysml.runtime.controlprogram.caching.MatrixObject in project incubator-systemml by apache.
the class ExecutionContext method setMatrixOutput.
public void setMatrixOutput(String varName, MatrixBlock outputData, UpdateType flag, String opcode) {
if (flag.isInPlace()) {
// modify metadata to carry update status
MatrixObject mo = getMatrixObject(varName);
mo.setUpdateType(flag);
}
// default case
setMatrixOutput(varName, outputData, opcode);
}
use of org.apache.sysml.runtime.controlprogram.caching.MatrixObject in project incubator-systemml by apache.
the class ExecutionContext method releaseMatrixOutputForGPUInstruction.
public void releaseMatrixOutputForGPUInstruction(String varName) {
MatrixObject mo = getMatrixObject(varName);
if (mo.getGPUObject(getGPUContext(0)) == null || !mo.getGPUObject(getGPUContext(0)).isAllocated()) {
throw new DMLRuntimeException("No output is allocated on GPU");
}
mo.getGPUObject(getGPUContext(0)).releaseOutput();
}
use of org.apache.sysml.runtime.controlprogram.caching.MatrixObject in project incubator-systemml by apache.
the class ExecutionContext method getSparseMatrixOutputForGPUInstruction.
/**
* Allocates a sparse matrix in CSR format on the GPU.
* Assumes that mat.getNumRows() returns a valid number
*
* @param varName variable name
* @param numRows number of rows of matrix object
* @param numCols number of columns of matrix object
* @param nnz number of non zeroes
* @return matrix object
*/
public Pair<MatrixObject, Boolean> getSparseMatrixOutputForGPUInstruction(String varName, long numRows, long numCols, long nnz) {
MatrixObject mo = allocateGPUMatrixObject(varName, numRows, numCols);
mo.getMatrixCharacteristics().setNonZeros(nnz);
boolean allocated = mo.getGPUObject(getGPUContext(0)).acquireDeviceModifySparse();
return new Pair<>(mo, allocated);
}
use of org.apache.sysml.runtime.controlprogram.caching.MatrixObject in project incubator-systemml by apache.
the class ExecutionContext method setMetaData.
public void setMetaData(String varName, long nrows, long ncols) {
MatrixObject mo = getMatrixObject(varName);
if (mo.getNumRows() == nrows && mo.getNumColumns() == ncols)
return;
MetaData oldMetaData = mo.getMetaData();
if (oldMetaData == null || !(oldMetaData instanceof MetaDataFormat))
throw new DMLRuntimeException("Metadata not available");
MatrixCharacteristics mc = new MatrixCharacteristics(nrows, ncols, (int) mo.getNumRowsPerBlock(), (int) mo.getNumColumnsPerBlock());
mo.setMetaData(new MetaDataFormat(mc, ((MetaDataFormat) oldMetaData).getOutputInfo(), ((MetaDataFormat) oldMetaData).getInputInfo()));
}
Aggregations