pub struct GpuKdTree { /* private fields */ }Expand description
Immutable runtime-owned KD-tree uploaded explicitly and reused across batches. Construction/partitioning is on CPU; nearest-point traversal is on GPU. No device-to-host transfer is performed by upload, and no CPU search fallback is used. Public methods validate device identity before resource use.
Implementations§
Source§impl GpuKdTree
impl GpuKdTree
Sourcepub fn nearest_k_resident(
&self,
runtime: &WgpuRuntime,
queries: &GpuQueryBatch,
k: u32,
) -> SpatialResult<GpuNeighborhoods>
pub fn nearest_k_resident( &self, runtime: &WgpuRuntime, queries: &GpuQueryBatch, k: u32, ) -> SpatialResult<GpuNeighborhoods>
Submits up to k nearest neighbors for each explicitly uploaded query. Results stay on GPU, sorted by distance with the CPU KD-tree selection and stable tie order. Supports k=0..=64; includes self/duplicate points. No payload upload/readback or host wait occurs. Unsupported sizes error before allocation. Finite targets/queries are required at upload; GPU f32 rounding/underflow may differ across backends near search boundaries.
Sourcepub fn radius_neighbors_resident(
&self,
runtime: &WgpuRuntime,
queries: &GpuQueryBatch,
radius: f32,
capacity: u32,
) -> SpatialResult<GpuNeighborhoods>
pub fn radius_neighbors_resident( &self, runtime: &WgpuRuntime, queries: &GpuQueryBatch, radius: f32, capacity: u32, ) -> SpatialResult<GpuNeighborhoods>
Submits radius search (radius is not squared) with bounded row capacity. All matches are counted on GPU; the first capacity matches are stored in CPU traversal order. Capacity=0 performs count-only search. Negative/ NaN radii produce empty rows; infinite/overflowing radius squares are unbounded. Self/duplicate points are included. No silent truncation: readback complete access rejects overflow, and device consumers must inspect total counts. Target/query payloads are reused without copies.
Source§impl GpuKdTree
impl GpuKdTree
Sourcepub fn upload(runtime: &WgpuRuntime, tree: &KdTree) -> SpatialResult<Self>
pub fn upload(runtime: &WgpuRuntime, tree: &KdTree) -> SpatialResult<Self>
Uploads a finite CPU KD-tree, preserving its leaf and tie traversal order. The borrowed tree may be dropped afterwards. Upload accounting includes 16 bytes per point and 32 per node, excluding uniform control data.
Sourcepub fn upload_with_gpu_gather(
runtime: &WgpuRuntime,
tree: &KdTree,
) -> SpatialResult<Self>
pub fn upload_with_gpu_gather( runtime: &WgpuRuntime, tree: &KdTree, ) -> SpatialResult<Self>
Explicitly uploads original SoA axes/indices and gathers point records on GPU. CPU partitioning, finite validation and node packing remain. Existing nearest-search device requirements apply; unsupported limits reject. The pass copies integer words, preserving coordinate bits and leaf/tie order. Host upload is 16N + 32M bytes; the gather records 16N device-to-device bytes. There is no download or host completion wait. Two transient inputs use 16N extra device bytes beside the owned output; there is no 16*N host point-packing vector. Submission retains inputs until completion, and later searches on this runtime follow queue ordering.
Sourcepub fn upload_and_queries_with_gpu_gather(
runtime: &WgpuRuntime,
tree: &KdTree,
) -> SpatialResult<(Self, GpuQueryBatch)>
pub fn upload_and_queries_with_gpu_gather( runtime: &WgpuRuntime, tree: &KdTree, ) -> SpatialResult<(Self, GpuQueryBatch)>
Uploads the tree and generates queries for every point in original input order, sharing the same integer gather pass and uploaded SoA axes/indices. Combined host upload is 16N + 32M bytes, compared with 32N + 32M for separate tree/query uploads. Each returned object records 16N device-to-device output bytes; queries record zero host upload bytes. CPU partitioning, finite validation and node packing remain. No readback or completion wait occurs. Both outputs are owned and reusable; the CPU tree may be dropped. Two transient inputs use 16N extra device bytes; no host point/query packing vectors are created. Device requirements match nearest search, with an additional query dispatch-size check.
Sourcepub fn upload_transfers(&self) -> TransferStats
pub fn upload_transfers(&self) -> TransferStats
Bytes transferred when this target was explicitly uploaded.
Sourcepub fn nearest_one_within_download(
&self,
runtime: &WgpuRuntime,
queries: &[[f32; 3]],
bound: f32,
) -> SpatialResult<(Vec<Option<Neighbor>>, TransferStats)>
pub fn nearest_one_within_download( &self, runtime: &WgpuRuntime, queries: &[[f32; 3]], bound: f32, ) -> SpatialResult<(Vec<Option<Neighbor>>, TransferStats)>
Explicitly uploads queries and downloads one optional nearest result per query, in input order, using an inclusive squared-distance gate. Negative/NaN gates and nonfinite queries produce None as on CPU; positive infinity is unbounded. Finite target coordinates are required at upload. GPU f32 arithmetic can differ near rounding/underflow boundaries across backends. Equal computed distances retain CPU near-first traversal ties. Accounting is 16 query bytes uploaded and 8 result bytes downloaded per query (uniform controls excluded); empty/invalid-gate calls copy no data. This synchronous API waits for completion, including the readback.