Skip to content

Commit cc56144

Browse files
committed
[MINOR] Add singlethread fused scalar and decompress
1 parent 75874c5 commit cc56144

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/main/java/org/apache/sysds/runtime/compress/lib/CLALibScalar.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,35 @@ public static MatrixBlock scalarOperations(ScalarOperator sop, CompressedMatrixB
108108
}
109109

110110
private static MatrixBlock fusedScalarAndDecompress(CompressedMatrixBlock in, ScalarOperator sop) {
111+
if(sop.getNumThreads() <= 1)
112+
return singleThreadFusedScalarAndDecompress(in, sop);
113+
return parallelFusedScalarAndDecompress(in, sop) ;
114+
}
115+
116+
private static MatrixBlock singleThreadFusedScalarAndDecompress(CompressedMatrixBlock in, ScalarOperator sop){
117+
final int nRow = in.getNumRows();
118+
final int nCol = in.getNumColumns();
119+
final MatrixBlock out = new MatrixBlock(nRow, nCol, false);
120+
out.allocateDenseBlock();
121+
final DenseBlock db = out.getDenseBlock();
122+
final List<AColGroup> groups = in.getColGroups();
123+
long nnz = fusedDecompressAndScalar(groups, nCol, 0, nRow, db, sop);
124+
out.setNonZeros(nnz);
125+
out.examSparsity(true);
126+
return out;
127+
}
128+
129+
private static MatrixBlock parallelFusedScalarAndDecompress(CompressedMatrixBlock in, ScalarOperator sop) {
111130
int k = sop.getNumThreads();
112131
ExecutorService pool = CommonThreadPool.get(k);
113132
try {
114-
final int nRow = in.getNumRows();
133+
final int nRow = in.getNumRows();
115134
final int nCol = in.getNumColumns();
116135
final MatrixBlock out = new MatrixBlock(nRow, nCol, false);
117136
final List<AColGroup> groups = in.getColGroups();
118137
out.allocateDenseBlock();
119138
final DenseBlock db = out.getDenseBlock();
120-
final int blkz = Math.max((int)(Math.ceil((double)nRow / k)), 256);
139+
final int blkz = Math.max((int) (Math.ceil((double) nRow / k)), 256);
121140
final List<Future<Long>> tasks = new ArrayList<>();
122141
for(int i = 0; i < nRow; i += blkz) {
123142
final int start = i;
@@ -138,9 +157,6 @@ private static MatrixBlock fusedScalarAndDecompress(CompressedMatrixBlock in, Sc
138157
finally {
139158
pool.shutdown();
140159
}
141-
142-
// MatrixBlock m1d = m1.decompress(sop.getNumThreads());
143-
// return m1d.scalarOperations(sop, result);
144160
}
145161

146162
private static long fusedDecompressAndScalar(final List<AColGroup> groups, int nCol, int start, int end,

0 commit comments

Comments
 (0)