ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Reduction.h
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 
8 #pragma once
9 
10 #include <Helper.h>
11 #include <Logging.h>
12 
13 #include <unordered_set>
14 
17 
18 namespace cloudViewer {
19 namespace core {
20 namespace kernel {
21 
22 enum class ReductionOpCode {
23  Sum,
24  Prod,
25  Min,
26  Max,
27  ArgMin,
28  ArgMax,
29  All,
30  Any,
31 };
32 
33 static const std::unordered_set<ReductionOpCode, utility::hash_enum_class>
39 };
40 static const std::unordered_set<ReductionOpCode, utility::hash_enum_class>
44 };
45 static const std::unordered_set<ReductionOpCode, utility::hash_enum_class>
49 };
50 
51 void Reduction(const Tensor& src,
52  Tensor& dst,
53  const SizeVector& dims,
54  bool keepdim,
55  ReductionOpCode op_code);
56 
57 void ReductionCPU(const Tensor& src,
58  Tensor& dst,
59  const SizeVector& dims,
60  bool keepdim,
61  ReductionOpCode op_code);
62 
63 #ifdef BUILD_SYCL_MODULE
64 void ReductionSYCL(const Tensor& src,
65  Tensor& dst,
66  const SizeVector& dims,
67  bool keepdim,
68  ReductionOpCode op_code);
69 #endif
70 
71 #ifdef BUILD_CUDA_MODULE
72 void ReductionCUDA(const Tensor& src,
73  Tensor& dst,
74  const SizeVector& dims,
75  bool keepdim,
76  ReductionOpCode op_code);
77 #endif
78 
79 } // namespace kernel
80 } // namespace core
81 } // namespace cloudViewer
cloudViewer
Generic file read and write utility for python interface.
Definition: CloudViewerConfig.cpp:12
cloudViewer::core::Tensor::GetDtype
Dtype GetDtype() const
Definition: Tensor.h:1164
cloudViewer::core::shape_util::ReductionShape
SizeVector ReductionShape(const SizeVector &src_shape, const SizeVector &dims, bool keepdim)
Returns the shape after reduction.
Definition: ShapeUtil.cpp:99
Indexer.h
CUDAUtils.h
Common CUDA utilities.
Kernel.h
cloudViewer::core::kernel::ReductionOpCode::Sum
@ Sum
AdvancedIndexing.h
cloudViewer::core::Tensor::GetShape
SizeVector GetShape() const
Definition: Tensor.h:1127
cloudViewer::core::kernel::ReductionSYCL
void ReductionSYCL(const Tensor &src, Tensor &dst, const SizeVector &dims, bool keepdim, ReductionOpCode op_code)
Definition: ReductionSYCL.cpp:211
cloudViewer::core::IsDevice::IsCUDA
bool IsCUDA() const
Definition: Device.h:99
cloudViewer::core::MAX_DIMS
static constexpr int64_t MAX_DIMS
Definition: Indexer.h:38
cloudViewer::core::Tensor::Reshape
Tensor Reshape(const SizeVector &dst_shape) const
Definition: Tensor.cpp:671
cloudViewer::core::kernel::Reduction
void Reduction(const Tensor &src, Tensor &dst, const SizeVector &dims, bool keepdim, ReductionOpCode op_code)
Definition: Reduction.cpp:16
cloudViewer::core::kernel::s_regular_reduce_ops
static const std::unordered_set< ReductionOpCode, utility::hash_enum_class > s_regular_reduce_ops
Definition: Reduction.h:34
cloudViewer::core::Tensor
Definition: Tensor.h:32
cloudViewer::core::kernel::s_arg_reduce_ops
static const std::unordered_set< ReductionOpCode, utility::hash_enum_class > s_arg_reduce_ops
Definition: Reduction.h:41
SYCLContext.h
SYCL queue manager.
cloudViewer::core::kernel::ReductionOpCode::All
@ All
cloudViewer::core::kernel::NonZeroSYCL
Tensor NonZeroSYCL(const Tensor &src)
Definition: NonZeroSYCL.cpp:22
cloudViewer::core::Device::ToString
std::string ToString() const
Returns string representation of device, e.g. "CPU:0", "CUDA:0".
Definition: Device.cpp:89
result
core::Tensor result
Definition: VtkUtils.cpp:76
Parallel.h
cloudViewer::core::Tensor::NumDims
int64_t NumDims() const
Definition: Tensor.h:1172
SizeVector.h
cloudViewer::core::kernel::ReductionOpCode
ReductionOpCode
Definition: Reduction.h:22
cloudViewer::core::Tensor::Arange
static Tensor Arange(const Scalar start, const Scalar stop, const Scalar step=1, const Dtype dtype=core::Int64, const Device &device=core::Device("CPU:0"))
Create a 1D tensor with evenly spaced values in the given interval.
Definition: Tensor.cpp:436
cloudViewer::core::SizeVector::ToString
std::string ToString() const
Definition: SizeVector.cpp:132
cloudViewer::core::kernel::ReductionOpCode::Any
@ Any
cloudViewer::core::Device
Definition: Device.h:18
cloudViewer::core::kernel::ReductionOpCode::Max
@ Max
cloudViewer::core::kernel::ReductionOpCode::Prod
@ Prod
core
cloudViewer::core::kernel::ReductionCPU
void ReductionCPU(const Tensor &src, Tensor &dst, const SizeVector &dims, bool keepdim, ReductionOpCode op_code)
Definition: ReductionCPU.cpp:278
cloudViewer::core::Tensor::GetDevice
Device GetDevice() const override
Definition: Tensor.cpp:1435
cloudViewer::core::BENCHMARK_CAPTURE
BENCHMARK_CAPTURE(BinaryEW, Add__CPU_Int8__100, 100, BinaryOpCode::Add, Int8, Device("CPU:0")) -> Unit(benchmark::kMillisecond)
DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL
#define DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL(DTYPE,...)
Definition: Dispatch.h:68
cloudViewer::core::TensorIterator
Definition: Indexer.h:222
cloudViewer::core::SizeVector
Definition: SizeVector.h:70
cloudViewer::core::kernel::s_boolean_reduce_ops
static const std::unordered_set< ReductionOpCode, utility::hash_enum_class > s_boolean_reduce_ops
Definition: Reduction.h:46
LogError
#define LogError(...)
Definition: Logging.h:60
cloudViewer::core::sy::SYCLContext::GetInstance
static SYCLContext & GetInstance()
Get singleton instance.
Definition: SYCLContext.cpp:25
cloudViewer::core::IsDevice::IsCPU
bool IsCPU() const
Definition: Device.h:95
cloudViewer::core::Tensor::NumElements
int64_t NumElements() const
Definition: Tensor.h:1170
cloudViewer::core::Reduction
void Reduction(benchmark::State &state, const Device &device)
Definition: Reduction.cpp:21
Tensor.h
cloudViewer::core::kernel::ReductionOpCode::ArgMin
@ ArgMin
cloudViewer::core::Tensor::Sum
Tensor Sum(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1240
cloudViewer::core::IsDevice::IsSYCL
bool IsSYCL() const
Definition: Device.h:103
cloudViewer::core::Tensor::AsRvalue
Tensor AsRvalue()
Definition: Tensor.h:558
CLOUDVIEWER_ASSERT
#define CLOUDVIEWER_ASSERT(...)
Definition: Macro.h:51
cloudViewer::core::kernel::NonZeroCPU
Tensor NonZeroCPU(const Tensor &src)
Definition: NonZeroCPU.cpp:20
cloudViewer::core::kernel::ReductionOpCode::ArgMax
@ ArgMax
cloudViewer::core::cuda::Synchronize
void Synchronize()
Definition: CUDAUtils.cpp:59
cloudViewer::core::sy::SYCLContext::GetDefaultQueue
sycl::queue GetDefaultQueue(const Device &device)
Get the default SYCL queue given an CloudViewer device.
Definition: SYCLContext.cpp:43
Utils::distance
static double distance(T *pot1, T *pot2)
Definition: utils.h:111
Reduction.h
cloudViewer::core::Int64
const Dtype Int64
Definition: Dtype.cpp:47
NonZero.h
MemoryManager.h
Dtype.h
cloudViewer::core::Tensor::GetDataPtr
T * GetDataPtr()
Definition: Tensor.h:1144
cloudViewer::core::kernel::ReductionOpCode::Min
@ Min