Skip to main content

GPU-native BVH, k-NN, MLS interpolation, and FPS primitives for PyTorch.

Project description

torchbvh

GPU-native geometry primitives for PyTorch point-cloud workflows: BVH construction, exact k-NN search, MLS interpolation, displaced-query helpers, and FPS downsampling.

Performance

k-NN at N=10k, 3D, k=8 (RTX 3500 Ada, uniform distribution):

Build + query
scipy_cKD-Tree CPU ~23 ms
torch_cluster GPU ~6.8 ms
cupy_knn GPU ~4.1 ms
torchbvh GPU ~1.4 ms

FPS at B=16, N=10k, 25% selection (RTX 3500 Ada):

Time
fpsample CPU ~833 ms
torch_fpsample h=7 (CPU, fastest setting) ~37 ms
torchbvh GPU ~21 ms

See benchmarks/third_party_algorithm_comparison.ipynb for more detailed comparisons.

Install

pip install torchbvh

torchbvh builds a PyTorch CUDA extension. Source installs require PyTorch, a compatible CUDA toolkit/NVCC, and a supported host compiler in the build environment.

Docs

Documentation can be found at torchbvh.readthedocs.io.

Quickstart

import torch
import torchbvh as tb

points = torch.randn(1024, 3, device="cuda")
bvh = tb.BVH(points)

# k-NN
idx, dists = bvh.knn(points, k=8)         # (N,8) int64, (N,8) float32

# MLS interpolation — gradients flow through features
feat = torch.randn(1024, 16, device="cuda", requires_grad=True)
out = bvh.interpolate(points, feat, k=8)  # (N, 16)

# FPS downsampling geometry
fps = tb.fps(points, target_tokens=256)
# fps.indices, fps.points, fps.nearest_anchor, fps.anchor_radius, ...

# Batched: pass (B, N, D) → returns (B, N, k)

Supports D in {2, 3}, k in {4, 8, 16}, CUDA float32 contiguous inputs.

References

torchbvh builds an implicit bounding volume hierarchy over 2-D or 3-D points. The BVH layout follows the ostensibly-implicit tree formulation of Chitalu, Dubach, and Komura, and the Python/CUDA implementation was ported from the Julia ImplicitBVH.jl implementation.

  • Floyd M. Chitalu, Christophe Dubach, and Taku Komura. "Binary Ostensibly-Implicit Trees for Fast Collision Detection." Computer Graphics Forum, 39(2), 509-521, 2020. DOI: 10.1111/cgf.13948.
  • ImplicitBVH.jl, StellaOrg. Julia implementation of the implicitly indexed BVH formulation from which the torchbvh BVH code was ported: github.com/StellaOrg/ImplicitBVH.jl.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchbvh-0.1.0.tar.gz (110.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torchbvh-0.1.0-cp313-cp313-win_amd64.whl (688.4 kB view details)

Uploaded CPython 3.13Windows x86-64

File details

Details for the file torchbvh-0.1.0.tar.gz.

File metadata

  • Download URL: torchbvh-0.1.0.tar.gz
  • Upload date:
  • Size: 110.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for torchbvh-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4e04a00aedb3b20e1fe1777d67e7d1095244326ac8b0a5c260afc7aa932f3b08
MD5 69b26b0ffca4ea1e0611b0c0d0a46f1a
BLAKE2b-256 2cb4096acd0a448453e31ce14416b53cf9ba8a23916f921f8004e6b31b18e5d8

See more details on using hashes here.

File details

Details for the file torchbvh-0.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: torchbvh-0.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 688.4 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for torchbvh-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 126d21fddb7575be9c0dcb2fd7663a88f88c021344ea1a9c282db8d4b77836f0
MD5 b4c18114daef0a37f124e5f1e4098a9c
BLAKE2b-256 f211379893be87bc7b19c09740f66d08cd103480e96e519fa0d53cce5ee49acf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page