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

Write direct dispatches for axpy! & axpby! #225

Merged
merged 2 commits into from
Oct 25, 2023

Conversation

avik-pal
Copy link
Contributor

@avik-pal avik-pal commented Oct 24, 2023

MWE:

julia> y = ComponentArray(a = cu(zeros(2)), b = cu(zeros(2)))
ComponentVector{Float32, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, Tuple{Axis{(a = 1:2, b = 3:4)}}}(a = Float32[0.0, 0.0], b = Float32[0.0, 0.0])

julia> x = ComponentArray(a = cu(rand(2)), b = cu(rand(2)))
ComponentVector{Float32, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, Tuple{Axis{(a = 1:2, b = 3:4)}}}(a = Float32[0.024100939, 0.77158135], b = Float32[0.40818077, 0.44528246])

julia> axpy!(-1, y, x)  # After the patch
ComponentVector{Float32, ComponentVector{Float32, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, Tuple{Axis{(a = 1:2, b = 3:4)}}}, Tuple{Axis{(a = 1:2, b = 3:4)}}}(a = Float32[0.024100939, 0.77158135], b = Float32[0.40818077, 0.44528246])

julia> axpy!(-1, y, x)  # Before the patch for CUDA
ERROR: MethodError: no method matching axpy!(::Int64, ::Float32, ::CuPtr{Float32}, ::Int64, ::CuPtr{Float32}, ::Int64)

Closest candidates are:
  axpy!(::Integer, ::Float32, ::Union{Ptr{Float32}, AbstractArray{Float32}}, ::Integer, ::Union{Ptr{Float32}, AbstractArray{Float32}}, ::Integer)
   @ LinearAlgebra ~/.julia/juliaup/julia-1.10.0-beta3+0.x64.linux.gnu/share/julia/stdlib/v1.10/LinearAlgebra/src/blas.jl:509
  axpy!(::Integer, ::ComplexF32, ::Union{Ptr{ComplexF32}, AbstractArray{ComplexF32}}, ::Integer, ::Union{Ptr{ComplexF32}, AbstractArray{ComplexF32}}, ::Integer)
   @ LinearAlgebra ~/.julia/juliaup/julia-1.10.0-beta3+0.x64.linux.gnu/share/julia/stdlib/v1.10/LinearAlgebra/src/blas.jl:509
  axpy!(::Integer, ::ComplexF64, ::Union{Ptr{ComplexF64}, AbstractArray{ComplexF64}}, ::Integer, ::Union{Ptr{ComplexF64}, AbstractArray{ComplexF64}}, ::Integer)
   @ LinearAlgebra ~/.julia/juliaup/julia-1.10.0-beta3+0.x64.linux.gnu/share/julia/stdlib/v1.10/LinearAlgebra/src/blas.jl:509
  ...

Stacktrace:
 [1] axpy!(alpha::Int64, x::ComponentVector{…}, y::ComponentVector{…})
   @ LinearAlgebra.BLAS ~/.julia/juliaup/julia-1.10.0-beta3+0.x64.linux.gnu/share/julia/stdlib/v1.10/LinearAlgebra/src/blas.jl:522
 [2] axpy!::Int64, x::ComponentVector{Float32, CuArray{…}, Tuple{…}}, y::ComponentVector{Float32, CuArray{…}, Tuple{…}})
   @ LinearAlgebra ~/.julia/juliaup/julia-1.10.0-beta3+0.x64.linux.gnu/share/julia/stdlib/v1.10/LinearAlgebra/src/generic.jl:1510
 [3] top-level scope
   @ REPL[46]:1
Some type information was truncated. Use `show(err)` to see complete types.

I will add tests, but unfortunately without CUDA I couldn't reproduce it since JLArrays would also hit the correct BLAS routines.

@codecov-commenter
Copy link

codecov-commenter commented Oct 24, 2023

Codecov Report

Merging #225 (2730051) into main (df9bd66) will decrease coverage by 0.61%.
The diff coverage is 0.00%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@            Coverage Diff             @@
##             main     #225      +/-   ##
==========================================
- Coverage   73.24%   72.64%   -0.61%     
==========================================
  Files          23       23              
  Lines         725      731       +6     
==========================================
  Hits          531      531              
- Misses        194      200       +6     
Files Coverage Δ
src/linear_algebra.jl 78.12% <0.00%> (-18.03%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@avik-pal
Copy link
Contributor Author

@jonniedie do you want any additional change to this?

@jonniedie jonniedie merged commit 6d4ea42 into jonniedie:main Oct 25, 2023
6 checks passed
@jonniedie
Copy link
Owner

Nope, looks good. Thanks!

@vpuri3
Copy link
Contributor

vpuri3 commented Oct 25, 2023

it would be good to add methods for args (::Number, ::ComponentArray, ::Number, ::AbstractArray), and (::Number, AbstractArray, ::Number, ::ComponentArray)

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

Successfully merging this pull request may close these issues.

4 participants