In backprob of times Dense Sparse no switching to sparse

This commit is contained in:
Thilo Will 2016-08-23 16:45:45 +02:00
Родитель 8c2ec53cde
Коммит 2de2ffb10b
2 изменённых файлов: 14 добавлений и 15 удалений

Просмотреть файл

@ -330,15 +330,8 @@ public:
if (inputIndex == 0) // left derivative
{
// TODO: we might leverage the fact that eg. for dense * sparse input(0)->Gradient() might ideally me block sparse.
// Currently AddMatrixProductOf(..) doesn't support that.
// currently we only support one combination when the input is sparse
// If input data is sparse, then gradient is block sparse.
// BUGBUG: This does not accumulate into the Input(0)->Gradient, which might cause problems elsewhere.
if (Input(1)->Value().GetMatrixType() == SPARSE && Input(0)->Gradient().GetMatrixType() == DENSE && Gradient().GetMatrixType() == DENSE)
Input(0)->Gradient().SwitchToMatrixType(SPARSE, MatrixFormat::matrixFormatSparseBlockCol, false);
// TODO: we might leverage the fact that eg. for dense * sparse input(0)->Gradient() might ideally be represented as block sparse.
// Currently AddMatrixProductOf(..) doesn't support that.
auto input0Gradient = OneSampleTensorFor(0, /*gradient=*/true, fr.AllowBroadcast());
auto input1 = OneSampleTensorFor(1, /*gradient=*/false, fr.AllowBroadcast());
auto outputGradient = OneSampleTensorFor(-1, /*gradient=*/true, fr);

Просмотреть файл

@ -4434,12 +4434,18 @@ void Matrix<ElemType>::MultiplyAndWeightedAdd(ElemType alpha, const Matrix<ElemT
*c.m_GPUSparseMatrix = tmpSparse + (*c.m_GPUSparseMatrix) * beta;
c.SetDataLocation(GPU, SPARSE);
}
else if (a.m_matrixType == MatrixType::SPARSE && b.m_matrixType == MatrixType::SPARSE && c.m_matrixType == MatrixType::DENSE) // GPU, SPARSE * SPARSE -> DENSE
NOT_IMPLEMENTED;
else if (a.m_matrixType == MatrixType::SPARSE && b.m_matrixType == MatrixType::DENSE && c.m_matrixType == MatrixType::SPARSE) // GPU, SPARSE * DENSE -> SPARSE
NOT_IMPLEMENTED;
else // No combination left
NOT_IMPLEMENTED; // We should never get here.
else if (a.m_matrixType == MatrixType::SPARSE && b.m_matrixType == MatrixType::SPARSE && c.m_matrixType == MatrixType::DENSE) // GPU, SPARSE * SPARSE -> DENSE
{
NOT_IMPLEMENTED;
}
else if (a.m_matrixType == MatrixType::SPARSE && b.m_matrixType == MatrixType::DENSE && c.m_matrixType == MatrixType::SPARSE) // GPU, SPARSE * DENSE -> SPARSE
{
NOT_IMPLEMENTED;
}
else // No combination left
{
NOT_IMPLEMENTED;
}
}
}