Cupy-KNN
This package provides a fast nearest neighbor index for 3D points
using a cupy implementation of a linear BVH-tree.
Installation
Since cupy can be installed in several different variants (depending on the cuda version; cupy, cupy-cuda11x, cupy-cuda12x),
cupy-knn requires the selection of an optional dependency depending on the installed cupy version:
Using pip
pip install cupy-knn[default]
pip install cupy-knn[cuda11x]
pip install cupy-knn[cuda12x]
Usage
cupy-knn provides the class LBVHIndex that wraps an array-based linear bounding volume hierarchy (LBVH) for 3D-points on the gpu accessible using cupy.
The LBVH can be created by using the following code:
from cupy_knn import LBVHIndex
lbvh = LBVHIndex(leaf_size=32,
compact=True,
shrink_to_fit=True,
sort_queries=True)
Afterwards, it is required to actually build the tree using a provided cupy-array of 3D points:
lbvh.build(self, points)
This will first sort the points array in morton order and construct and optionally compress the tree using multiple CUDA-kernels.
The LBVHIndex avoids copiing the points array if possible
to conserve space on the GPU so whenever the data in the points array changes, the index has to be rebuilt using build again.
Afterwards, the LBVHIndex can be prepared for KNN as follows:
lbvh.prepare_knn_default(k, radius=np.inf) # use radius=<float> to specifiy a maximum search radius for the neighbors
The CUDA implementation relies on the KNN-queue being present in the GPU registers avoiding excessive access to global memory. Therefore the KNN-query kernel has to be recompiled whenever the k parameter changes. After preparation the query can be executed using:
indices, distances, count = lbvh.query_knn(query_points)
Additionally, the LBVHIndex supports the injection of custom kernels to process the query results directly. This is required for radius-queries:
lbvh.prepare_radius(custom_module, "custom_radius_kernel", radius=0.5)
lbvh.prepare_knn(custom_module, "custom_knn_kernel", radius=0.5)
For KNN-queries, the K parameter must be provided to the custom module via compiler flags. These can be obtained by calling lbvh.compile_flags(k=k).
Refer to the examples directory for a more detailed example of custom kernels.
Acknowledgements
This package is inspired by the approach presented in the following paper:
@inproceedings{jakob2021optimizing,
title={Optimizing LBVH-Construction and Hierarchy-Traversal to accelerate kNN Queries on Point Clouds using the GPU},
author={Jakob, Johannes and Guthe, Michael},
booktitle={Computer Graphics Forum},
volume={40},
number={1},
pages={124--137},
year={2021},
organization={Wiley Online Library}
}
Metadata
Release files for cupy-knn 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cupy_knn-0.4.0.tar.gz | 29.1 kB | Without provenance | Details for cupy_knn-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cupy_knn-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for cupy_knn-0.4.0-py3-none-any.whl |
Total release size: 56.6 kB
Release files / cupy_knn-0.4.0.tar.gz
| Download URL | cupy_knn-0.4.0.tar.gz |
|---|---|
| Size | 29.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e440353b62b610554894a66d389fa26f20d87796e3e00d0f62d89d4efd1dbf58
|
|
BLAKE2b-256 checksum How to use checksums |
a52c007733e641c9f68fe6f0b74d1249ef19bfbb252a74ac39c6bdc9ff1d05fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|
Release files / cupy_knn-0.4.0-py3-none-any.whl
| Download URL | cupy_knn-0.4.0-py3-none-any.whl |
|---|---|
| Size | 27.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
87a4e78ee3a0e6e69c56c295c9c2810ae1802bcfa9847116b9a2a65e36675818
|
|
BLAKE2b-256 checksum How to use checksums |
4cc074c270714711071409f3bbbd0755425099a24111cc06028756dc43a27f46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|
Security for cupy-knn 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.