"vscode:/vscode.git/clone" did not exist on "371d4e5df30dc55702ce812006e0624dbba9bbb0"
knn.cpp 1.31 KB
Newer Older
1
// Modified from https://github.com/CVMI-Lab/PAConv/tree/main/scene_seg/lib/pointops/src/knnquery_heap
2

3
#include <torch/serialize/tensor.h>
4
#include <torch/extension.h>
5
6
#include <vector>
#include <THC/THC.h>
7
8
#include <ATen/cuda/CUDAContext.h>

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
extern THCState *state;

#define CHECK_CUDA(x) TORCH_CHECK(x.is_cuda(), #x, " must be a CUDAtensor ")
#define CHECK_CONTIGUOUS(x) TORCH_CHECK(x.is_contiguous(), #x, " must be contiguous ")
#define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x)


void knn_kernel_launcher(
    int b,
    int n,
    int m,
    int nsample,
    const float *xyz,
    const float *new_xyz,
    int *idx,
    float *dist2,
25
26
27
    cudaStream_t stream
    );

28
29
30
31
32
33
34
35
36
void knn_wrapper(int b, int n, int m, int nsample, at::Tensor xyz_tensor, at::Tensor new_xyz_tensor, at::Tensor idx_tensor, at::Tensor dist2_tensor)
{
    CHECK_INPUT(new_xyz_tensor);
    CHECK_INPUT(xyz_tensor);

    const float *new_xyz = new_xyz_tensor.data_ptr<float>();
    const float *xyz = xyz_tensor.data_ptr<float>();
    int *idx = idx_tensor.data_ptr<int>();
    float *dist2 = dist2_tensor.data_ptr<float>();
37
38
39

    cudaStream_t stream = at::cuda::getCurrentCUDAStream();

40
    knn_kernel_launcher(b, n, m, nsample, xyz, new_xyz, idx, dist2, stream);
41
42
43
44
45
46
}


PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
    m.def("knn_wrapper", &knn_wrapper, "knn_wrapper");
}