Skip to content

Commit

Permalink
Fix a memshare bug to prevent non-shareable matrices to be allocated …
Browse files Browse the repository at this point in the history
…from the shared matrix pool
  • Loading branch information
amitaga committed Feb 25, 2016
1 parent 24acd99 commit 34de7e5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Source/ComputationNetworkLib/ComputationNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ struct ComputationNetworkOwnedNodeState

virtual void MarkValueNonSharable() { m_valueSharable = false; }
virtual void MarkValueSharable() { m_valueSharable = true; }
bool isValueSharable() const { return m_valueSharable; }
bool IsValueSharable() const { return m_valueSharable; }

protected: // TODO: should be fully encapsulated here

Expand Down Expand Up @@ -1359,14 +1359,17 @@ class ComputationNode : public ComputationNodeBase // abstract class that cannot
// request matrices needed to do node function value evaluation
virtual void RequestMatricesBeforeForwardProp(MatrixPool& matrixPool) override
{
RequestMatrixFromPool(m_value, matrixPool);
if (IsValueSharable())
RequestMatrixFromPool(m_value, matrixPool);
else
CreateMatrixIfNull(m_value);
}

// release temp matrices that are only used by forward computation
// don't release matrices that need to be used in the gradient computation
virtual void ReleaseMatricesAfterForwardProp(MatrixPool& matrixPool) override
{
if (!IsOutputNeededDuringBackprop() && (m_value->GetMatrixType() != SPARSE) && isValueSharable())
if (!IsOutputNeededDuringBackprop() && (m_value->GetMatrixType() != SPARSE) && IsValueSharable())
ReleaseMatrixToPool(m_value, matrixPool);
}

Expand Down Expand Up @@ -1395,7 +1398,7 @@ class ComputationNode : public ComputationNodeBase // abstract class that cannot

// Release the Value matrix only if the output value is needed during backprop
// since in the case it isn't used, we release it during forward prop itself
if (IsOutputNeededDuringBackprop() && m_value->GetMatrixType() != SPARSE && isValueSharable())
if (IsOutputNeededDuringBackprop() && m_value->GetMatrixType() != SPARSE && IsValueSharable())
ReleaseMatrixToPool(m_value, matrixPool);
}
}
Expand Down

0 comments on commit 34de7e5

Please sign in to comment.