Skip to content
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

Problem with Base.mapreducedim! #521

Open
vpuri3 opened this issue Mar 6, 2024 · 2 comments
Open

Problem with Base.mapreducedim! #521

vpuri3 opened this issue Mar 6, 2024 · 2 comments

Comments

@vpuri3
Copy link
Contributor

vpuri3 commented Mar 6, 2024

Problem 1

method ambiguity for Adjoint

julia> Base.mapreducedim!(identity, +, CUDA.zeros(4), CUDA.ones(4,4)')
ERROR: MethodError: mapreducedim!(::typeof(identity), ::typeof(+), ::CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, ::Adjoint{Float32, CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}}) is ambiguous.

Candidates:
  mapreducedim!(f, op, R::AnyGPUArray, A::AbstractArray)
    @ GPUArrays ~/.julia/packages/GPUArrays/Hd5Sk/src/host/mapreduce.jl:10
  mapreducedim!(f, op::Union{typeof(&), typeof(+), typeof(Base._extrema_rf), typeof(Base.add_sum), typeof(max), typeof(min), typeof(|)}, B::AbstractArray, A::Adjoint{T, <:AbstractMatrix} where T)
    @ LinearAlgebra ~/.julia/juliaup/julia-1.10.2+0.x64.linux.gnu/share/julia/stdlib/v1.10/LinearAlgebra/src/adjtrans.jl:427

Possible fix, define
  mapreducedim!(::Any, ::Union{typeof(&), typeof(+), typeof(Base._extrema_rf), typeof(Base.add_sum), typeof(max), typeof(min), typeof(|)}, ::AnyGPUArray, ::Adjoint{T, <:AbstractMatrix} where T)

Stacktrace:
 [1] top-level scope
   @ REPL[39]:1
 [2] top-level scope
   @ ~/.julia/packages/CUDA/htRwP/src/initialization.jl:206

Problem 2

not dropping singleton dims

julia> Base.mapreducedim!(identity, +, CUDA.zeros(4), CUDA.ones(4,4,4))
4×1×1 CuArray{Float32, 3, CUDA.Mem.DeviceBuffer}:
[:, :, 1] =
 16.0
 16.0
 16.0
 16.0

julia> Base.mapreducedim!(identity, +, zeros(4), ones(4,4,4))
4-element Vector{Float64}:
 16.0
 16.0
 16.0
 16.0
@vpuri3
Copy link
Contributor Author

vpuri3 commented Mar 6, 2024

@maleadt can you recommend a fix for these problems?

For the first problem, my first thought was to implement https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra/src/adjtrans.jl#L440-L448 for AnyGPUArray but that would be hard to maintain.

@vpuri3
Copy link
Contributor Author

vpuri3 commented Mar 6, 2024

Nevertheless that seems to be the only feasible solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant