forked from apache/systemds
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYSTEMML-2043] New abstraction for large dense row blocks
This patch introduces a new abstraction for dense row blocks, which is the basis for supporting both small and large (>16GB) dense blocks, while enabling memory-efficient linearized representations and efficient operations for entire dense blocks.
- Loading branch information
Showing
1 changed file
with
155 additions
and
0 deletions.
There are no files selected for viewing
155 changes: 155 additions & 0 deletions
155
src/main/java/org/apache/sysml/runtime/matrix/data/DenseBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
|
||
package org.apache.sysml.runtime.matrix.data; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* This DenseBlock is an abstraction for different dense, row-major | ||
* matrix formats. For efficient dense operations, this API does not | ||
* expose a row but a row-block abstraction, where a block can contain | ||
* one or many contiguous rows. | ||
* | ||
*/ | ||
public abstract class DenseBlock implements Serializable | ||
{ | ||
private static final long serialVersionUID = 7517220490270237832L; | ||
|
||
public enum Type { | ||
DRB, //dense row block | ||
LDBR, //large dense row block | ||
} | ||
|
||
/** | ||
* Resets the dense block by deleting non-zero values. After this | ||
* call all countNonZeros() calls are guaranteed to return 0. | ||
*/ | ||
public abstract void reset(); | ||
|
||
/** | ||
* Resets the dense block by deleting non-zero values. After this | ||
* call all countNonZeros() calls are guaranteed to return 0. If | ||
* the new dimensions exceed the current capacity, the underlying | ||
* storage is extended accordingly. | ||
* | ||
* @param rlen number of rows | ||
* @param clen number of columns | ||
*/ | ||
public abstract void reset(int rlen, int clen); | ||
|
||
/** | ||
* Get the number of rows. | ||
* | ||
* @return number of rows | ||
*/ | ||
public abstract int numRows(); | ||
|
||
/** | ||
* Get the number of allocated blocks. | ||
* | ||
* @return number of blocks | ||
*/ | ||
public abstract int numBlocks(); | ||
|
||
/** | ||
* Get the length of the dense block as the product | ||
* of row and column dimensions. | ||
* | ||
* @return length | ||
*/ | ||
public abstract long size(); | ||
|
||
/** | ||
* Get the total length of allocated blocks. | ||
* | ||
* @return capacity | ||
*/ | ||
public abstract long capacity(); | ||
|
||
/** | ||
* Compute the number of non-zero values, which potentially | ||
* makes a full pass over the underlying blocks. | ||
* | ||
* @return number of non-zeros | ||
*/ | ||
public abstract long countNonZeros(); | ||
|
||
/** | ||
* Get the allocated blocks. | ||
* | ||
* @return blocks | ||
*/ | ||
public abstract double[][] values(); | ||
|
||
|
||
/** | ||
* Get an allocated block. | ||
* | ||
* @param bix block index | ||
* @return block | ||
*/ | ||
public abstract double[] values(int bix); | ||
|
||
/** | ||
* Get the block index for a given row. | ||
* | ||
* @param r row index | ||
* @return block index | ||
*/ | ||
public abstract int index(int r); | ||
|
||
/** | ||
* Get the position for a given row within | ||
* its associated block. | ||
* | ||
* @param r row index | ||
* @return block position | ||
*/ | ||
public abstract int pos(int r); | ||
|
||
/** | ||
* Get the position for a given row and column | ||
* within the associated block. | ||
* | ||
* @param r row index | ||
* @param c column index | ||
* @return block position | ||
*/ | ||
public abstract int pos(int r, int c); | ||
|
||
/** | ||
* Set the given value for a given row and column. | ||
* | ||
* @param r row index | ||
* @param c column index | ||
* @param v value | ||
*/ | ||
public abstract void set(int r, int c, double v); | ||
|
||
/** | ||
* Get the value for a given row and column. | ||
* | ||
* @param r row index | ||
* @param c column index | ||
* @return value | ||
*/ | ||
public abstract double get(int r, int c); | ||
} |