Search in sources :

Example 1 with PartitionGetResult

use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.

the class WorkerPool method getSplit.

/**
 * Get from the partition use PSF
 * @param seqId rpc request id
 * @param request request
 * @return serialized rpc response contain the get result
 */
private ByteBuf getSplit(int seqId, GetUDFRequest request) {
    GetUDFResponse response = null;
    try {
        Class<? extends GetFunc> funcClass = (Class<? extends GetFunc>) Class.forName(request.getGetFuncClass());
        Constructor<? extends GetFunc> constructor = funcClass.getConstructor();
        constructor.setAccessible(true);
        GetFunc func = constructor.newInstance();
        func.setPsContext(context);
        PartitionGetResult partResult = func.partitionGet(request.getPartParam());
        response = new GetUDFResponse(partResult);
        response.setResponseType(ResponseType.SUCCESS);
    } catch (Throwable e) {
        LOG.fatal("get udf request " + request + " failed ", e);
        response = new GetUDFResponse();
        response.setDetail("get udf request failed " + e.getMessage());
        response.setResponseType(ResponseType.SERVER_HANDLE_FATAL);
    }
    long startTs = System.currentTimeMillis();
    ByteBuf buf = ByteBufUtils.newByteBuf(4 + response.bufferLen(), useDirectorBuffer);
    buf.writeInt(seqId);
    response.serialize(buf);
    LOG.info("Serialize use time=" + (System.currentTimeMillis() - startTs));
    return buf;
}
Also used : GetFunc(com.tencent.angel.ml.matrix.psf.get.base.GetFunc) ByteBuf(io.netty.buffer.ByteBuf) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Example 2 with PartitionGetResult

use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.

the class MatrixTransportClient method get.

@SuppressWarnings("unchecked")
@Override
public Future<PartitionGetResult> get(GetFunc func, PartitionGetParam partitionGetParam) {
    ParameterServerId serverId = PSAgentContext.get().getMatrixMetaManager().getMasterPS((partitionGetParam.getPartKey()));
    GetUDFRequest request = new GetUDFRequest(partitionGetParam.getPartKey(), func.getClass().getName(), partitionGetParam);
    LOG.debug("get request=" + request);
    FutureResult<PartitionGetResult> future = new FutureResult<PartitionGetResult>();
    FutureResult<PartitionGetResult> oldFuture = requestToResultMap.putIfAbsent(request, future);
    if (oldFuture != null) {
        LOG.debug("same request exist, just return old future");
        return oldFuture;
    } else {
        addToGetQueueForServer(serverId, request);
        startGet();
        return future;
    }
}
Also used : ParameterServerId(com.tencent.angel.ps.ParameterServerId) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Example 3 with PartitionGetResult

use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.

the class ValuesCombineUtils method mergeSparseFloatCompVector.

public static CompSparseFloatVector mergeSparseFloatCompVector(IndexGetParam param, List<PartitionGetResult> partResults) {
    Map<PartitionKey, PartitionGetResult> partKeyToResultMap = mapPartKeyToResult(partResults);
    List<PartitionKey> partKeys = getSortedPartKeys(param.matrixId, param.getRowId());
    MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(param.matrixId);
    int size = partKeys.size();
    SparseFloatVector[] splitVecs = new SparseFloatVector[size];
    for (int i = 0; i < size; i++) {
        if (param.getPartKeyToIndexesMap().containsKey(partKeys.get(i))) {
            splitVecs[i] = new SparseFloatVector((int) meta.getColNum(), param.getPartKeyToIndexesMap().get(partKeys.get(i)), ((IndexPartGetFloatResult) partKeyToResultMap.get(partKeys.get(i))).getValues());
        }
    }
    return new CompSparseFloatVector(meta.getId(), param.getRowId(), (int) meta.getColNum(), partKeys.toArray(new PartitionKey[0]), splitVecs);
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) PartitionKey(com.tencent.angel.PartitionKey) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Example 4 with PartitionGetResult

use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.

the class ValuesCombineUtils method mergeSparseDoubleCompVector.

public static CompSparseLongKeyDoubleVector mergeSparseDoubleCompVector(LongIndexGetParam param, List<PartitionGetResult> partResults) {
    Map<PartitionKey, PartitionGetResult> partKeyToResultMap = mapPartKeyToResult(partResults);
    List<PartitionKey> partKeys = getSortedPartKeys(param.matrixId, param.getRowId());
    MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(param.matrixId);
    int size = partKeys.size();
    SparseLongKeyDoubleVector[] splitVecs = new SparseLongKeyDoubleVector[size];
    for (int i = 0; i < size; i++) {
        if (param.getPartKeyToIndexesMap().containsKey(partKeys.get(i))) {
            splitVecs[i] = new SparseLongKeyDoubleVector(meta.getColNum(), param.getPartKeyToIndexesMap().get(partKeys.get(i)), ((LongIndexGetResult) partKeyToResultMap.get(partKeys.get(i))).getValues());
        }
    }
    CompSparseLongKeyDoubleVector vector = new CompSparseLongKeyDoubleVector(meta.getId(), param.getRowId(), meta.getColNum(), partKeys.toArray(new PartitionKey[0]), splitVecs);
    return vector;
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) PartitionKey(com.tencent.angel.PartitionKey) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Example 5 with PartitionGetResult

use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.

the class ValuesCombineUtils method mergeSparseFloatVector.

public static SparseFloatVector mergeSparseFloatVector(IndexGetParam param, List<PartitionGetResult> partResults) {
    SparseFloatVector vector = new SparseFloatVector((int) PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(param.getMatrixId()).getColNum(), param.size());
    for (PartitionGetResult part : partResults) {
        PartitionKey partKey = ((IndexPartGetFloatResult) part).getPartKey();
        int[] indexes = param.getPartKeyToIndexesMap().get(partKey);
        float[] values = ((IndexPartGetFloatResult) part).getValues();
        for (int i = 0; i < indexes.length; i++) {
            vector.set(indexes[i], values[i]);
        }
    }
    vector.setMatrixId(param.getMatrixId());
    vector.setRowId(param.getRowId());
    return vector;
}
Also used : PartitionKey(com.tencent.angel.PartitionKey) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Aggregations

PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)12 PartitionKey (com.tencent.angel.PartitionKey)8 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)4 ArrayAggrResult (com.tencent.angel.ml.matrix.psf.aggr.enhance.ArrayAggrResult)1 ArrayPartitionAggrResult (com.tencent.angel.ml.matrix.psf.aggr.enhance.ArrayPartitionAggrResult)1 FullAggrResult (com.tencent.angel.ml.matrix.psf.aggr.enhance.FullAggrResult)1 FullPartitionAggrResult (com.tencent.angel.ml.matrix.psf.aggr.enhance.FullPartitionAggrResult)1 GetFunc (com.tencent.angel.ml.matrix.psf.get.base.GetFunc)1 ParameterServerId (com.tencent.angel.ps.ParameterServerId)1 ByteBuf (io.netty.buffer.ByteBuf)1