use of org.apache.sysml.runtime.DMLRuntimeException in project incubator-systemml by apache.
the class ConvolutionOp method inferOutputCharacteristics.
@Override
protected long[] inferOutputCharacteristics(MemoTable memo) {
// [numRows, numCols, NNZ]
long[] ret = new long[3];
if (op == ConvOp.BIAS_ADD || op == ConvOp.BIAS_MULTIPLY) {
MatrixCharacteristics[] mc = memo.getAllInputStats(getInput());
ret[0] = mc[0].rowsKnown() ? mc[0].getRows() : -1;
ret[1] = mc[0].colsKnown() ? mc[0].getCols() : -1;
ret[2] = -1;
return (ret[0] > 0 && ret[1] > 0) ? ret : null;
}
ConvolutionParameters params;
try {
params = parseInput();
} catch (DMLRuntimeException e) {
throw new RuntimeException(e);
}
switch(op) {
case MAX_POOLING:
{
// input
long N = getInput().get(0)._dim1;
ret[0] = N;
ret[1] = getExtractedVal(params.C, params.P, params.Q);
ret[2] = -1;
break;
}
case DIRECT_CONV2D:
{
// input, filter
long N = getInput().get(0)._dim1;
ret[0] = N;
ret[1] = getExtractedVal(params.K, params.P, params.Q);
ret[2] = -1;
break;
}
case DIRECT_CONV2D_BACKWARD_FILTER:
{
// input, dout
ret[0] = params.K;
ret[1] = getExtractedVal(params.C, params.R, params.S);
ret[2] = -1;
break;
}
case MAX_POOLING_BACKWARD:
{
// input, dout
ret[0] = getInput().get(0)._dim1;
ret[1] = getInput().get(0)._dim2;
ret[2] = -1;
break;
}
case DIRECT_CONV2D_BACKWARD_DATA:
{
// filter, dout
long N = getInput().get(1)._dim1;
ret[0] = N;
ret[1] = getExtractedVal(params.C, params.H, params.W);
ret[2] = -1;
break;
}
default:
throw new RuntimeException("Unsupported op:" + op.name());
}
if (LOG.isDebugEnabled() && (ret[0] <= 0 || ret[1] <= 0)) {
LOG.debug("Unknown dimensions for ConvolutionOp in inferOutputCharacteristics:" + op.name() + " " + ret[0] + " " + ret[1] + " img_dim=[" + params.N + " " + params.C + " " + params.H + " " + params.W + "]" + " filter_dim=[" + params.K + " " + params.C + " " + params.H + " " + params.W + "]" + " output_feature_map=[" + params.P + " " + params.Q + "] stride=[" + params.stride_h + " " + params.stride_w + "]" + " pad=[" + params.pad_h + " " + params.pad_w + "]");
}
//safe return (create entry only if at least dims known)
return (ret[0] > 0 && ret[1] > 0) ? ret : null;
}
use of org.apache.sysml.runtime.DMLRuntimeException in project incubator-systemml by apache.
the class GPUObject method copyFromDeviceToHost.
protected void copyFromDeviceToHost() throws DMLRuntimeException {
LOG.trace("GPU : copyFromDeviceToHost, on " + this + ", GPUContext=" + getGPUContext());
if (getJcudaDenseMatrixPtr() != null && getJcudaSparseMatrixPtr() != null) {
throw new DMLRuntimeException("Invalid state : JCuda dense/sparse pointer are both allocated");
}
if (getJcudaDenseMatrixPtr() != null) {
long start = 0;
if (DMLScript.STATISTICS)
start = System.nanoTime();
MatrixBlock tmp = new MatrixBlock(toIntExact(mat.getNumRows()), toIntExact(mat.getNumColumns()), false);
tmp.allocateDenseBlock();
double[] data = tmp.getDenseBlock();
cudaMemcpy(Pointer.to(data), getJcudaDenseMatrixPtr(), getDoubleSizeOf(data.length), cudaMemcpyDeviceToHost);
tmp.recomputeNonZeros();
mat.acquireModify(tmp);
mat.release();
if (DMLScript.STATISTICS)
GPUStatistics.cudaFromDevTime.addAndGet(System.nanoTime() - start);
if (DMLScript.STATISTICS)
GPUStatistics.cudaFromDevCount.addAndGet(1);
} else if (getJcudaSparseMatrixPtr() != null) {
if (!LibMatrixCUDA.isInSparseFormat(getGPUContext(), mat))
throw new DMLRuntimeException("Block not in sparse format on host yet the device sparse matrix pointer is not null");
if (this.isSparseAndEmpty()) {
// Empty Block
MatrixBlock tmp = new MatrixBlock();
mat.acquireModify(tmp);
mat.release();
} else {
long start = 0;
if (DMLScript.STATISTICS)
start = System.nanoTime();
int rows = toIntExact(mat.getNumRows());
int cols = toIntExact(mat.getNumColumns());
int nnz = toIntExact(getJcudaSparseMatrixPtr().nnz);
int[] rowPtr = new int[rows + 1];
int[] colInd = new int[nnz];
double[] values = new double[nnz];
CSRPointer.copyToHost(getJcudaSparseMatrixPtr(), rows, nnz, rowPtr, colInd, values);
SparseBlockCSR sparseBlock = new SparseBlockCSR(rowPtr, colInd, values, nnz);
MatrixBlock tmp = new MatrixBlock(rows, cols, nnz, sparseBlock);
mat.acquireModify(tmp);
mat.release();
if (DMLScript.STATISTICS)
GPUStatistics.cudaFromDevTime.addAndGet(System.nanoTime() - start);
if (DMLScript.STATISTICS)
GPUStatistics.cudaFromDevCount.addAndGet(1);
}
} else {
throw new DMLRuntimeException("Cannot copy from device to host as JCuda dense/sparse pointer is not allocated");
}
dirty = false;
}
use of org.apache.sysml.runtime.DMLRuntimeException in project incubator-systemml by apache.
the class BinaryBlockFrame method getFrameBlock.
/**
* Obtain a SystemML binary-block frame as a {@code FrameBlock}
*
* @return the SystemML binary-block frame as a {@code FrameBlock}
*/
public FrameBlock getFrameBlock() {
try {
MatrixCharacteristics mc = getMatrixCharacteristics();
FrameSchema frameSchema = frameMetadata.getFrameSchema();
return SparkExecutionContext.toFrameBlock(binaryBlocks, frameSchema.getSchema().toArray(new ValueType[0]), (int) mc.getRows(), (int) mc.getCols());
} catch (DMLRuntimeException e) {
throw new MLContextException("Exception while getting FrameBlock from binary-block frame", e);
}
}
use of org.apache.sysml.runtime.DMLRuntimeException in project incubator-systemml by apache.
the class MLContextConversionUtil method javaRDDStringCSVToFrameObject.
/**
* Convert a {@code JavaRDD<String>} in CSV format to a {@code FrameObject}
*
* @param variableName
* name of the variable associated with the frame
* @param javaRDD
* the Java RDD of strings
* @param frameMetadata
* frame metadata
* @return the {@code JavaRDD<String>} converted to a {@code FrameObject}
*/
public static FrameObject javaRDDStringCSVToFrameObject(String variableName, JavaRDD<String> javaRDD, FrameMetadata frameMetadata) {
JavaPairRDD<LongWritable, Text> javaPairRDD = javaRDD.mapToPair(new ConvertStringToLongTextPair());
MatrixCharacteristics mc = (frameMetadata != null) ? frameMetadata.asMatrixCharacteristics() : new MatrixCharacteristics();
JavaPairRDD<LongWritable, Text> javaPairRDDText = javaPairRDD.mapToPair(new CopyTextInputFunction());
FrameObject frameObject = new FrameObject(OptimizerUtils.getUniqueTempFileName(), new MatrixFormatMetaData(mc, OutputInfo.BinaryBlockOutputInfo, InputInfo.BinaryBlockInputInfo), frameMetadata.getFrameSchema().getSchema().toArray(new ValueType[0]));
JavaPairRDD<Long, FrameBlock> rdd;
try {
rdd = FrameRDDConverterUtils.csvToBinaryBlock(jsc(), javaPairRDDText, mc, frameObject.getSchema(), false, ",", false, -1);
} catch (DMLRuntimeException e) {
e.printStackTrace();
return null;
}
frameObject.setRDDHandle(new RDDObject(rdd, variableName));
return frameObject;
}
use of org.apache.sysml.runtime.DMLRuntimeException in project incubator-systemml by apache.
the class MLContextConversionUtil method frameObjectToBinaryBlockFrame.
/**
* Convert a {@code FrameObject} to a {@code BinaryBlockFrame}.
*
* @param frameObject
* the {@code FrameObject}
* @param sparkExecutionContext
* the Spark execution context
* @return the {@code FrameObject} converted to a {@code BinaryBlockFrame}
*/
public static BinaryBlockFrame frameObjectToBinaryBlockFrame(FrameObject frameObject, SparkExecutionContext sparkExecutionContext) {
try {
@SuppressWarnings("unchecked") JavaPairRDD<Long, FrameBlock> binaryBlock = (JavaPairRDD<Long, FrameBlock>) sparkExecutionContext.getRDDHandleForFrameObject(frameObject, InputInfo.BinaryBlockInputInfo);
MatrixCharacteristics matrixCharacteristics = frameObject.getMatrixCharacteristics();
FrameSchema fs = new FrameSchema(Arrays.asList(frameObject.getSchema()));
FrameMetadata fm = new FrameMetadata(fs, matrixCharacteristics);
return new BinaryBlockFrame(binaryBlock, fm);
} catch (DMLRuntimeException e) {
throw new MLContextException("DMLRuntimeException while converting frame object to BinaryBlockFrame", e);
}
}
Aggregations