Open3D (C++ API)  0.20.0
Loading...
Searching...
No Matches
VoxelizeOpKernel.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2026 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7//
8#pragma once
9
11#include "torch/script.h"
12
13template <class T>
14void VoxelizeCPU(const torch::Tensor& points,
15 const torch::Tensor& row_splits,
16 const torch::Tensor& voxel_size,
17 const torch::Tensor& points_range_min,
18 const torch::Tensor& points_range_max,
19 const int64_t max_points_per_voxel,
20 const int64_t max_voxels,
21 torch::Tensor& voxel_coords,
22 torch::Tensor& voxel_point_indices,
23 torch::Tensor& voxel_point_row_splits,
24 torch::Tensor& voxel_batch_splits);
25
26#ifdef BUILD_CUDA_MODULE
27template <class T>
28void VoxelizeCUDA(const torch::Tensor& points,
29 const torch::Tensor& row_splits,
30 const torch::Tensor& voxel_size,
31 const torch::Tensor& points_range_min,
32 const torch::Tensor& points_range_max,
33 const int64_t max_points_per_voxel,
34 const int64_t max_voxels,
35 torch::Tensor& voxel_coords,
36 torch::Tensor& voxel_point_indices,
37 torch::Tensor& voxel_point_row_splits,
38 torch::Tensor& voxel_batch_splits);
39#endif
40
41#ifdef BUILD_SYCL_MODULE
42template <class T>
43void VoxelizeSYCLDispatch(const torch::Tensor& points,
44 const torch::Tensor& row_splits,
45 const torch::Tensor& voxel_size,
46 const torch::Tensor& points_range_min,
47 const torch::Tensor& points_range_max,
48 const int64_t max_points_per_voxel,
49 const int64_t max_voxels,
50 torch::Tensor& voxel_coords,
51 torch::Tensor& voxel_point_indices,
52 torch::Tensor& voxel_point_row_splits,
53 torch::Tensor& voxel_batch_splits);
54#endif
55
57public:
58 VoxelizeOutputAllocator(torch::DeviceType device_type, int device_idx)
59 : device_type(device_type), device_idx(device_idx) {}
60
61 void AllocVoxelCoords(int32_t** ptr, int64_t rows, int64_t cols) {
62 voxel_coords = torch::empty({rows, cols},
63 torch::dtype(ToTorchDtype<int32_t>())
64 .device(device_type, device_idx));
65 *ptr = voxel_coords.data_ptr<int32_t>();
66 }
67
68 void AllocVoxelPointIndices(int64_t** ptr, int64_t num) {
69 voxel_point_indices =
70 torch::empty({num}, torch::dtype(ToTorchDtype<int64_t>())
71 .device(device_type, device_idx));
72 *ptr = voxel_point_indices.data_ptr<int64_t>();
73 }
74
75 void AllocVoxelPointRowSplits(int64_t** ptr, int64_t num) {
76 voxel_point_row_splits =
77 torch::empty({num}, torch::dtype(ToTorchDtype<int64_t>())
78 .device(device_type, device_idx));
79 *ptr = voxel_point_row_splits.data_ptr<int64_t>();
80 }
81
82 void AllocVoxelBatchSplits(int64_t** ptr, int64_t num) {
83 voxel_batch_splits =
84 torch::empty({num}, torch::dtype(ToTorchDtype<int64_t>())
85 .device(device_type, device_idx));
86 *ptr = voxel_batch_splits.data_ptr<int64_t>();
87 }
88
89 const torch::Tensor& VoxelCoords() const { return voxel_coords; }
90 const torch::Tensor& VoxelPointIndices() const {
91 return voxel_point_indices;
92 }
93 const torch::Tensor& VoxelPointRowSplits() const {
94 return voxel_point_row_splits;
95 }
96 const torch::Tensor& VoxelBatchSplits() const { return voxel_batch_splits; }
97
98private:
99 torch::Tensor voxel_coords;
100 torch::Tensor voxel_point_indices;
101 torch::Tensor voxel_point_row_splits;
102 torch::Tensor voxel_batch_splits;
103 torch::DeviceType device_type;
104 int device_idx;
105};
TorchDtype_t ToTorchDtype< int64_t >()
Definition TorchHelper.h:82
TorchDtype_t ToTorchDtype< int32_t >()
Definition TorchHelper.h:78
void VoxelizeSYCLDispatch(const torch::Tensor &points, const torch::Tensor &row_splits, const torch::Tensor &voxel_size, const torch::Tensor &points_range_min, const torch::Tensor &points_range_max, const int64_t max_points_per_voxel, const int64_t max_voxels, torch::Tensor &voxel_coords, torch::Tensor &voxel_point_indices, torch::Tensor &voxel_point_row_splits, torch::Tensor &voxel_batch_splits)
Definition VoxelizeOpKernelSYCL.cpp:19
Definition VoxelizeOpKernel.h:56
const torch::Tensor & VoxelPointIndices() const
Definition VoxelizeOpKernel.h:90
void AllocVoxelPointRowSplits(int64_t **ptr, int64_t num)
Definition VoxelizeOpKernel.h:75
void AllocVoxelBatchSplits(int64_t **ptr, int64_t num)
Definition VoxelizeOpKernel.h:82
void AllocVoxelCoords(int32_t **ptr, int64_t rows, int64_t cols)
Definition VoxelizeOpKernel.h:61
const torch::Tensor & VoxelPointRowSplits() const
Definition VoxelizeOpKernel.h:93
const torch::Tensor & VoxelBatchSplits() const
Definition VoxelizeOpKernel.h:96
void AllocVoxelPointIndices(int64_t **ptr, int64_t num)
Definition VoxelizeOpKernel.h:68
const torch::Tensor & VoxelCoords() const
Definition VoxelizeOpKernel.h:89
VoxelizeOutputAllocator(torch::DeviceType device_type, int device_idx)
Definition VoxelizeOpKernel.h:58
int points
Definition FilePCD.cpp:55
void VoxelizeCPU(const torch::Tensor &points, const torch::Tensor &row_splits, const torch::Tensor &voxel_size, const torch::Tensor &points_range_min, const torch::Tensor &points_range_max, const int64_t max_points_per_voxel, const int64_t max_voxels, torch::Tensor &voxel_coords, torch::Tensor &voxel_point_indices, torch::Tensor &voxel_point_row_splits, torch::Tensor &voxel_batch_splits)
Definition VoxelizeOpKernel.cpp:18