Perf/shared memory prefetch#14
Open
Functionhx wants to merge 2 commits into
Open
Conversation
added 2 commits
April 27, 2026 01:36
- Add TORCH_CHECK guards for CUDA tensor, shape, dtype, and contiguity - Add CUDA_CHECK macro for cudaMalloc/Memcpy/Free error handling - Remove manual #define __CUDACC__ (set automatically by nvcc) - Improve README with prerequisites and --no-build-isolation guidance - Add pyproject.toml for build metadata - Add pytest test suite and benchmark script - Improve .gitignore
Cooperatively load box points into __shared__ memory before the KNN search loop, reducing global memory reads by ~1024x per box. Benchmark (RTX 4070 Ti Super): - 10K points: 1.46ms → 0.81ms (1.8x) - 100K points: 8.6ms → 3.2ms (2.7x) - 1M points: 68.7ms → 33.4ms (2.1x)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Optimize the
boxMeanDistkernel by cooperatively loading points into shared memory before processing each spatial box, reducing global memorybandwidth consumption by ~1024×.
Problem
In the
boxMeanDistkernel, all 1024 threads in a block read the same set of points from global memory for each box. For a box with 1024 points,each point is read 1024 times — a 1024× bandwidth waste.
Solution
Before processing each box, cooperatively load all points into
__shared__memory (12KB per block), then read from shared memory during the KNNsearch.
Benchmark (RTX 4070 Ti Super, CUDA 11.8, PyTorch 2.7.1)
Test plan