Match points to regions already on the GPU#
Evaluate seven point–region pairings and consume the results on a CUDA stream. The checked-in sample specifies one region target for each point, so Intersects produces one result slot per pairing.
Run the sample#
From an SDK build directory configured with the sample and tests, run the following command.
cmake --build . --target cugeo_geometry_cuda_direct_device
ctest -V -R '^sdk_direct_device$'
The runnable program is backends/cuda/examples/direct_device.cu, with its adjacent sample_data.h. After checking its results, it prints the following output.
device GeoArrow producer -> import -> Intersects -> leased consumer: seven expected results
Follow the first point into Geometry#
The sample copies its fixture inputs from host to device memory, then a producer kernel updates the first point’s x coordinate to 1. The point and polygon device arrays carry the producer’s readiness event into cugeo_geometry_cuda_geometry_import_arrow_device, so the pending producer work is accounted for at import.
The sample checks stats.h2d_bytes == 0 at both geometry imports: neither import stages geometry through host-to-device transfers. The setup copies populate the device arrays, and a final device-to-host copy makes the consumer’s output available for inspection.
Follow the borrowed result#
In the sample, the request selects CUGEO_GEOMETRY_CUDA_INTERSECTS and supplies seven targets. The excerpt borrows a device view for the consumer stream and queues the consumer kernel before releasing its lease.
auto request=cugeo::geometry::cuda::descriptor<cugeo_geometry_cuda_pairs_request>(); request.operation=CUGEO_GEOMETRY_CUDA_INTERSECTS; request.targets=data.targets; request.target_count=7;
auto job=cugeo::geometry::cuda::submit_pairs(context,points,regions,request);
points.reset(); regions.reset(); // Job retains its geometry through completion.
auto result=cugeo::geometry::cuda::wait(job); job.reset();
auto view=cugeo::geometry::cuda::descriptor<cugeo_geometry_cuda_cuda_result_view>(); cugeo_geometry_cuda_device_lease* lease=nullptr;
cugeo::geometry::cuda::check(cugeo_geometry_cuda_result_borrow_device(result.get(),reinterpret_cast<CUstream>(consumer),&view,&lease,&diagnostic),diagnostic);
uint8_t empty[14]={}; auto* output=allocations.copy(empty,14,consumer);
consume<<<1,1,0,consumer>>>(view,output); cuda_checked(cudaGetLastError());
// The lease alone owns the result while real consumer work is pending.
points.reset(); regions.reset(); result.reset(); context.reset();
cugeo::geometry::cuda::check(cugeo_geometry_cuda_device_lease_release(lease,&diagnostic),diagnostic);
The consumer kernel reads the view’s value and validity arrays on that stream. Queue dependent consumer work before releasing the lease. For what must stay alive while that work is pending, see how Geometry schedules work across a CUDA boundary.
Decode the seven slots#
The program checks these (value, validity) pairs in target order.
(1,1), (1,1), (0,1), (0,0), (0,1), (1,1), (0,0)
The first point intersects its target, and the third result is false. The fourth and seventh slots have zero validity, so the application must disregard their value bytes.