ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
IndexReduction.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 #include <Logging.h>
11 
12 namespace cloudViewer {
13 namespace core {
14 namespace kernel {
15 
16 void IndexAdd_(int64_t dim,
17  const Tensor& index,
18  const Tensor& src,
19  Tensor& dst) {
20  // Permute the reduction dimension to the first.
21  SizeVector permute = {};
22  for (int64_t d = 0; d <= dim; ++d) {
23  if (d == 0) {
24  permute.push_back(dim);
25  } else {
26  permute.push_back(d - 1);
27  }
28  }
29  for (int64_t d = dim + 1; d < src.NumDims(); ++d) {
30  permute.push_back(d);
31  }
32 
33  auto src_permute = src.Permute(permute);
34  auto dst_permute = dst.Permute(permute);
35 
36  if (dst.IsCPU()) {
37  IndexAddCPU_(dim, index, src_permute, dst_permute);
38  } else if (dst.IsSYCL()) {
39 #ifdef BUILD_SYCL_MODULE
40  IndexAddSYCL_(dim, index, src_permute, dst_permute);
41 #endif
42  } else if (dst.IsCUDA()) {
43 #ifdef BUILD_CUDA_MODULE
44  IndexAddCUDA_(dim, index, src_permute, dst_permute);
45 #endif
46  } else {
47  utility::LogError("IndexAdd_: Unimplemented device");
48  }
49 }
50 
51 } // namespace kernel
52 } // namespace core
53 } // namespace cloudViewer
bool IsCUDA() const
Definition: Device.h:99
bool IsCPU() const
Definition: Device.h:95
int64_t NumDims() const
Definition: Tensor.h:1172
Tensor Permute(const SizeVector &dims) const
Permute (dimension shuffle) the Tensor, returns a view.
Definition: Tensor.cpp:1028
#define LogError(...)
Definition: Logging.h:60
void IndexAdd_(int64_t dim, const Tensor &index, const Tensor &src, Tensor &dst)
void IndexAddCPU_(int64_t dim, const Tensor &index, const Tensor &src, Tensor &dst)
void IndexAddSYCL_(int64_t dim, const Tensor &index, const Tensor &src, Tensor &dst)
Generic file read and write utility for python interface.