Overlap transforms with other CUDA work#

Keep two batches in flight so your application can work with other CUDA tasks while their transforms run. Each batch in this example contains one Arrow Device row: longitude 3°, latitude 0°, in XY order, transformed from EPSG:4326 to EPSG:32631.

Prepare two slots#

Before the submission loop, create the plan and prepare the transform. Give each slot its own explicit nondefault stream, workspace sized for one row, input, output and status storage, and a place to retain its execution handle.

Slot A

Slot B

Transform stream

Nondefault stream A

Nondefault stream B

Workspace

Capacity of one row

Capacity of one row

Storage

Separate input, output and status

Separate input, output and status

Execution

Retain handle A

Retain handle B

The checked native CUDA example in examples/cpp_cuda.cu shows plan creation, preparation, a capacity-sized workspace, a stream and an execution lease. If you use a DeviceResource, account for preparation’s stream wait separately from enqueue. Keep the inputs, outputs and their owners live through completion.

Submit and collect both batches#

  1. Write each input on its producer stream and record a valid producer event after the write. In this example, each transform uses a different stream from its producer, so supply the corresponding event to order the input write before the transform.

  2. Enqueue batch A on stream A. If an empty Arrow event handle causes CUGEO_PROJ_CUDA_ERROR, there is no execution to wait on: record a valid event and retry A’s submission.

  3. Enqueue batch B on stream B before waiting for A. Apply the same empty-event check and retry B’s submission with a valid event if needed.

  4. Query an execution while you have independent work, or wait when you need its result. If completion is uncertain, retain its owners and retry the wait before reading the row. After the wait completes, read the status and easting and print the batch ID, easting in metres and status. Repeat for the other slot. For each ID, check for status OK and an easting of approximately 500000 m.

  5. Release each execution when it is no longer needed. If release is uncertain, retain its owners and retry the release before reusing the slot. Keep the slot reserved while a downstream consumer still uses its result. For a Python-managed execution, retain owners through native release. Closing it requires exclusive access to the handle.