Skip to content

Define copyto! for GPU Diagonals - #829

Merged
maleadt merged 2 commits into
mainfrom
diagcopy
Oct 28, 2026
Merged

maleadt merged 2 commits into
mainfrom
diagcopy

Conversation

@christiangnrd

@christiangnrd christiangnrd commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Diagonal{T, <:AbstractGPUArray} is one of Adapt's wrapped arrays, so GPUArrays' generic copyto!(::AnyGPUArray, ::AnyGPUArray) takes precedence over LinearAlgebra's copyto! for Diagonals. Instead of copying the diagonal, it launched a kernel over all n² entries, each calling setindex!(::Diagonal, ...). cholesky(::Diagonal) gets there through cholcopy.

This adds a method that copies only the diagonal, as LinearAlgebra does:

  • cholesky of a 4096×4096 JLArray Diagonal goes from 42 ms to 0.2 ms.
  • On Julia 1.10, setindex!'s error path builds its message eagerly, which POCL can't compile. Without this, cholesky(::Diagonal) fails on JLArrays once they move to KernelAbstractions 0.10 ([JLArrays] Support KA 0.10 #826).

@christiangnrd
christiangnrd added this pull request to stack #830 October 20, 2026 14:36
@christiangnrd christiangnrd changed the title Define copyto for GPU Diagonals Define copyto! for GPU Diagonals Oct 21, 2026
The generic AnyGPUArray copyto! is more specific than LinearAlgebra's
Diagonal method, so it launched a kernel over all n^2 entries calling
setindex!(::Diagonal). On Julia 1.10 that method's error path eagerly
builds a string, which POCL/SPIR-V rejects, breaking cholesky(::Diagonal)
for JLArrays with KA 0.10.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Cover the method directly, including a conversion between element types,
rather than only through `cholesky`.
@maleadt
maleadt merged commit d88ea8e into main Oct 28, 2026
8 of 9 checks passed
@maleadt
maleadt deleted the diagcopy branch October 28, 2026 10:11
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