Reject aliased c in matmulInPlace!, add regression tests - #140
Open
Quafadas wants to merge 2 commits into
Open
Conversation
matmulOutputCheck validated c's shape and dense-column-major layout, but never that c's backing array is distinct from m's or b's. BLAS dgemm/sgemm assume the output doesn't overlap the inputs: if c shares an array with m or b, dgemm can read an element of m/b after it's already been overwritten via the aliased c, silently corrupting the result instead of failing loudly - e.g. computing `a @@ a` in place into `a` itself. m and b may still safely share an array with each other (dgemm only ever reads those two), so only c-vs-m and c-vs-b are checked. Also verified the "row-major/strided/undersized c" concern separately raised: already covered by the existing shape and isDenseColMajor checks in matmulOutputCheck (see the "matmulInPlace! throws when c is row-major instead of column-major" and "...wrong shape" tests already in matMulLayoutChecks.test.scala) - no changes needed there. Added regression tests: c aliasing m throws, c aliasing b throws (via a distinct Matrix wrapping the same backing array, not just the same object reference), and m aliasing b remains allowed and correct.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
matmulOutputCheck validated c's shape and dense-column-major layout, but never that c's backing array is distinct from m's or b's. BLAS dgemm/sgemm assume the output doesn't overlap the inputs: if c shares an array with m or b, dgemm can read an element of m/b after it's already been overwritten via the aliased c, silently corrupting the result instead of failing loudly - e.g. computing
a @@ ain place intoaitself. m and b may still safely share an array with each other (dgemm only ever reads those two), so only c-vs-m and c-vs-b are checked.Also verified the "row-major/strided/undersized c" concern separately raised: already covered by the existing shape and isDenseColMajor checks in matmulOutputCheck (see the "matmulInPlace! throws when c is row-major instead of column-major" and "...wrong shape" tests already in matMulLayoutChecks.test.scala) - no changes needed there.
Added regression tests: c aliasing m throws, c aliasing b throws (via a distinct Matrix wrapping the same backing array, not just the same object reference), and m aliasing b remains allowed and correct.