karu
Stateless byte-range transport
Karu is one layer of the Asterisk stack for AI
Remote reads are bound by round trips, not bytes
An example with four separate ranges. Karu keeps up to 64 remote transfers in flight by default.
Give Karu every range you know
// six tiles of one remote scenestd::array<karu::Read, 6> reads;for (int i = 0; i < 6; ++i) reads[i] = {.object = &scene, .offset = off[i], .destination = tile[i], .tag = &tile[i]}; auto batch = client.submit(reads).value(); for (;;) { auto ev = batch.next().value(); if (ev.state == karu::BatchState::end) break; // each event: tag, status, bytes_read}
Describe every read up front, each with a tag of your own.
submit queues all six and returns at once, without waiting for any bytes.
next() hands back each read as it finishes, with its tag and its own status.
Which ranges merge
Gap 1 MiB
KARU_COALESCE_GAPThe next read joins the request when the hole before it is at most 1 MiB.
Ratio 16×
KARU_COALESCE_AMPLIFICATIONThe next read joins only if the request then fetches at most 16 times the bytes asked.
You only pass each read's offset and size. Karu measures the holes and ratios itself, with its defaults.
How big one request gets
Span 64 MiB
KARU_COALESCE_LIMITA request covers at most 64 MiB, from its first byte to its last.
Parts 1024
KARU_COALESCE_PARTSA request carries at most 1024 reads, even when they touch.
Holes not to scale. Local files merge only ranges that touch, and a gap of 0 turns merging off.
One contract, seven backends
point at a backend
offset 1048576length 65536file:///data/scene.tifpositional readGDAL/data/scene.tiffd = open("/data/scene.tif", O_RDONLY | O_CLOEXEC)
pread(fd, buf, 65536, 1048576)file:// is dropped and the path percent-decoded. No HTTP.
https://example.com/scene.tifrange GETGDAL/vsicurl/https://example.com/scene.tifGET https://example.com/scene.tif
Range: bytes=1048576-1114111/vsicurl/ is dropped and the URL is sent as written.
s3://bucket/scene.tifsigned range GETGDAL/vsis3/bucket/scene.tifGET https://bucket.s3.us-east-1.amazonaws.com/scene.tif
Range: bytes=1048576-1114111
Authorization: AWS4-HMAC-SHA256 Credential=…Both spellings are one object, /vsis3/bucket/scene.tif.
gs://bucket/scene.tifsigned range GETGDAL/vsigs/bucket/scene.tifGET https://storage.googleapis.com/bucket/scene.tif
Range: bytes=1048576-1114111
Authorization: Bearer …Both spellings are one object, /vsigs/bucket/scene.tif.
az://container/scene.tifsigned range GETGDAL/vsiaz/container/scene.tifGET https://account.blob.core.windows.net/container/scene.tif
Range: bytes=1048576-1114111
Authorization: SharedKey account:…abfs:// and /vsiadls/ reach Data Lake at account.dfs.core.windows.net.
hf://datasets/org/repo/scene.tifrange GET, token if setGDAL/vsihf/datasets/org/repo/scene.tifGET https://huggingface.co/datasets/org/repo/resolve/main/scene.tif
Range: bytes=1048576-1114111Large files redirect to a CDN. Karu follows, without the token.
source://account/product/scene.tifanonymous range GETGDAL/vsisource/account/product/scene.tifGET https://data.source.coop/account/product/scene.tif
Range: bytes=1048576-1114111Path style and unsigned until Source credentials are set.
s3://bucket/archive.zip#bytes=4194304-12582911inner request, shiftedGDAL/vsisubfile/4194304_8388608,/vsis3/bucket/archive.zipGET https://bucket.s3.us-east-1.amazonaws.com/archive.zip
Range: bytes=5242880-5308415
Authorization: AWS4-HMAC-SHA256 Credential=…A window over another path. Offsets add, so the read starts 4 MiB further in.
What a streaming DataLoader needs
forks its workers
one process per worker, so no shared threads
a new engine in each worker
pid checked on every call
shuffles across files
a batch takes windows from many objects
one submit spans every object
nearby ranges merged per object
decodes on the CPU
while the GPU trains on the last batch
each window as soon as it lands
batch.next()
fills preallocated buffers
one per batch tensor, reused every step
bytes land in your buffer
no extra copy for remote ranges
runs for days
millions of requests, tokens that expire
retries, resumes, refreshes tokens
KARU_MAX_ATTEMPTS 8
reads a live dataset
files can be rewritten mid-epoch
a replaced file fails with 412
Read::if_match
Streaming means training reads its samples straight from object storage, with no local copy of the dataset.
Why not object_store?
Both merge nearby ranges, but get_ranges takes no If-Match: pinning a version means one get_opts per range.
Four I/O threads keep 64 transfers in flight
A thread waits on its 16 transfers at once and takes the next one the moment a slot frees. Reuse one client.
Karu can also download large objects
client.download(object, "scene.rumi")
One read of up to 1 MiB returns the first bytes, the size and the ETag. Each range asks for that ETag with If-Match and is written at its offset when it lands. The destination appears only after every range has landed, and an existing file is not replaced by default. A changed ETag or a cancel deletes the temporary file, so no partial destination ever appears.