Skip to content

Add options to extend compute backends - #316

Merged
meggart merged 14 commits into
mainfrom
fg/compute_backends2
Oct 15, 2026
Merged

meggart merged 14 commits into
mainfrom
fg/compute_backends2

Conversation

@meggart

@meggart meggart commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

This replaces #308 as I completely messed up the stacked PR when merging in @asinghvi17 s PRs locally.

meggart and others added 13 commits September 11, 2026 16:34
- Define `DiskArrayEngineBackend` in DiskArrays itself and add a MethodError
  hint pointing to DiskArrayEngine.jl. Drops the DiskArrayEngine dependency
  and extension, which only existed to import the type.
- `DynamicBackend` now holds a `Union{DefaultBackend,DiskArrayEngineBackend}`
  so dispatch on it is union-split into a branch instead of a dynamic
  dispatch. `set_dynamic_backend!` switches it at runtime.
- Backends unknown to DiskArrays are attached per array with
  `withbackend(array, backend)`. Entry points find the backend with
  `get_backend(array)`, which walks up `parent` until `parent(a) === a`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018ra7EAJeFE1dtekwf4Tzxh
The union-split branch costs ~nothing (measured: same time and allocations
as a hard-coded DefaultBackend), so runtime switching no longer needs a
"dynamic" preference. The preference now only selects the backend that is
active at load time, and `set_backend` also switches the running session
instead of asking for a restart.

Also force specialization on `f` in the `sum`/`prod`/.../`extrema`/`mean`
entry points. `f::Function` is only passed through there, so Julia did not
specialize on it and the inner call was a dynamic dispatch: `sum(a)` on a
2-element array goes from 142 ns / 11 allocs to 61 ns / 7 allocs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018ra7EAJeFE1dtekwf4Tzxh
- `unique` visits chunks in a different order than an Array's elements, so
  test with `issetequal` (of the `f` values for `unique(f, x)`, where the
  first representative differs) instead of `@test_broken ... ==`, which
  passed or failed depending on the random data.
- Qualify `Base.mapreducedim!`, size the output from `ndims` instead of
  assuming 3 dimensions, and start the reference from `zero(R)` instead of
  uninitialized memory.
- Only test `median(dims=2)` for ndims >= 2 and `cumsum`/`cumprod` without
  `dims` for vectors.
- `init=0.0` for float data, an Int `init` with `dims` throws in Base too.
- Compare chunked float reductions with `≈`, and do not `count` floats.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018ra7EAJeFE1dtekwf4Tzxh
…I on stacked PRs

`count`, `unique`, `extrema` and `mean` were only defined for
`DefaultBackend`, so unlike the other hooks a backend had to implement them
or they threw a MethodError. They now have a `::ComputeBackend` fallback
like `sum`, `mapreduce` etc.

CI only ran for pull requests into `main`, so stacked PRs were never tested.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018ra7EAJeFE1dtekwf4Tzxh
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018ra7EAJeFE1dtekwf4Tzxh
…erred`

On Julia 1.10 the default `sum` over chunks infers `Any`, also on `main`
and with a hard-coded `DefaultBackend`. What the backend tests should
guarantee is that the indirection through `DynamicBackend` does not change
the inferred type.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018ra7EAJeFE1dtekwf4Tzxh
@meggart
meggart marked this pull request as ready for review September 21, 2026 15:26
@felixcremer felixcremer mentioned this pull request Sep 23, 2026
This was referenced Sep 24, 2026
@asinghvi17

Copy link
Copy Markdown
Member

We spoke about scoped values on the phone last week, so I guess this needs that?

@meggart

meggart commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

@asinghvi17 There were no additional comments on this PR so far. So what about merging, and then I will have a look at your invalidation PR stack?

@meggart

meggart commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

We spoke about scoped values on the phone last week, so I guess this needs that?

It has all your commits + the withbackend logic in it. So I think we should be able to merge.

@meggart
meggart merged commit c16aed2 into main Oct 15, 2026
11 checks passed
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