Repository navigation
CUTENSOR: axpy! and axpby! not mutating fixed - #1416
Merged
Merged
Conversation
axpy! and axpby! are supposed to overwrite the input (in-place multiplication) without allocating a new CuTensor in memory. This fixes the incorrect behavior as well as improving performance.
Creates a copy of input tensor before calling axpy! and axpby! and checks if the returned tensor points to the overwritten input.
Codecov Report
@@ Coverage Diff @@
## master #1416 +/- ##
==========================================
- Coverage 76.66% 75.94% -0.72%
==========================================
Files 124 124
Lines 9246 9247 +1
==========================================
- Hits 7088 7023 -65
- Misses 2158 2224 +66
Continue to review full report at Codecov.
|
Contributor
Author
|
UPDATE: Unit test |
yapanuwan
marked this pull request as ready for review
February 27, 2022 03:09
maleadt
requested changes
Mar 7, 2022
maleadt
left a comment
Member
There was a problem hiding this comment.
Thanks for the contribution, and sorry for the delayed response! LGTM, but I'd change the test to prevent needless copying and comparison.
Implement Base.copy() for CuTensors which duplicates the object with all its contents.
simonbyrne
pushed a commit
to simonbyrne/CUDA.jl
that referenced
this pull request
Nov 13, 2023
* In-place multiplication axpy! and axpby! are supposed to overwrite the input (in-place multiplication) without allocating a new CuTensor in memory. This fixes the incorrect behavior as well as improving performance. * Tests for in-place behavior Creates a copy of input tensor before calling axpy! and axpby! and checks if the returned tensor points to the overwritten input. * Refractor by implementing CuTensor copying Implement Base.copy() for CuTensors which duplicates the object with all its contents.
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.
axpy!andaxpby!routines are supposed to overwrite the input array (mutating / in-place operation) without allocating a new array in memory. From the official LinearAlgebra documentation,This quick fix corrects the behavior as well as improving performance.
Luckily, according to NVIDIA's cuTENSOR documentation for cutensorElementwiseBinary(), the output tensor could be aliasing an input tensor.
So the fix turned out be really easy.
Please be warned that I'm a newbie when it comes to open-source collaborations. An expert's opinion is highly appreciated. I cross-checked the outputs in my own application. It worked correctly, and the performance had improved dramatically!