Skip to content

Fixed reducedim operations for CuQRPackedQ #1118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rkube
Copy link

@rkube rkube commented Aug 26, 2021

Applying Base.sum/prod/maximum/minimum to CuQRPackedQ raises ERROR: Scalar indexing is disallowed Casting to CuArray fixes the issue. Also, Base.similar returned a CPU matrix when applied to CuQRPackedQ @DhairyaLGandhi

@maleadt
Copy link
Member

maleadt commented Aug 26, 2021

I understand your motivation, but I don't like the fix 😛 What's special about sum, or the other reduction operators you've selected? I guess we don't really have another way to make those operations dispatch to the existing implementations (which would also require making CuQRPackedQ device compatible so that it can use the existing sum kernel as is).

@maleadt maleadt added cuda array Stuff about CuArray. enhancement New feature or request labels Aug 26, 2021
@rkube
Copy link
Author

rkube commented Aug 26, 2021

Those four reduction operators are all dispatched in a similar manner: https://github.com/JuliaLang/julia/blob/bb2d8630f3aeb99c38c659a35ee9aa57bb71012a/base/reducedim.jl#L885

So I thought to handle them all equally. Feel free to close this if it's not needed.

@codecov
Copy link

codecov bot commented Aug 26, 2021

Codecov Report

Merging #1118 (0e0dc5d) into master (afe8179) will decrease coverage by 0.06%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1118      +/-   ##
==========================================
- Coverage   79.44%   79.37%   -0.07%     
==========================================
  Files         118      118              
  Lines        8001     8006       +5     
==========================================
- Hits         6356     6355       -1     
- Misses       1645     1651       +6     
Impacted Files Coverage Δ
lib/cusolver/linalg.jl 79.71% <0.00%> (-6.23%) ⬇️
src/pool.jl 75.52% <0.00%> (-0.43%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update afe8179...0e0dc5d. Read the comment docs.

Copy link
Member

@maleadt maleadt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a note on why we need these definitions.

Needs tests though.

@@ -26,6 +26,14 @@ Base.size(A::CuQRPackedQ, dim::Integer) = 0 < dim ? (dim <= 2 ? size(A.factors,
CUDA.CuMatrix(A::CuQRPackedQ) = orgqr!(copy(A.factors), A.τ)
CUDA.CuArray(A::CuQRPackedQ) = CuMatrix(A)
Base.Matrix(A::CuQRPackedQ) = Matrix(CuMatrix(A))
Base.similar(A::CuQRPackedQ{S,T}) where {S,T} = CuArray{S, ndims(a)}(undef, size(a))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a vs A
T and S are switched around compared to the CuQRPackedQ definition
Also, can't you get N statically from S typevar?

@@ -26,6 +26,14 @@ Base.size(A::CuQRPackedQ, dim::Integer) = 0 < dim ? (dim <= 2 ? size(A.factors,
CUDA.CuMatrix(A::CuQRPackedQ) = orgqr!(copy(A.factors), A.τ)
CUDA.CuArray(A::CuQRPackedQ) = CuMatrix(A)
Base.Matrix(A::CuQRPackedQ) = Matrix(CuMatrix(A))
Base.similar(A::CuQRPackedQ{S,T}) where {S,T} = CuArray{S, ndims(a)}(undef, size(a))

# CuQRPackedQ isn't an AbstractGPUArray, so we miss out on lots of GPU-compatible methods.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want the same for CuQR?

Copy link
Member

@DhairyaLGandhi DhairyaLGandhi Aug 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be an AbstractGPUArray?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How? It's currently a AbstractQ already, and presumable that's more useful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, that is true

@maleadt
Copy link
Member

maleadt commented Aug 27, 2021

So I thought to handle them all equally.

I meant: why sum in the first place, just because of your needs or is this a common operation to perform on qr(...).Q?

@maleadt maleadt added needs changes Changes are needed. needs tests Tests are requested. labels Aug 27, 2021
Copy link
Member

@DhairyaLGandhi DhairyaLGandhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! Agreed that we shouldn't be defining such specific methods, if it's avoidable.

Can we not make these types device compatible? I guess the factors already are CuArrays

@@ -26,6 +26,14 @@ Base.size(A::CuQRPackedQ, dim::Integer) = 0 < dim ? (dim <= 2 ? size(A.factors,
CUDA.CuMatrix(A::CuQRPackedQ) = orgqr!(copy(A.factors), A.τ)
CUDA.CuArray(A::CuQRPackedQ) = CuMatrix(A)
Base.Matrix(A::CuQRPackedQ) = Matrix(CuMatrix(A))
Base.similar(A::CuQRPackedQ{S,T}) where {S,T} = CuArray{S, ndims(a)}(undef, size(a))

# CuQRPackedQ isn't an AbstractGPUArray, so we miss out on lots of GPU-compatible methods.
Copy link
Member

@DhairyaLGandhi DhairyaLGandhi Aug 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be an AbstractGPUArray?

@maleadt maleadt force-pushed the master branch 4 times, most recently from 5d585c4 to c850163 Compare December 20, 2024 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuda array Stuff about CuArray. enhancement New feature or request needs changes Changes are needed. needs tests Tests are requested.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants