|
|
@ -22,11 +22,8 @@ namespace paddle {
|
|
|
|
static void resizeAndCopy(MatrixPtr& dest, const MatrixPtr& src, bool useGpu,
|
|
|
|
static void resizeAndCopy(MatrixPtr& dest, const MatrixPtr& src, bool useGpu,
|
|
|
|
hl_stream_t stream) {
|
|
|
|
hl_stream_t stream) {
|
|
|
|
if (src) {
|
|
|
|
if (src) {
|
|
|
|
if (!dest) {
|
|
|
|
Matrix::resizeOrCreate(dest, src->getHeight(),
|
|
|
|
dest = src->clone(0, 0, useGpu);
|
|
|
|
src->getWidth(), false, useGpu);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
dest->resize(src->getHeight(), src->getWidth());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dest->copyFrom(*src, stream);
|
|
|
|
dest->copyFrom(*src, stream);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
dest.reset();
|
|
|
|
dest.reset();
|
|
|
@ -60,14 +57,9 @@ static void resizeAndCopy(MatrixPtr& dest, const MatrixPtr& src,
|
|
|
|
hl_stream_t stream = HPPL_STREAM_DEFAULT) {
|
|
|
|
hl_stream_t stream = HPPL_STREAM_DEFAULT) {
|
|
|
|
if (src) {
|
|
|
|
if (src) {
|
|
|
|
CHECK_LE((size_t)startRow + copySize, src->getHeight());
|
|
|
|
CHECK_LE((size_t)startRow + copySize, src->getHeight());
|
|
|
|
|
|
|
|
|
|
|
|
int height = copySize;
|
|
|
|
int height = copySize;
|
|
|
|
int width = src->getWidth();
|
|
|
|
int width = src->getWidth();
|
|
|
|
if (!dest) {
|
|
|
|
Matrix::resizeOrCreate(dest, height, width, false, useGpu);
|
|
|
|
dest = src->clone(height, width, useGpu);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
dest->resize(height, width);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
MatrixPtr submat = src->subMatrix(startRow, copySize);
|
|
|
|
MatrixPtr submat = src->subMatrix(startRow, copySize);
|
|
|
|
if (dynamic_cast<GpuSparseMatrix*>(dest.get())) {
|
|
|
|
if (dynamic_cast<GpuSparseMatrix*>(dest.get())) {
|
|
|
|
// copy a subMatrix of CpuSparseMatrix to GpuSparseMatrix.
|
|
|
|
// copy a subMatrix of CpuSparseMatrix to GpuSparseMatrix.
|
|
|
@ -182,6 +174,11 @@ static void resizeAndCopy(SVectorPtr& dest, const SVectorPtr& src,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Argument::resizeAndCopyFrom(const Argument& src, bool useGpu) {
|
|
|
|
|
|
|
|
resizeAndCopyFrom(src, useGpu, HPPL_STREAM_DEFAULT);
|
|
|
|
|
|
|
|
hl_stream_synchronize(HPPL_STREAM_DEFAULT);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Argument::resizeAndCopyFrom(const Argument& src, bool useGpu,
|
|
|
|
void Argument::resizeAndCopyFrom(const Argument& src, bool useGpu,
|
|
|
|
hl_stream_t stream) {
|
|
|
|
hl_stream_t stream) {
|
|
|
|
dataId = src.dataId;
|
|
|
|
dataId = src.dataId;
|
|
|
@ -199,6 +196,14 @@ void Argument::resizeAndCopyFrom(const Argument& src, bool useGpu,
|
|
|
|
resizeAndCopy(strs, src.strs, useGpu, stream);
|
|
|
|
resizeAndCopy(strs, src.strs, useGpu, stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32_t Argument::resizeAndCopyFrom(const Argument& src, int32_t startSeq,
|
|
|
|
|
|
|
|
int32_t copySize, bool useGpu) {
|
|
|
|
|
|
|
|
int32_t size = resizeAndCopyFrom(src, startSeq, copySize, useGpu,
|
|
|
|
|
|
|
|
HPPL_STREAM_DEFAULT);
|
|
|
|
|
|
|
|
hl_stream_synchronize(HPPL_STREAM_DEFAULT);
|
|
|
|
|
|
|
|
return size;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t Argument::resizeAndCopyFrom(const Argument& src, int32_t startSeq,
|
|
|
|
int32_t Argument::resizeAndCopyFrom(const Argument& src, int32_t startSeq,
|
|
|
|
int32_t copySize, bool useGpu,
|
|
|
|
int32_t copySize, bool useGpu,
|
|
|
|
hl_stream_t stream) {
|
|
|
|
hl_stream_t stream) {
|
|
|
|