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;
}
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;
}
}
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);
}
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;
}
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;
}
Aggregations