Search in sources :

Example 26 with MatrixMeta

use of com.tencent.angel.ml.matrix.MatrixMeta in project angel by Tencent.

the class LongKeysGetParam method split.

@Override
public List<PartitionGetParam> split() {
    // Get matrix meta
    MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    PartitionKey[] parts = meta.getPartitionKeys();
    // Split
    KeyPart[] nodeIdsParts = RouterUtils.split(meta, 0, nodeIds, false);
    // Generate Part psf get param
    List<PartitionGetParam> partParams = new ArrayList<>(parts.length);
    assert parts.length == nodeIdsParts.length;
    for (int i = 0; i < parts.length; i++) {
        if (nodeIdsParts[i] != null && nodeIdsParts[i].size() > 0) {
            partParams.add(new GeneralPartGetParam(matrixId, parts[i], nodeIdsParts[i]));
        }
    }
    return partParams;
}
Also used : GeneralPartGetParam(com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam) MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) ArrayList(java.util.ArrayList) PartitionKey(com.tencent.angel.PartitionKey) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)

Example 27 with MatrixMeta

use of com.tencent.angel.ml.matrix.MatrixMeta in project angel by Tencent.

the class RowSplitCombineUtils method combineServerRowSplits.

/**
 * Combine row splits of a single matrix row.
 *
 * @param rowSplits row splits
 * @param matrixId matrix id
 * @param rowIndex row index
 * @return TVector merged row
 */
public static Vector combineServerRowSplits(List<ServerRow> rowSplits, int matrixId, int rowIndex) {
    MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    RowType rowType = matrixMeta.getRowType();
    switch(rowType) {
        case T_DOUBLE_DENSE:
        case T_DOUBLE_SPARSE:
            return combineServerIntDoubleRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_FLOAT_DENSE:
        case T_FLOAT_SPARSE:
            return combineServerIntFloatRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_INT_DENSE:
        case T_INT_SPARSE:
            return combineServerIntIntRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_LONG_DENSE:
        case T_LONG_SPARSE:
            return combineServerIntLongRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_DOUBLE_SPARSE_LONGKEY:
            return combineServerLongDoubleRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_FLOAT_SPARSE_LONGKEY:
            return combineServerLongFloatRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_INT_SPARSE_LONGKEY:
            return combineServerLongIntRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_LONG_SPARSE_LONGKEY:
            return combineServerLongLongRowSplits(rowSplits, matrixMeta, rowIndex);
        default:
            throw new UnsupportedOperationException("Unsupport operation: merge " + rowType + " vector splits");
    }
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) RowType(com.tencent.angel.ml.matrix.RowType)

Example 28 with MatrixMeta

use of com.tencent.angel.ml.matrix.MatrixMeta in project angel by Tencent.

the class UserRequestAdapter method update.

public Future<VoidResult> update(int matrixId, int rowId, Vector delta, UpdateOp op) {
    checkParams(matrixId, rowId);
    delta.setMatrixId(matrixId);
    delta.setRowId(rowId);
    MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    PartitionKey[] parts = matrixMeta.getPartitionKeys();
    CompStreamKeyValuePart[] splits = RouterUtils.splitStream(matrixMeta, delta);
    FutureResult<VoidResult> result = new FutureResult<>();
    int needRequestPartNum = noEmptyPartNum(splits);
    if (needRequestPartNum == 0) {
        result.set(null);
        return result;
    }
    UpdateRowRequest request = new UpdateRowRequest(matrixId, rowId, op);
    ResponseCache cache = new MapResponseCache(needRequestPartNum);
    int requestId = request.getRequestId();
    requestIdToResponseCache.put(requestId, cache);
    requestIdToResultMap.put(requestId, result);
    requests.put(requestId, request);
    MatrixTransportClient matrixClient = PSAgentContext.get().getMatrixTransportClient();
    for (int i = 0; i < splits.length; i++) {
        if (splits[i] != null && splits[i].size() > 0) {
            sendUpdateRequest(matrixClient, requestId, matrixId, parts[i].getPartitionId(), splits[i], op);
        }
    }
    return result;
}
Also used : VoidResult(com.tencent.angel.ml.matrix.psf.update.base.VoidResult) MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) MapResponseCache(com.tencent.angel.psagent.matrix.transport.response.MapResponseCache) MatrixTransportClient(com.tencent.angel.psagent.matrix.transport.MatrixTransportClient) FutureResult(com.tencent.angel.psagent.matrix.transport.FutureResult) PartitionKey(com.tencent.angel.PartitionKey) MapResponseCache(com.tencent.angel.psagent.matrix.transport.response.MapResponseCache) ResponseCache(com.tencent.angel.psagent.matrix.transport.response.ResponseCache) CompStreamKeyValuePart(com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart)

Example 29 with MatrixMeta

use of com.tencent.angel.ml.matrix.MatrixMeta in project angel by Tencent.

the class UserRequestAdapter method checkParams.

private void checkParams(int matrixId, int[] rowIds) {
    MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    if (matrixMeta == null) {
        throw new AngelException("can not find matrix " + matrixId);
    }
    if (rowIds == null || rowIds.length == 0) {
        throw new AngelException("row ids is empty");
    }
    int rowNum = matrixMeta.getRowNum();
    for (int rowId : rowIds) {
        if (rowId < 0 || rowId >= rowNum) {
            throw new AngelException("not valid row id, row id is in range[0," + rowNum + ")");
        }
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta)

Example 30 with MatrixMeta

use of com.tencent.angel.ml.matrix.MatrixMeta in project angel by Tencent.

the class MergeUtils method combineServerRowSplits.

/**
 * Combine row splits of a single matrix row.
 *
 * @param rowSplits row splits
 * @param matrixId matrix id
 * @param rowIndex row index
 * @return TVector merged row
 */
public static Vector combineServerRowSplits(List<ServerRow> rowSplits, int matrixId, int rowIndex) {
    MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    RowType rowType = matrixMeta.getRowType();
    switch(rowType) {
        case T_DOUBLE_DENSE:
        case T_DOUBLE_SPARSE:
            return combineServerIntDoubleRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_FLOAT_DENSE:
        case T_FLOAT_SPARSE:
            return combineServerIntFloatRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_INT_DENSE:
        case T_INT_SPARSE:
            return combineServerIntIntRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_LONG_DENSE:
        case T_LONG_SPARSE:
            return combineServerIntLongRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_DOUBLE_SPARSE_LONGKEY:
            return combineServerLongDoubleRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_FLOAT_SPARSE_LONGKEY:
            return combineServerLongFloatRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_INT_SPARSE_LONGKEY:
            return combineServerLongIntRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_LONG_SPARSE_LONGKEY:
            return combineServerLongLongRowSplits(rowSplits, matrixMeta, rowIndex);
        default:
            throw new UnsupportedOperationException("Unsupport operation: merge " + rowType + " vector splits");
    }
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) RowType(com.tencent.angel.ml.matrix.RowType)

Aggregations

MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)78 PartitionKey (com.tencent.angel.PartitionKey)40 ArrayList (java.util.ArrayList)25 PartitionGetParam (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)13 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)13 PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)12 AngelException (com.tencent.angel.exception.AngelException)7 PartitionMeta (com.tencent.angel.ml.matrix.PartitionMeta)7 RowType (com.tencent.angel.ml.matrix.RowType)7 MatrixTransportClient (com.tencent.angel.psagent.matrix.transport.MatrixTransportClient)7 KeyValuePart (com.tencent.angel.psagent.matrix.transport.router.KeyValuePart)7 PartitionUpdateParam (com.tencent.angel.ml.matrix.psf.update.base.PartitionUpdateParam)6 Path (org.apache.hadoop.fs.Path)6 GeneralPartGetParam (com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam)5 ParameterServerId (com.tencent.angel.ps.ParameterServerId)5 FutureResult (com.tencent.angel.psagent.matrix.transport.FutureResult)5 MapResponseCache (com.tencent.angel.psagent.matrix.transport.response.MapResponseCache)5 ResponseCache (com.tencent.angel.psagent.matrix.transport.response.ResponseCache)5 AMMatrixMetaManager (com.tencent.angel.master.matrixmeta.AMMatrixMetaManager)4 Vector (com.tencent.angel.ml.math2.vector.Vector)4