Share device geometry with another CUDA component#
Choose a handoff for the receiving component.
SDK consumer. Borrow geometry storage, row states, or a typed result view under a device lease. The lease retains the owner and its context while the consumer reads.
Arrow consumer. Call
cugeo_geometry_cuda_geometry_export_arrow_deviceto produce a schema and device array. A blocking export returns ready with a nullsync_event. A stream-ordered WKB export supplies an array-owned readiness event. Wait for it and check for a zero failure word before reading. The array retains the exported storage and context. Finish all consumer reads before calling the array release callback, and call the schema release callback separately.Incoming Arrow device geometry. Identify the producer’s CUDA context and event dependency. A null event declares producer writes complete. The array must name the SDK context’s device, and its buffers must be in mapped, non-managed allocations of that context. For the Point layout, the admitted spans include the x and y coordinate buffers and an optional validity bitmap. See the import descriptor in backends/cuda/include/cugeo/geometry/cuda/cuda_interop/geometry_import.h for the layouts and spans.
For a blocking import, keep the producer’s schema, array, event, and immutable buffers alive until the call returns. The SDK copies the data and does not release the producer’s Arrow objects. For a stream-ordered import, the structures and event may be released after the call returns, but the buffer owner must survive until the import work completes on the supplied stream.
Borrow storage#
Use the device input, execution, and cleanup in backends/cuda/examples/direct_device.cu as the candidate setup. It creates producer and consumer streams, imports point and region columns, and executes a predicate. Add the handoff before releasing the point geometry.
Call
cugeo_geometry_cuda_context_cuda_identityand check that the returned context and device match the consumer’s context and device.Initialize a
cugeo_geometry_cuda_cuda_geometry_descand callcugeo_geometry_cuda_geometry_borrow_storage_devicewith the point geometry and consumer stream. Check the status and retain the returned lease. The view describes the geometry’s row count and device spans.Enqueue a small device consumer on that same stream to read the point row slots and count them, including NULL and EMPTY slots. The borrow establishes readiness on the supplied stream. Keep the stream and lease alive through the dependent work.
After the consumer runs, copy its count scalar to the host and wait for the copy. Print that count beside the producer’s point row count, seven. Equality is the expected check. Trace the counter type and copy size in your adaptation so the scalar’s exact host transfer is clear. The geometry spans remain on the device.
Release the handoff#
After the last dependent read has been enqueued on the consumer stream, release the lease with cugeo_geometry_cuda_device_lease_release while that stream is still valid. A successful release waits for those reads and invalidates the view. A failed release leaves the lease live for retry. Keep allocator callback state alive until the final child retaining the context has been released.
For another view or export, check which owner must survive and which release call belongs to the view.