Skip to content

Fix segfault in qr(dA) \ b#941

Merged
luraess merged 5 commits into
mainfrom
lr/ormqr
Jul 3, 2026
Merged

Fix segfault in qr(dA) \ b#941
luraess merged 5 commits into
mainfrom
lr/ormqr

Conversation

@luraess

@luraess luraess commented Jul 1, 2026

Copy link
Copy Markdown
Member

Problem

On Julia 1.10+, adjoint(Q::AbstractQ) returns LinearAlgebra.AdjointQ, not Adjoint, making the six existing lmul!/rmul! overloads on Adjoint{T,<:QRPackedQ} / Transpose{T,<:QRPackedQ} dead code. Julia 1.12 then added:

lmul!(adjQ::AdjointQ{<:Any,<:QRPackedQ{T,<:StridedMatrix}}, B::StridedVecOrMat{T})

Since ROCArray <: StridedArray, this matches GPU arrays and calls CPU OpenBLAS with a GPU pointer → segfault.

qr(dA) \ b was also broken independently: stdlib's \(Factorization, b) allocates the output with zeros(T, n) — always a CPU array — then passes it through ldiv! mixing GPU factors with CPU data → segfault.

Fix

  • Replace the six dead Adjoint/Transpose-based overloads with AdjointQ-based ones, widening B to StridedROCVecOrMat to also cover SubArray views produced by stdlib internals.
  • Add Base.:\ overloads for QR{T,<:ROCMatrix,<:ROCVector} that call ldiv!(F, copy(b)) directly, bypassing the zeros(T, n) CPU allocation.
  • Widen ormqr! / LAPACK.ormqr! to accept StridedROCVecOrMat.

Tests

  • qr(dA) \ b and qr(dA) \ B (tall matrix, vector and matrix RHS)
  • Explicit lmul!/rmul! for Q, Q', and transpose(Q) (real types)
  • ldiv!(qr(dA), dx) and ldiv!(dy, qr(dA), dx)

@luraess luraess mentioned this pull request Jul 1, 2026
@luraess luraess changed the title Fix QRPackedQ mul dispatch on Julia 1.12 Fix segfault in qr(dA) \ b Jul 1, 2026
@mfherbst

mfherbst commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Awesome, thanks @luraess !

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AMDGPU.jl Benchmarks

Details
Benchmark suite Current: 876515b Previous: 4ba6e0b Ratio
amdgpu/synchronization/context/device 600 ns 620 ns 0.97
amdgpu/synchronization/stream/blocking 250 ns 250 ns 1
amdgpu/synchronization/stream/nonblocking 340 ns 350 ns 0.97
array/accumulate/Float32/1d 84371 ns 86201 ns 0.98
array/accumulate/Float32/dims=1 263373 ns 319185 ns 0.83
array/accumulate/Float32/dims=1L 135672 ns 134892 ns 1.01
array/accumulate/Float32/dims=2 133672 ns 129962 ns 1.03
array/accumulate/Float32/dims=2L 2806689 ns 2803440 ns 1.00
array/accumulate/Int64/1d 95751 ns 97561 ns 0.98
array/accumulate/Int64/dims=1 245044 ns 243253 ns 1.01
array/accumulate/Int64/dims=1L 167512 ns 166972 ns 1.00
array/accumulate/Int64/dims=2 126312 ns 126982 ns 0.99
array/accumulate/Int64/dims=2L 2985611 ns 2991421 ns 1.00
array/broadcast 88781 ns 91982 ns 0.97
array/construct 1740 ns 1690 ns 1.03
array/copy 39211 ns 37151 ns 1.06
array/copyto!/cpu_to_gpu 182582 ns 182603 ns 1.00
array/copyto!/gpu_to_cpu 181833 ns 182843 ns 0.99
array/copyto!/gpu_to_gpu 82551 ns 61041 ns 1.35
array/iteration/findall/bool 180702 ns 179112 ns 1.01
array/iteration/findall/int 198143 ns 187843 ns 1.05
array/iteration/findfirst/bool 117522 ns 119701 ns 0.98
array/iteration/findfirst/int 115812 ns 116352 ns 1.00
array/iteration/findmin/1d 169172 ns 169822 ns 1.00
array/iteration/findmin/2d 155302 ns 155632 ns 1.00
array/iteration/logical 349604 ns 351185 ns 1.00
array/iteration/scalar 289124 ns 292104 ns 0.99
array/permutedims/2d 73961 ns 72651 ns 1.02
array/permutedims/3d 73041 ns 73951 ns 0.99
array/permutedims/4d 75891 ns 75441 ns 1.01
array/random/rand/Float32 50491 ns 54361 ns 0.93
array/random/rand/Int64 56910 ns 55600 ns 1.02
array/random/rand!/Float32 125862 ns 83711 ns 1.50
array/random/rand!/Int64 96432 ns 146362 ns 0.66
array/random/randn/Float32 90511 ns 93562 ns 0.97
array/random/randn!/Float32 123812 ns 110852 ns 1.12
array/reductions/mapreduce/Float32/1d 129542 ns 133492 ns 0.97
array/reductions/mapreduce/Float32/dims=1 94982 ns 95501 ns 0.99
array/reductions/mapreduce/Float32/dims=1L 774391 ns 774131 ns 1.00
array/reductions/mapreduce/Float32/dims=2 96771 ns 97341 ns 0.99
array/reductions/mapreduce/Float32/dims=2L 301224 ns 297434 ns 1.01
array/reductions/mapreduce/Int64/1d 133642 ns 133462 ns 1.00
array/reductions/mapreduce/Int64/dims=1 95391 ns 94862 ns 1.01
array/reductions/mapreduce/Int64/dims=1L 783531 ns 781601 ns 1.00
array/reductions/mapreduce/Int64/dims=2 96841 ns 95151 ns 1.02
array/reductions/mapreduce/Int64/dims=2L 299504 ns 298665 ns 1.00
array/reductions/reduce/Float32/1d 133552 ns 129141 ns 1.03
array/reductions/reduce/Float32/dims=1 94731 ns 95271 ns 0.99
array/reductions/reduce/Float32/dims=1L 774031 ns 772951 ns 1.00
array/reductions/reduce/Float32/dims=2 96971 ns 97282 ns 1.00
array/reductions/reduce/Float32/dims=2L 296904 ns 306574 ns 0.97
array/reductions/reduce/Int64/1d 133322 ns 133571 ns 1.00
array/reductions/reduce/Int64/dims=1 95271 ns 95052 ns 1.00
array/reductions/reduce/Int64/dims=1L 780231 ns 781570 ns 1.00
array/reductions/reduce/Int64/dims=2 96781 ns 96001 ns 1.01
array/reductions/reduce/Int64/dims=2L 297644 ns 297294 ns 1.00
array/reverse/1d 43131 ns 43120 ns 1.00
array/reverse/1dL 75091 ns 75241 ns 1.00
array/reverse/1dL_inplace 100991 ns 165292 ns 0.61
array/reverse/1d_inplace 72581 ns 111651 ns 0.65
array/reverse/2d 50971 ns 50591 ns 1.01
array/reverse/2dL 101601 ns 101221 ns 1.00
array/reverse/2dL_inplace 104521 ns 178993 ns 0.58
array/reverse/2d_inplace 82771 ns 136752 ns 0.61
array/sorting/1d 342115 ns 342394 ns 1.00
integration/byval/reference 39010 ns 39281 ns 0.99
integration/byval/slices=1 40430 ns 40281 ns 1.00
integration/byval/slices=2 129382 ns 144452 ns 0.90
integration/byval/slices=3 246053 ns 237824 ns 1.03
integration/volumerhs 5030180 ns 5035301 ns 1.00
kernel/indexing 65921 ns 58331 ns 1.13
kernel/indexing_checked 92051 ns 46671 ns 1.97
kernel/launch 1350 ns 1300 ns 1.04
kernel/rand 195823 ns 127022 ns 1.54
latency/import 1587127731 ns 1567060274 ns 1.01
latency/precompile 36233947041 ns 36346768726 ns 1.00
latency/ttfp 2156775563 ns 2138341786 ns 1.01

This comment was automatically generated by workflow using github-action-benchmark.

@luraess luraess marked this pull request as ready for review July 2, 2026 06:22
@luraess luraess merged commit 122a77d into main Jul 3, 2026
5 checks passed
@luraess luraess deleted the lr/ormqr branch July 3, 2026 06:40
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.

2 participants