Skip to content

Shim new streaming backend - #212

Open
nclack wants to merge 115 commits into
acquire-project:mainfrom
nclack:shim
Open

nclack wants to merge 115 commits into
acquire-project:mainfrom
nclack:shim

Conversation

@nclack

@nclack nclack commented Mar 31, 2026

Copy link
Copy Markdown
Member

chucky is a new streaming backend for acquire.

It adds support for gpu acceleration and there are some improvements to cpu-based streaming as well.

Getting it in is going to take a few steps.

I'm starting with this PR by creating a "shim". The shim is a thin layer implementing the public c api of acquire using chucky. I will use that to gradually walk through acquire-zarr's tests, changing chucky as necessary.

This should allow us to make some standalone libraries/wheels we can test for a bit and identify when to switch the back-ends more permanently.

@nclack

nclack commented Apr 6, 2026

Copy link
Copy Markdown
Member Author

Added almost all functionality. I'm trying very hard to maintain existing acquire-zarr behavior. One thing that will have to change is some of the downsampling behavior.

acquire-zarr treats x and y in a special way, where chucky does not. This impacts some rules determining when to stop downsampling certain dimensions as we get to higher (coarser) levels of detail (lod).

If the user doesn't want to allow the aspect of ratios of dimensions to change, then we must stop downsampling as soon as any dimension becomes too small; "Too small" means it's one chuck or fewer in that dimension.

If aspect ratios can change, then we just stop downsampling dimensions that are too small and continue with the others until there are no dimensions left - everything fits in one chunk.

This is almost what acquire-zarr does. The aspect ratio of x and y are held fixed, but the others can change. Chunk sizes also vary.

In chucky, variable chunk size causes all kinds of headaches - so I'll constrain to a constant chunk size. I'll add an option letting a user select whether they want a variable aspect ratio or not. I've already got a max lod parameter. The lod's will be computed until any/all dimensions are 1 or fewer chunks wide or the max lod is hit.

@nclack
nclack marked this pull request as draft April 21, 2026 03:35
@nclack
nclack marked this pull request as ready for review May 10, 2026 00:40

@aliddell aliddell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Couple of things need looking at.

Comment thread .github/workflows/test.yml
assert np.array_equal(array, data)


@pytest.mark.timeout(300)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

not when things are working :D I vote for keeping it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lol fair enough

Comment thread python/tests/test_stream.py
Comment thread .gitmodules Outdated
Comment thread .gitignore
.idea
.vscode
.vs
.claude

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

.claude is already on line 87

Comment thread shim/shim_log.c Outdated
Comment thread shim/README.md
Comment thread shim/plan.md

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is going to get out of date very quickly (if it isn't already) and it probably won't be relevant after merge. Consider deleting this file and moving the contents to the PR description instead.

Comment thread shim/shim.c
const char* metadata_key,
const char* metadata)
{
if (!stream || !metadata_key || !metadata) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rejecting NULL-valued metadata_key is a behavior change. It should be accepted if and only if we have just the one array.

Comment thread shim/shim_settings.c
const ZarrArraySettings* as = &settings->arrays[index];
if (!as->output_key) {
*key = NULL;
return ZarrStatusCode_Success;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems wrong to return Success with a NULL-valued *key.

On closer inspection, the original code dedupes and regularizes the keys, so the behavior is changed here.

nclack and others added 5 commits May 14, 2026 15:53
Co-authored-by: Alan Liddell <alan.c.liddell@gmail.com>
Co-authored-by: Alan Liddell <alan.c.liddell@gmail.com>
Co-authored-by: Alan Liddell <alan.c.liddell@gmail.com>
Rename the CPU shim distribution from `acquire-zarr-cpu` to `acquire-zarr`
so it satisfies downstream `acquire-zarr>=...` requirements (e.g.
ome-writers[acquire-zarr]) as a transparent drop-in replacement for the
baseline package, without consumers having to edit their dependency name.
The GPU variant stays `acquire-zarr-gpu`.

Used to build the cp313 / linux_x86_64 wheel trialed in
czbiohub-sf/livescreen-acquisition#169.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Mirror the CPU rename (3692f4c): rename the GPU shim distribution from
`acquire-zarr-gpu` to `acquire-zarr` so the GPU wheel is a transparent drop-in
for downstream `acquire-zarr>=...` requirements (e.g. ome-writers[acquire-zarr]),
matching the CPU wheel.

Both shim/python and shim/python-gpu now build dist `acquire-zarr`; they're
published/consumed as separate wheels (CPU vs GPU), never on the same index.

Used to build the cp313 / sm_120 GPU wheel trialed in
czbiohub-sf/livescreen-acquisition#169.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@nclack

nclack commented May 29, 2026

Copy link
Copy Markdown
Member Author

Packaging note: chucky drop-in wheels (shim/python, shim/python-gpu)

The two shim Python packages now both declare distribution name acquire-zarr (was acquire-zarr-cpu / acquire-zarr-gpu):

  • shim/python → acquire-zarr (CPU) — commit 3692f4c
  • shim/python-gpu → acquire-zarr (GPU) — commit a2a6470

Why: this makes the chucky wheels a transparent drop-in for the baseline package, so downstream acquire-zarr>=… requirements (e.g. ome-writers[acquire-zarr]) resolve to chucky without consumers editing their dependency names. Both build dist acquire-zarr but ship as separate wheels (CPU vs GPU) — never on the same index, so there's no name collision.

Trial wheels (cp313 / linux_x86_64) published as pre-releases on the fork, built natively via a uv py3.13 venv + python -m build --no-isolation shim/python[-gpu] (self-contained):

Release Backend Deps
chucky-cpu-cp313 CPU vcpkg static (aws-c-s3/blosc/lz4/zstd/openssl)
chucky-gpu-cp313 GPU sm_120 CUDA 13.2 + nvcomp 5.2 (static); needs only libcuda.so.1 at runtime

Consumed by czbiohub-sf/livescreen-acquisition#169.

⚠️ GPU compression limitation: the GPU backend supports only zstd / uncompressed — blosc-lz4 and blosc-zstd are rejected at stream-create (shim/chucky/src/stream/config.c: "max_output_size is 0 (unsupported codec?)"). The downstream trial works around this by defaulting to zstd. Flagging in case GPU CODEC_BLOSC_* support is in scope for this PR (the CPU backend handles blosc fine).

This branch has not been deployed

No deployments
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