-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Support negative strides in BLAS.gemv!
#41513
Conversation
Do all BLAS implementations handle this correctly? |
I tested it with OpenBLAS and MKL (via MKL.jl) on 64-bit Linux, both handle it correctly (at least for the test cases in this PR). |
@dkarrasch Does this look good? I like the tests and wondering if we can merge. |
This broke the case where the output length happened to be zero: julia> BLAS.gemv!('N', 1.0, zeros(0, 10), rand(10), 1., zeros(0))
Float64[] # before
ERROR: `stride(A,2)` must be at least `max(1, size(A,1))` # now Was that unsafe (e.g. could cause some memory corruption or the like) to do before? Or is the check too strict, i.e. would |
Ah, well, with LBT enabling simple switching of the used BLAS library, it's probably better not to expect anything from it not stated in the specs. Still, it's a bit unfortunate this potentially causes breakage. Alternatively, is it safe to set |
I would guess so (I would be surprised if any elements of |
If I read the specs correctly, the condition is that |
@martinholters if this is an MKL bug (or something they should handle better), even while we need to address as discussed here, let's also file as a separate issue here and I can report to Intel. |
There is no bug in MKL AFAICT. Prior to this change, one could have |
Setting However, in the case julia> BLAS.gemv!('N', 1.0, zeros(5,0), zeros(0), 2.0, ones(5)) # non-empty output vector should be scaled by 2
5-element Vector{Float64}:
1.0
1.0
1.0
1.0
1.0
Here, |
Yes, that's also something I had noticed a while ago and wondered whether the old Fortran code (which also does this) or its accompanying documentation were to be regarded as the reference... |
#42012 fixes the case where |
I just noticed that we actually don’t have to error for negative if stride(A,2) < 0
A = @view A[:, end:-1:begin]
x = @view x[end:-1:begin]
end Would that be fine? For better performance, one could also calculate the resulting pointer and stride without creating the |
This was made an error in JuliaLang/julia#41513. Obviously, the `gemv!` call can just be omitted if the output is empty anyway.
This was made an error in JuliaLang/julia#41513. Obviously, the `gemv!` call can just be omitted if the output is empty anyway.
* Support negative strides in `BLAS.gemv!` * Preserve X and Y during ccall
* Support negative strides in `BLAS.gemv!` * Preserve X and Y during ccall
* Support negative strides in `BLAS.gemv!` * Preserve X and Y during ccall (cherry picked from commit 29c9ea0)
* Support negative strides in `BLAS.gemv!` * Preserve X and Y during ccall (cherry picked from commit 29c9ea0)
* Support negative strides in `BLAS.gemv!` * Preserve X and Y during ccall (cherry picked from commit 29c9ea0)
Fixes #30765.
This calculates the correct pointers for the BLAS call in the case of vectors with negative stride. I also added an error if
stride(A,2)
doesn’t meet the requirements.I can also go through the other BLAS functions to see if some of them need to be fixed as well, but I wanted to get feedback on this PR first.