From 2afe66093a40dd46395b9294045af2a1a20821d5 Mon Sep 17 00:00:00 2001 From: hedaoyuan Date: Tue, 30 Aug 2016 13:37:44 +0000 Subject: [PATCH] multi-gpu training with sparse input. ISSUE=4586833 git-svn-id: https://svn.baidu.com/idl/trunk/paddle@1429 1ad973e4-5ce8-4261-8a94-b56d1f490c56 --- paddle/parameter/Argument.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/paddle/parameter/Argument.cpp b/paddle/parameter/Argument.cpp index 374b78841..93f86cecc 100644 --- a/paddle/parameter/Argument.cpp +++ b/paddle/parameter/Argument.cpp @@ -14,6 +14,7 @@ limitations under the License. */ #include "Argument.h" +#include "paddle/math/SparseMatrix.h" #include @@ -68,7 +69,15 @@ static void resizeAndCopy(MatrixPtr& dest, const MatrixPtr& src, dest->resize(height, width); } MatrixPtr submat = src->subMatrix(startRow, copySize); - dest->copyFrom(*submat, stream); + if (dynamic_cast(dest.get())) { + // copy a subMatrix of CpuSparseMatrix to GpuSparseMatrix. + // First copy it to CPU, and then copy it to the GPU. + MatrixPtr tmp = src->clone(height, width, false); + tmp->copyFrom(*submat, stream); + dest->copyFrom(*tmp, stream); + } else { + dest->copyFrom(*submat, stream); + } } else { dest.reset(); } -- GitLab