Search in sources :

Example 1 with KeyValuePart

use of com.tencent.angel.psagent.matrix.transport.router.KeyValuePart in project angel by Tencent.

the class HashRouterUtils method splitStream.

/**
 * Split keys by matrix partition
 *
 * @param matrixMeta matrix meta data
 * @param vectors Matrix vectors
 * @return partition key to key partition map
 */
public static CompStreamKeyValuePart[] splitStream(MatrixMeta matrixMeta, Vector[] vectors) {
    PartitionKey[] matrixParts = matrixMeta.getPartitionKeys();
    // Use comp key value part
    CompStreamKeyValuePart[] dataParts = new CompStreamKeyValuePart[matrixParts.length];
    KeyValuePart[][] subDataParts = new KeyValuePart[vectors.length][];
    // Split each vector
    for (int i = 0; i < subDataParts.length; i++) {
        subDataParts[i] = split(matrixMeta, vectors[i]);
    }
    // Combine sub data part
    for (int i = 0; i < dataParts.length; i++) {
        dataParts[i] = new CompStreamKeyValuePart(vectors.length);
        for (int j = 0; j < vectors.length; j++) {
            dataParts[i].add(subDataParts[j][i]);
        }
    }
    return dataParts;
}
Also used : PartitionKey(com.tencent.angel.PartitionKey) CompStreamKeyValuePart(com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart) KeyValuePart(com.tencent.angel.psagent.matrix.transport.router.KeyValuePart) CompStreamKeyValuePart(com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart)

Example 2 with KeyValuePart

use of com.tencent.angel.psagent.matrix.transport.router.KeyValuePart in project angel by Tencent.

the class GeneralInitParam method split.

@Override
public List<PartitionUpdateParam> split() {
    MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    PartitionKey[] parts = meta.getPartitionKeys();
    KeyValuePart[] splits = RouterUtils.split(meta, 0, nodeIds, features);
    assert parts.length == splits.length;
    List<PartitionUpdateParam> partParams = new ArrayList<>(parts.length);
    for (int i = 0; i < parts.length; i++) {
        if (splits[i] != null && splits[i].size() > 0) {
            partParams.add(new GeneralPartUpdateParam(matrixId, parts[i], splits[i]));
        }
    }
    return partParams;
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) PartitionUpdateParam(com.tencent.angel.ml.matrix.psf.update.base.PartitionUpdateParam) ArrayList(java.util.ArrayList) GeneralPartUpdateParam(com.tencent.angel.ml.matrix.psf.update.base.GeneralPartUpdateParam) PartitionKey(com.tencent.angel.PartitionKey) KeyValuePart(com.tencent.angel.psagent.matrix.transport.router.KeyValuePart)

Example 3 with KeyValuePart

use of com.tencent.angel.psagent.matrix.transport.router.KeyValuePart in project angel by Tencent.

the class SampleNeighborWithFilterParam method split.

@Override
public List<PartitionGetParam> split() {
    // Get matrix meta
    MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    PartitionKey[] partitions = meta.getPartitionKeys();
    // Split nodeIds
    KeyValuePart[] splits = RouterUtils.split(meta, 0, nodeIds, filterWithNeighKeys);
    assert partitions.length == splits.length;
    // Generate node ids
    List<PartitionGetParam> partParams = new ArrayList<>(partitions.length);
    for (int i = 0; i < partitions.length; i++) {
        if (splits[i] != null && splits[i].size() > 0) {
            partParams.add(new PartSampleNeighborWithFilterParam(matrixId, partitions[i], count, sampleType, splits[i], filterWithoutNeighKeys));
        }
    }
    return partParams;
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) ArrayList(java.util.ArrayList) PartitionKey(com.tencent.angel.PartitionKey) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam) KeyValuePart(com.tencent.angel.psagent.matrix.transport.router.KeyValuePart)

Example 4 with KeyValuePart

use of com.tencent.angel.psagent.matrix.transport.router.KeyValuePart in project angel by Tencent.

the class ByteBufSerdeUtils method deserializeKeyValuePart.

public static KeyValuePart deserializeKeyValuePart(ByteBuf in) {
    boolean isComp = ByteBufSerdeUtils.deserializeBoolean(in);
    KeyValuePart keyValuePart;
    if (isComp) {
        keyValuePart = new CompStreamKeyValuePart();
    } else {
        RouterType routerType = RouterType.valueOf(deserializeInt(in));
        RowType keyValueType = RowType.valueOf(deserializeInt(in));
        keyValuePart = DataPartFactory.createKeyValuePart(keyValueType, routerType);
    }
    keyValuePart.deserialize(in);
    return keyValuePart;
}
Also used : RouterType(com.tencent.angel.psagent.matrix.transport.router.RouterType) RowType(com.tencent.angel.ml.matrix.RowType) CompStreamKeyValuePart(com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart) KeyValuePart(com.tencent.angel.psagent.matrix.transport.router.KeyValuePart) CompStreamKeyValuePart(com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart)

Example 5 with KeyValuePart

use of com.tencent.angel.psagent.matrix.transport.router.KeyValuePart in project angel by Tencent.

the class HashRouterUtils method split.

/**
 * Split keys by matrix partition
 *
 * @param matrixMeta matrix meta data
 * @param vector Matrix vector
 * @return partition key to key partition map
 */
public static KeyValuePart[] split(MatrixMeta matrixMeta, Vector vector) {
    KeyHash hasher = HasherFactory.getHasher(matrixMeta.getRouterHash());
    PartitionKey[] matrixParts = matrixMeta.getPartitionKeys();
    KeyValuePart[] dataParts = new KeyValuePart[matrixParts.length];
    int estSize = (int) (vector.getSize() / matrixMeta.getPartitionNum());
    for (int i = 0; i < dataParts.length; i++) {
        dataParts[i] = generateDataPart(vector.getRowId(), vector.getType(), estSize);
    }
    switch(vector.getType()) {
        case T_DOUBLE_DENSE:
        case T_DOUBLE_SPARSE:
            {
                splitIntDoubleVector(hasher, matrixMeta, (IntDoubleVector) vector, dataParts);
                break;
            }
        case T_FLOAT_DENSE:
        case T_FLOAT_SPARSE:
            {
                splitIntFloatVector(hasher, matrixMeta, (IntFloatVector) vector, dataParts);
                break;
            }
        case T_INT_DENSE:
        case T_INT_SPARSE:
            {
                splitIntIntVector(hasher, matrixMeta, (IntIntVector) vector, dataParts);
                break;
            }
        case T_LONG_DENSE:
        case T_LONG_SPARSE:
            {
                splitIntLongVector(hasher, matrixMeta, (IntLongVector) vector, dataParts);
                break;
            }
        case T_DOUBLE_SPARSE_LONGKEY:
            {
                splitLongDoubleVector(hasher, matrixMeta, (LongDoubleVector) vector, dataParts);
                break;
            }
        case T_FLOAT_SPARSE_LONGKEY:
            {
                splitLongFloatVector(hasher, matrixMeta, (LongFloatVector) vector, dataParts);
                break;
            }
        case T_INT_SPARSE_LONGKEY:
            {
                splitLongIntVector(hasher, matrixMeta, (LongIntVector) vector, dataParts);
                break;
            }
        case T_LONG_SPARSE_LONGKEY:
            {
                splitLongLongVector(hasher, matrixMeta, (LongLongVector) vector, dataParts);
                break;
            }
        default:
            {
                throw new UnsupportedOperationException("Unsupport vector type " + vector.getType());
            }
    }
    for (int i = 0; i < dataParts.length; i++) {
        if (dataParts[i] != null) {
            dataParts[i].setRowId(vector.getRowId());
        }
    }
    return dataParts;
}
Also used : IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) CompStreamKeyValuePart(com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart) KeyValuePart(com.tencent.angel.psagent.matrix.transport.router.KeyValuePart) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) KeyHash(com.tencent.angel.psagent.matrix.transport.router.KeyHash) PartitionKey(com.tencent.angel.PartitionKey)

Aggregations

KeyValuePart (com.tencent.angel.psagent.matrix.transport.router.KeyValuePart)12 PartitionKey (com.tencent.angel.PartitionKey)9 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)7 ArrayList (java.util.ArrayList)7 PartitionUpdateParam (com.tencent.angel.ml.matrix.psf.update.base.PartitionUpdateParam)5 GeneralPartUpdateParam (com.tencent.angel.ml.matrix.psf.update.base.GeneralPartUpdateParam)4 CompStreamKeyValuePart (com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart)4 PartitionGetParam (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)2 IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)1 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)1 IntIntVector (com.tencent.angel.ml.math2.vector.IntIntVector)1 IntLongVector (com.tencent.angel.ml.math2.vector.IntLongVector)1 LongDoubleVector (com.tencent.angel.ml.math2.vector.LongDoubleVector)1 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)1 LongIntVector (com.tencent.angel.ml.math2.vector.LongIntVector)1 LongLongVector (com.tencent.angel.ml.math2.vector.LongLongVector)1 RowType (com.tencent.angel.ml.matrix.RowType)1 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)1 KeyHash (com.tencent.angel.psagent.matrix.transport.router.KeyHash)1 RouterType (com.tencent.angel.psagent.matrix.transport.router.RouterType)1