Search in sources :

Example 1 with ServerIntIntRow

use of com.tencent.angel.ps.storage.vector.ServerIntIntRow in project angel by Tencent.

the class UpdatePartFunc method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    CSRPartUpdateParam param = (CSRPartUpdateParam) partParam;
    PartitionKey pkey = partParam.getPartKey();
    pkey = psContext.getMatrixMetaManager().getMatrixMeta(pkey.getMatrixId()).getPartitionMeta(pkey.getPartitionId()).getPartitionKey();
    try {
        while (param.buf.isReadable()) {
            int row = param.buf.readInt();
            int len = param.buf.readInt();
            ServerRow serverRow = psContext.getMatrixStorageManager().getRow(pkey, row);
            try {
                serverRow.startWrite();
                if (serverRow.isDense())
                    updateDenseIntRow((ServerIntIntRow) serverRow, param.buf, len);
                if (serverRow.isSparse())
                    updateSparseIntRow((ServerIntIntRow) serverRow, param.buf, len);
            } finally {
                serverRow.endWrite();
            }
        }
    } finally {
        param.buf.release();
    }
}
Also used : PartitionKey(com.tencent.angel.PartitionKey) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) ServerIntIntRow(com.tencent.angel.ps.storage.vector.ServerIntIntRow)

Example 2 with ServerIntIntRow

use of com.tencent.angel.ps.storage.vector.ServerIntIntRow in project angel by Tencent.

the class GetColumnFunc method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    if (partParam instanceof PartitionGetRowsParam) {
        PartitionGetRowsParam param = (PartitionGetRowsParam) partParam;
        PartitionKey pkey = param.getPartKey();
        pkey = psContext.getMatrixMetaManager().getMatrixMeta(pkey.getMatrixId()).getPartitionMeta(pkey.getPartitionId()).getPartitionKey();
        List<Integer> reqCols = param.getRowIndexes();
        int start = reqCols.get(0);
        int end = reqCols.get(1);
        MatrixStorageManager manager = psContext.getMatrixStorageManager();
        Map<Integer, Int2IntOpenHashMap> cks = new HashMap();
        for (int col = start; col < end; col++) cks.put(col, new Int2IntOpenHashMap());
        int rowOffset = pkey.getStartRow();
        int rowLength = pkey.getEndRow();
        for (int r = rowOffset; r < rowLength; r++) {
            ServerRow row = manager.getRow(pkey, r);
            if (row instanceof ServerIntIntRow) {
                for (int col = start; col < end; col++) {
                    Int2IntOpenHashMap map = cks.get(col);
                    int k = ((ServerIntIntRow) row).get(col);
                    if (k > 0)
                        map.put(row.getRowId(), k);
                }
            }
        }
        return new PartColumnResult(cks);
    } else {
        return null;
    }
}
Also used : Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap) HashMap(java.util.HashMap) PartitionGetRowsParam(com.tencent.angel.ml.matrix.psf.get.getrows.PartitionGetRowsParam) MatrixStorageManager(com.tencent.angel.ps.storage.MatrixStorageManager) PartitionKey(com.tencent.angel.PartitionKey) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) ServerIntIntRow(com.tencent.angel.ps.storage.vector.ServerIntIntRow) Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)

Example 3 with ServerIntIntRow

use of com.tencent.angel.ps.storage.vector.ServerIntIntRow in project angel by Tencent.

the class PartCSRResult method bufferLen.

@Override
public int bufferLen() {
    int len = 4;
    for (ServerRow row : splits) {
        if (row.isDense()) {
            int[] values = ServerRowUtils.getVector((ServerIntIntRow) row).getStorage().getValues();
            int size = (int) (row.getEndCol() - row.getStartCol());
            int cnt = 0;
            for (int i = 0; i < size; i++) if (values[i] > 0)
                cnt++;
            len += 1 + 4;
            if (cnt > size * 0.5) {
                // dense
                len += 4 * size;
            } else {
                // sparse
                len += 8 * cnt;
            }
        } else if (row.isSparse()) {
            int[] values = ServerRowUtils.getVector((ServerIntIntRow) row).getStorage().getValues();
            int size = values.length;
            int cnt = 0;
            for (int i = 0; i < size; i++) if (values[i] > 0)
                cnt++;
            len += 1 + 4 + 8 * cnt;
        } else
            return len;
    }
    return len;
}
Also used : ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) ServerIntIntRow(com.tencent.angel.ps.storage.vector.ServerIntIntRow)

Example 4 with ServerIntIntRow

use of com.tencent.angel.ps.storage.vector.ServerIntIntRow in project angel by Tencent.

the class MergeUtils method combineServerIntIntRowSplits.

private static Vector combineServerIntIntRowSplits(List<ServerRow> rowSplits, MatrixMeta matrixMeta, int rowIndex) {
    int colNum = (int) matrixMeta.getColNum();
    int elemNum = 0;
    int size = rowSplits.size();
    for (int i = 0; i < size; i++) {
        elemNum += rowSplits.get(i).size();
    }
    IntIntVector row;
    if (matrixMeta.isHash()) {
        row = VFactory.sparseIntVector(colNum, elemNum);
    } else {
        if (elemNum >= (int) (storageConvFactor * colNum)) {
            row = VFactory.denseIntVector(colNum);
        } else {
            row = VFactory.sparseIntVector(colNum, elemNum);
        }
    }
    row.setMatrixId(matrixMeta.getId());
    row.setRowId(rowIndex);
    Collections.sort(rowSplits, serverRowComp);
    for (int i = 0; i < size; i++) {
        if (rowSplits.get(i) == null) {
            continue;
        }
        ((ServerIntIntRow) rowSplits.get(i)).mergeTo(row);
    }
    return row;
}
Also used : IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector) ServerIntIntRow(com.tencent.angel.ps.storage.vector.ServerIntIntRow)

Example 5 with ServerIntIntRow

use of com.tencent.angel.ps.storage.vector.ServerIntIntRow in project angel by Tencent.

the class RowSplitCombineUtils method combineServerIntIntRowSplits.

private static Vector combineServerIntIntRowSplits(List<ServerRow> rowSplits, MatrixMeta matrixMeta, int rowIndex) {
    int colNum = (int) matrixMeta.getColNum();
    int elemNum = 0;
    int size = rowSplits.size();
    for (int i = 0; i < size; i++) {
        elemNum += rowSplits.get(i).size();
    }
    IntIntVector row;
    if (elemNum >= (int) (storageConvFactor * colNum)) {
        row = VFactory.denseIntVector(colNum);
    } else {
        row = VFactory.sparseIntVector(colNum, elemNum);
    }
    row.setMatrixId(matrixMeta.getId());
    row.setRowId(rowIndex);
    Collections.sort(rowSplits, serverRowComp);
    int clock = Integer.MAX_VALUE;
    for (int i = 0; i < size; i++) {
        if (rowSplits.get(i) == null) {
            continue;
        }
        if (rowSplits.get(i).getClock() < clock) {
            clock = rowSplits.get(i).getClock();
        }
        ((ServerIntIntRow) rowSplits.get(i)).mergeTo(row);
    }
    row.setClock(clock);
    return row;
}
Also used : IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector) ServerIntIntRow(com.tencent.angel.ps.storage.vector.ServerIntIntRow)

Aggregations

ServerIntIntRow (com.tencent.angel.ps.storage.vector.ServerIntIntRow)6 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)4 PartitionKey (com.tencent.angel.PartitionKey)3 IntIntVector (com.tencent.angel.ml.math2.vector.IntIntVector)2 AngelException (com.tencent.angel.exception.AngelException)1 ScalarPartitionAggrResult (com.tencent.angel.ml.matrix.psf.aggr.enhance.ScalarPartitionAggrResult)1 PartitionGetRowsParam (com.tencent.angel.ml.matrix.psf.get.getrows.PartitionGetRowsParam)1 MatrixStorageManager (com.tencent.angel.ps.storage.MatrixStorageManager)1 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)1 HashMap (java.util.HashMap)1