Prepared CUDA device reads#
The public experimental advanced device-read surface plans and submits an ordered array of source windows into caller-owned CUDA rasters. The backend policy is explicit. ABI v1 does not choose a codec automatically, split a rejected batch, allocate output, convert pixels, or fall back to host I/O.
The implemented backend is direct nvTIFF multi-region decode. Its
qualification contract accepts one classic,
little-endian, stripped, uncompressed native TIFF base image with contiguous
unsigned 16-bit, three-band samples, predictor 1, and orientation 1, and writes
each region to a tight or pitched BIP destination. All
requests enter one nvtiffDecodeCheckSupported call and one nvtiffDecode
call. nvTIFF compression/IFD combinations outside the separately recorded
qualification matrix remain unsupported.
cugeo_raster_device_read_backend includes
CUGEO_RASTER_DEVICE_READ_BACKEND_NVIMAGECODEC as reserved additive ABI growth,
and Rust exposes the corresponding policy spelling. The current planner always
rejects that choice as Unsupported: nvTIFF is the only implemented generic
device-read backend. This enum value does not expose the crate-private
nvImageCodec multi-ROI experiment.
The surface is implemented consistently as cugeo_raster::cuda::DeviceRead*,
the cugeo_raster_device_read_*_v1 C family, and
cugeo.raster.io.nvtiff.DeviceRead*. The header-only C++20 owners are isolated as
cugeo::raster::io::nvtiff::device_read_*; their generic C handles never expose an
nvTIFF library type. The bounded pool has an exact two-stream GPU
correctness/capacity/backpressure/lifetime rail, and the C/C++ ABI/lifecycle
rails are qualified. There is no automatic backend or performance guarantee, and total foreign
memory is not attributed.
Lifecycle and ownership#
Planning copies a pointer-free request specification array and retains its native
Dataset. Request identifiers must be unique; duplicate or overlapping source windows are allowed. The C++ nvTIFF factory forces that backend and writes zero for fallback and subbatch splitting.Preparation binds the plan, selected backend, current CUDA context, caller stream (including defaults), device resource, pinned-host resource, and nonblocking admission gate. Every resource must name the same context and device. Preparation retains all of them. C and Rust treat the raw stream as a caller-proven valid/living handle; C++ accepts the exact
uintptr_tand does not retain or validate its external owner. Python uses the shared stream adapter, including default streams, and retains supplied owners through completion. Bare integer/ctypes handles borrow their external lifetime. Enqueue inherits the prepared stream and exposes no override because its resources are bound.Enqueue validates the complete destination array before the support probe or decode. It rejects changed order/IDs/windows/shape/dtype/strides/extents, invalid device spans. Writable samples and forbidden input/output overlaps are caller preconditions without runtime alias validation.
An execution copies its native descriptors and ordered results. C and C++ callers keep every destination allocation alive until successful close and the caller stream alive until completion and prepared close. C++ request/result pointers are borrowed only for the enqueue or wait call; every result-capacity record, including a tail, must be initialized with its exact ABI header. Python executions retain the destination and stream objects. The lower-level Rust
NvTiffPrepared::new_resourcespath likewise clones its generic resource owners into each returnedNvTiffDecode, so dropping the prepared owner after enqueue cannot invalidate native allocator handles.queryis nonblocking.waitestablishes the device-completion boundary and updates every normalized request result. Fallible close waits and destroys native completion state; owner-context activation/current-context mismatch, wait, or destroy failure leaves the handle valid for retry. Caller-context restoration failure is terminal and aborts rather than returning under the wrong context. C++ prepared/pool/execution destructors retry that close once and terminate if cleanup still fails, rather than silently expose caller storage for reuse. Release is null-safe but is not a substitute for a successful close of live work.
One prepared source binding admits one execution at a time.
DeviceReadPreparedPool/cugeo_raster_device_read_pool configures an
exact caller-selected number of reusable slots and is consumed by the same
generic request/result/execution path. Every member supplies a unique
stream and a distinct device/pinned resource pair bound to the common
current context and device. Resources must be empty and quiescent when creating
a new pool owner. Binding another facade to the same configured owner may reuse
its warm resources. SDK state and scratch grow only after slot acquisition.
Pool selection is nonblocking explicit round-robin. The first free member is
leased through proven device completion; when all members are leased, enqueue
returns WOULD_BLOCK without entering nvTIFF. A shared MemoryAdmission gate
still decides whether the selected execution’s resource hard caps plus caller
output capacity may be live. Pool close is fallible and context-bound. An
already submitted execution remains valid after pool close because it retains
the decoder state, resources, stream contract, plan, and destinations.
For the Rust owner, decoder_count() remains the configured historical count
after successful close, is_closed() becomes true, and info() reports zero
available decoders. Its live-execution count continues to describe retained
executions until they observe completion. The C close consumes its handle, so
post-close C queries are invalid.
Explicit device-read pool construction requires EXPLICIT_ROUND_ROBIN and
an explicit member array. Scalar, prepared, batch and affine nvTIFF reads use
the same slot owner. Ordinary/default callers share eight slots per live CUDA
context using the SDK’s default allocation strategy without an imposed byte
cap. Call
cugeo.raster.io.nvtiff.configure_default_pool with finite device/pinned
resources and slots before the first default preparation or read to choose
another bound.
A resource pair binds to a one-slot pool on first resource-only preparation.
To share a larger owner, configure its slots before preparing resource-only
bindings. A device-read pool with distinct resource pairs can install its
existing owner with DeviceReadPool.configure_default() in Python,
DeviceReadPreparedPool::configure_default in Rust, or
device_read_pool::configure_default in C++. The C entry point is
cugeo_raster_device_read_pool_configure_default_v1. Default scalar, prepared
and affine reads can then borrow any of its slots, while resource-specific
bindings borrow only slots backed by their pair.
Each resource pool has one admission association while any device-read binding
or admitted execution retains it. Concurrent bindings must supply the same
MemoryAdmission object. Closing the last binding permits another admission
owner after all admitted executions observe completion. Installing admission
while an unadmitted scalar execution is pending returns WOULD_BLOCK; retry
after completion. Both single-prepared and one-member pool construction orders
bind the same one-slot policy. Resource receipts
are aggregate ledger snapshots, not per-execution attribution.
trim_default_pool retires idle SDK storage and rejects pending claims.
shutdown_default_pool stops acquisitions permanently for the live context;
retained executions still complete. Close every execution and shut down the
default before destroying its CUDA context. Busy scalar/prepared calls report
ErrorCode.WOULD_BLOCK (7); actual capacity exhaustion uses code 8.
The C++ io::nvtiff namespace exposes configure_default_pool,
trim_default_pool and shutdown_default_pool with the same ownership rules.
Bounded two-owner scheduling#
This qualifies one explicit two-owner schedule on the qualified cell; it does not select a default pool size. Two independent RTX 6000 Ada runs each used five fresh-owner cold samples, five warmups, and 30 recorded pairs of simultaneous full-image decodes. Every output matched the native TIFF oracle. Warm median pair wall time was 2.245 ms and 2.253 ms (5,108 and 5,090 MiB/s of decoded output), a 0.354% between-run difference. The timed warm boundary begins immediately before both enqueues and ends after both waits; validation copies are excluded.
The rail also repeats busy submission twice per pair, proves deterministic decoder/stream mapping and release/reacquire ordering, injects an admission failure after slot selection to prove slot recovery, closes the pool with an active execution, and uses a unit fault seam to prove partial pool-preparation cleanup.
The 1 GiB retained capacity is the sum of four configured resource hard caps, not an observed allocation. Preparation retained zero requested bytes on this lane; observed requested-byte high water was 6,045,696 device bytes and 6,044,262 pinned bytes, while the conservative admission high water was 1,085,765,836 bytes including two caller outputs. Additional nvTIFF foreign device and pinned memory remains unknown. The protocol revision preceding the canonical measurements froze a maximum 10% between-run median drift, a maximum 1.5 per-run p90/median ratio, and at least 30 warm samples per run; the runs passed all three gates. GPU clocks, power, and utilization were uncontrolled. Raw logs and the CUDA SASS/PTX inspection sidecar are checked in with the closed packet. Automatic concurrency and an inferred decoder count remain off: the narrow explicit-schedule result does not establish a safe automatic policy.
Failure and result contract#
Results remain in caller order and include request ID, request index, source
window, normalized status, optional raw backend status, and logical output
bytes. The normalized states are PENDING, SUBMITTED, COMPLETED,
CANCELLED_BEFORE_SUBMIT, UNSUPPORTED, BATCH_INCOMPATIBLE,
CAPACITY_EXHAUSTED, WOULD_BLOCK, BACKEND_REJECTED, and DECODE_FAILED.
Caller result-array elements beyond the requested count are never modified.
Python exposes the same ordered failure payload as
DeviceReadSubmissionError.results; the exception remains confined to the
advanced cugeo.raster.io.nvtiff namespace.
Host preflight or support-probe rejection occurs before decode mutation and
leaves every destination unchanged. Once a decode is submitted, nvTIFF does
not provide transactional per-region output. This includes allocator callback
rejection observed after entering backend submission. A terminal submission or
decode failure marks the complete submitted array unusable; callers must not
inspect it as a partial success. Resource capacity/tracker counter growth is
normalized as CAPACITY_EXHAUSTED, with a raw nvTIFF status retained when the
backend reports one.
Memory and timing diagnostics#
Preparation timing covers source/resource binding. Lazy decoder construction, source rebinding and submission belong to enqueue timing. Preparation-retained bytes are a historical snapshot, not current aggregate scratch usage.
Destinations are always caller-owned and are reported three ways: logical pixel bytes, the exact forward addressed spans, and caller-declared allocation capacity. Output allocation calls and conversion bytes are zero for this path. The prepared device and pinned resources report exact requested-byte counters, hard capacities, peaks, failures, live records, and pending stream-ordered frees. These are cumulative shared-resource ledgers, not per-execution attribution. Each execution freezes them during its first successful host observation of completion; that observation can include concurrent or successor work which reached the shared resource before the snapshot. Repeated receipt, wait, and explain calls on that execution then remain stable even as the shared resources serve more work. The execution retains its nonblocking admission lease through proven completion. Admission reserves the sum of both configured resource hard capacities and all caller-declared output capacities. This is an explicit conservative scheduling contract, not proof that nvTIFF exposes or stays within a total foreign-memory peak; foreign/bypass scope remains unknown unless separately observed.
Plan construction, backend preparation, and host submission are separate wall times. Host submission begins at native enqueue entry and ends after whole-array preflight, the support probe, the caller producer event, the single decode enqueue on the owned work stream, its completion event and caller-stream dependency, and execution/receipt construction. Python validates and retains its destination objects before this native boundary, so Python-side validation is excluded. Query/wait and correctness copies are excluded. CUDA-event device time and enqueue-to-wait wall time carry explicit known state.
Pool facts separately report the retained-capacity limit, the exact sum of
member resource hard capacities, and the exact sum of resource-current bytes
immediately after decoder preparation. These logical requested-byte facts do
not claim CUDA allocator metadata, driver reservations, or unknown foreign
allocations. Pool receipts identify the selected decoder index and stream;
default_selection=false is always explicit. Execution resource snapshots are
frozen after completion, so reuse of that decoder cannot mutate an earlier
receipt.
Physical storage reads, codec-internal H2D/D2H/D2D traffic, foreign device or pinned allocations, and allocator bypass counts are unknown unless directly observed. A file size is never reported as bytes read, and an unavailable quantity is never represented as a measured zero. Direct device output is not evidence of GPUDirect Storage.
Exact pool rail#
tools/test-nvtiff-pool.sh builds and runs the dedicated C++20 RAII/CUDA rail against
the vendored 1001-square UInt16 C3 TIFF. It prepares two independently bounded
decoders on two non-default streams, submits two simultaneous full-image
decodes, verifies that a third returns WOULD_BLOCK, waits and compares every
sample exactly with the native TIFF host reader, reuses a released slot, closes
the pool before the last execution, and proves that the retained execution
still completes exactly. --compile-only verifies the ABI and link surface
without requiring a visible GPU.
The public Python multi-region lifecycle/correctness matrix is integrated into the aggregate GPU runner as an explicit opt-in:
CUGEO_PROJ_LIBRARY=/absolute/path/to/libcugeo_proj.so \
CUGEO_RASTER_RUN_NVTIFF_DEVICE_READ_GPU=1 \
tools/test-gpu.sh --skip-nvimagecodec
That rail runs python_tests/test_device_read_gpu.py against the exact
target/gpu-qualification/debug/libcugeo_raster.so it built (or the corresponding
CUGEO_RASTER_GPU_TARGET_DIR path), with the source checkout supplied explicitly
through PYTHONPATH. It is a correctness rail: do not interpret its wall time
as performance evidence, and do not run performance timing while another GPU
process is active.