ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
UnaryEW.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 <Logging.h>
11 
13 
14 namespace cloudViewer {
15 namespace core {
16 namespace kernel {
17 
18 enum class UnaryEWOpCode {
19  Sqrt,
20  Sin,
21  Cos,
22  Neg,
23  Exp,
24  Abs,
25  IsNan,
26  IsInf,
27  IsFinite,
28  Floor,
29  Ceil,
30  Round,
31  Trunc,
33 };
34 
35 void UnaryEW(const Tensor& src, Tensor& dst, UnaryEWOpCode op_code);
36 void UnaryEWCPU(const Tensor& src, Tensor& dst, UnaryEWOpCode op_code);
37 
38 #ifdef BUILD_SYCL_MODULE
39 void UnaryEWSYCL(const Tensor& src, Tensor& dst, UnaryEWOpCode op_code);
40 #endif
41 
42 #ifdef BUILD_CUDA_MODULE
43 void UnaryEWCUDA(const Tensor& src, Tensor& dst, UnaryEWOpCode op_code);
44 #endif
45 
46 // Copy is separated from other unary ops since it supports cross-device copy
47 // and dtype casting.
48 void Copy(const Tensor& src, Tensor& dst);
49 
50 void CopyCPU(const Tensor& src, Tensor& dst);
51 
52 #ifdef BUILD_CUDA_MODULE
53 void CopyCUDA(const Tensor& src, Tensor& dst);
54 #endif
55 
56 #ifdef BUILD_SYCL_MODULE
57 void CopySYCL(const Tensor& src, Tensor& dst);
58 #endif
59 
60 } // namespace kernel
61 } // namespace core
62 } // 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
ShapeUtil.h
Indexer.h
cloudViewer::core::Tensor::Sqrt
Tensor Sqrt() const
Element-wise square root of a tensor, returns a new tensor.
Definition: Tensor.cpp:1296
CUDAUtils.h
Common CUDA utilities.
cloudViewer::core::kernel::UnaryEWOpCode::Ceil
@ Ceil
cloudViewer::core::make_pair
CLOUDVIEWER_HOST_DEVICE Pair< First, Second > make_pair(const First &_first, const Second &_second)
Definition: SlabTraits.h:49
cloudViewer::core::kernel::UnaryEWOpCode::IsFinite
@ IsFinite
cloudViewer::core::Tensor::GetShape
SizeVector GetShape() const
Definition: Tensor.h:1127
cloudViewer::core::kernel::CPUAllReductionKernel
static uint8_t CPUAllReductionKernel(uint8_t a, uint8_t b)
Definition: ReductionCPU.cpp:42
cloudViewer::core::Tensor::Ceil
Tensor Ceil() const
Element-wise ceil value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1417
cloudViewer::core::MakeOperation
static std::function< Tensor(const Tensor &, const Tensor &)> MakeOperation(BinaryOpCode op)
Definition: BinaryEW.cpp:38
cloudViewer::core::kernel::UnaryEWOpCode
UnaryEWOpCode
Definition: UnaryEW.h:18
offset
int offset
Definition: FileIOFactory.cpp:135
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::kernel::UnaryEWSYCL
void UnaryEWSYCL(const Tensor &src, Tensor &dst, UnaryEWOpCode op_code)
Definition: UnaryEWSYCL.cpp:199
ENUM_BM_TENSOR
#define ENUM_BM_TENSOR(FN, OP)
Definition: UnaryEW.cpp:153
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::kernel::CPUArgReductionEngine
Definition: ReductionCPU.cpp:182
cloudViewer::core::kernel::UnaryEWOpCode::Sin
@ Sin
cloudViewer::core::kernel::CPUReductionEngine
Definition: ReductionCPU.cpp:70
cloudViewer::core::UnaryOpCode::IsFinite
@ IsFinite
cloudViewer::core::kernel::CPUReductionEngine::CPUReductionEngine
CPUReductionEngine(const CPUReductionEngine &)=delete
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::CPUArgReductionEngine::LaunchArgReductionKernelTwoPass
static void LaunchArgReductionKernelTwoPass(const Indexer &indexer, func_t reduce_func, scalar_t identity)
Definition: ReductionCPU.cpp:232
cloudViewer::core::Tensor::LogicalNot
Tensor LogicalNot() const
Definition: Tensor.cpp:1442
cloudViewer::core::kernel::CPUArgMaxReductionKernel
static std::pair< int64_t, scalar_t > CPUArgMaxReductionKernel(int64_t a_idx, scalar_t a, int64_t b_idx, scalar_t b)
Definition: ReductionCPU.cpp:61
cloudViewer::core::kernel::CPUArgReductionEngine::Run
void Run(const func_t &reduce_func, scalar_t identity)
Definition: ReductionCPU.cpp:189
cloudViewer::core::Dtype
Definition: Dtype.h:21
cloudViewer::core::kernel::UnaryEWOpCode::Exp
@ Exp
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
cloudViewer::core::UnaryOpCode::LogicalNot
@ LogicalNot
cloudViewer::core::UnaryOpCode::IsInf
@ IsInf
cloudViewer::core::sy::SYCLDevice::queue
sycl::queue queue
Default queue for this device.
Definition: SYCLContext.h:32
cloudViewer::core::Device::IsCUDA
bool IsCUDA() const
Returns true iff device type is CUDA.
Definition: Device.h:49
cloudViewer::core::kernel::CopyCPU
void CopyCPU(const Tensor &src, Tensor &dst)
Definition: UnaryEWCPU.cpp:174
Parallel.h
cloudViewer::core::kernel::Copy
void Copy(const Tensor &src, Tensor &dst)
Definition: UnaryEW.cpp:66
cloudViewer::core::kernel::CPUProdReductionKernel
static scalar_t CPUProdReductionKernel(scalar_t a, scalar_t b)
Definition: ReductionCPU.cpp:28
size
int size
Definition: FileIOFactory.cpp:130
cloudViewer::core::kernel::UnaryEWOpCode::Floor
@ Floor
ParallelFor.h
cloudViewer::core::kernel::UnaryEWOpCode::Round
@ Round
Logging.h
cloudViewer::core::UnaryOpCode::Floor
@ Floor
cloudViewer::core::kernel::ReductionOpCode
ReductionOpCode
Definition: Reduction.h:22
cloudViewer::core::UnaryOpCode::Round
@ Round
cloudViewer::core::Device::IsSYCL
bool IsSYCL() const
Returns true iff device type is SYCL GPU.
Definition: Device.h:52
cloudViewer::core::UnaryOpCode::Cos
@ Cos
cloudViewer::utility::EstimateMaxThreads
int EstimateMaxThreads()
Estimate the maximum number of threads to be used in a parallel region.
Definition: Parallel.cpp:31
UnaryEW.h
e
const double * e
Definition: essential_matrix_poly.h:10
cloudViewer::core::Indexer::NumOutputElements
int64_t NumOutputElements() const
Returns the number of output elements.
Definition: Indexer.cpp:414
cloudViewer::core::DtypePolicy::ALL_SAME
@ ALL_SAME
cloudViewer::core::kernel::CPUReductionEngine::operator=
CPUReductionEngine & operator=(const CPUReductionEngine &)=delete
ENUM_BM_TENSOR_FLOAT
#define ENUM_BM_TENSOR_FLOAT(FN, OP)
Definition: UnaryEW.cpp:161
Dispatch.h
cloudViewer::core::Device
Definition: Device.h:18
cloudViewer::core::Tensor::IsNan
Tensor IsNan() const
Definition: Tensor.cpp:1362
cloudViewer::core::Tensor::Exp
Tensor Exp() const
Element-wise exponential of a tensor, returning a new tensor.
Definition: Tensor.cpp:1340
cloudViewer::core::UnaryEW
void UnaryEW(benchmark::State &state, int size, UnaryOpCode op_code, const Dtype &dtype, const Device &device)
Definition: UnaryEW.cpp:89
core
cloudViewer::core::Bool
const Dtype Bool
Definition: Dtype.cpp:52
cloudViewer::core::Dtype::ToString
std::string ToString() const
Definition: Dtype.h:65
cloudViewer::core::UnaryOpCode::Abs
@ Abs
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::Float64
const Dtype Float64
Definition: Dtype.cpp:43
cloudViewer::core::DtypePolicy::INPUT_SAME
@ INPUT_SAME
a
a[190]
Definition: essential_matrix_poly.h:19
cloudViewer::core::Tensor::GetDevice
Device GetDevice() const override
Definition: Tensor.cpp:1435
cloudViewer::core::kernel::CPUArgReductionEngine::CPUArgReductionEngine
CPUArgReductionEngine(const CPUArgReductionEngine &)=delete
cloudViewer::core::kernel::CPUArgReductionEngine::CPUArgReductionEngine
CPUArgReductionEngine(const Indexer &indexer)
Definition: ReductionCPU.cpp:186
cloudViewer::core::kernel::UnaryEWOpCode::LogicalNot
@ LogicalNot
cloudViewer::core::Float32
const Dtype Float32
Definition: Dtype.cpp:42
cloudViewer::core::sy::SYCLContext::GetDeviceProperties
SYCLDevice GetDeviceProperties(const Device &device)
Get SYCL device properties given an CloudViewer device.
Definition: SYCLContext.h:62
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
indexer
Indexer indexer
Definition: BinaryEWSYCL.cpp:30
cloudViewer::core::kernel::UnaryEWCPU
void UnaryEWCPU(const Tensor &src, Tensor &dst, UnaryEWOpCode op_code)
Definition: UnaryEWCPU.cpp:217
cloudViewer::core::kernel::UnaryEWOpCode::Abs
@ Abs
cloudViewer::benchmarks::Rand
core::Tensor Rand(const core::SizeVector &shape, size_t seed, const std::pair< core::Scalar, core::Scalar > &range, core::Dtype dtype, const core::Device &device)
Returns a Tensor with random values within the range range .
Definition: Rand.cpp:23
LogError
#define LogError(...)
Definition: Logging.h:60
cloudViewer::core::kernel::CPUMinReductionKernel
static scalar_t CPUMinReductionKernel(scalar_t a, scalar_t b)
Definition: ReductionCPU.cpp:33
DISPATCH_DTYPE_TO_TEMPLATE
#define DISPATCH_DTYPE_TO_TEMPLATE(DTYPE,...)
Definition: Dispatch.h:31
cloudViewer::core::Indexer::GetOutputPtr
CLOUDVIEWER_HOST_DEVICE char * GetOutputPtr(int64_t workload_idx) const
Definition: Indexer.h:438
cloudViewer::core::kernel::CPUSumReductionKernel
static scalar_t CPUSumReductionKernel(scalar_t a, scalar_t b)
Definition: ReductionCPU.cpp:23
cloudViewer::core::sy::SYCLContext::GetInstance
static SYCLContext & GetInstance()
Get singleton instance.
Definition: SYCLContext.cpp:25
cloudViewer::core::shape_util::CanBeBrocastedToShape
bool CanBeBrocastedToShape(const SizeVector &src_shape, const SizeVector &dst_shape)
Returns true if src_shape can be brocasted to dst_shape.
Definition: ShapeUtil.cpp:90
cloudViewer::core::Indexer::GetInputPtr
CLOUDVIEWER_HOST_DEVICE char * GetInputPtr(int64_t input_idx, int64_t workload_idx) const
Definition: Indexer.h:406
cloudViewer::core::Device::IsCPU
bool IsCPU() const
Returns true iff device type is CPU.
Definition: Device.h:46
cloudViewer::core::kernel::UnaryEWOpCode::Sqrt
@ Sqrt
cloudViewer::core::Tensor::Round
Tensor Round() const
Element-wise round value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1423
std
Definition: Eigen.h:85
cloudViewer::core::UnaryOpCode
UnaryOpCode
Definition: UnaryEW.cpp:23
cloudViewer::core::kernel::UnaryEWOpCode::Neg
@ Neg
Rand.h
cloudViewer::core::Tensor::Sin
Tensor Sin() const
Element-wise sine of a tensor, returning a new tensor.
Definition: Tensor.cpp:1307
Tensor.h
cloudViewer::core::UnaryOpCode::Trunc
@ Trunc
cloudViewer::core::kernel::UnaryEWOpCode::Trunc
@ Trunc
cloudViewer::core::Tensor::IsFinite
Tensor IsFinite() const
Definition: Tensor.cpp:1382
cloudViewer::core::UnaryOpCode::IsNan
@ IsNan
cloudViewer::core::UnaryOpCode::Ceil
@ Ceil
cloudViewer::core::kernel::CPUMaxReductionKernel
static scalar_t CPUMaxReductionKernel(scalar_t a, scalar_t b)
Definition: ReductionCPU.cpp:38
cloudViewer::core::UnaryOpCode::Neg
@ Neg
ENUM_BM_TENSOR_WTIH_BOOL
#define ENUM_BM_TENSOR_WTIH_BOOL(FN, OP)
Definition: UnaryEW.cpp:170
cloudViewer::core::Indexer::NumWorkloads
int64_t NumWorkloads() const
Definition: Indexer.cpp:406
cloudViewer::core::UnaryOpCode::Sin
@ Sin
cloudViewer::core::Tensor::Trunc
Tensor Trunc() const
Element-wise trunc value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1429
cloudViewer::core::Tensor::Abs
Tensor Abs() const
Element-wise absolute value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1351
cloudViewer::core::kernel::UnaryEWOpCode::Cos
@ Cos
cloudViewer::core::kernel::CopySYCL
void CopySYCL(const Tensor &src, Tensor &dst)
Definition: UnaryEWSYCL.cpp:131
cloudViewer::core::Tensor::Cos
Tensor Cos() const
Element-wise cosine of a tensor, returning a new tensor.
Definition: Tensor.cpp:1318
cloudViewer::core::cuda::Synchronize
void Synchronize()
Definition: CUDAUtils.cpp:59
cloudViewer::core::UnaryOpCode::Sqrt
@ Sqrt
Reduction.h
cloudViewer::core::Indexer
Definition: Indexer.h:262
cloudViewer::core::kernel::UnaryEW
void UnaryEW(const Tensor &src, Tensor &dst, UnaryEWOpCode op_code)
Definition: UnaryEW.cpp:19
cloudViewer::core::Int64
const Dtype Int64
Definition: Dtype.cpp:47
cloudViewer::core::kernel::CPUArgReductionEngine::LaunchArgReductionParallelDim
static void LaunchArgReductionParallelDim(const Indexer &indexer, func_t reduce_func, scalar_t identity)
Definition: ReductionCPU.cpp:203
cloudViewer::core::Tensor::Neg
Tensor Neg() const
Element-wise negation of a tensor, returning a new tensor.
Definition: Tensor.cpp:1329
cloudViewer::core::kernel::CPUReductionEngine::Run
void Run(const func_t &reduce_func, scalar_t identity)
Definition: ReductionCPU.cpp:77
cloudViewer::core::kernel::UnaryEWOpCode::IsNan
@ IsNan
cloudViewer::core::kernel::CPUArgReductionEngine::operator=
CPUArgReductionEngine & operator=(const CPUArgReductionEngine &)=delete
cloudViewer::utility::InParallel
bool InParallel()
Returns true if in an parallel section.
Definition: Parallel.cpp:48
cloudViewer::core::kernel::CPUReductionEngine::CPUReductionEngine
CPUReductionEngine(const Indexer &indexer)
Definition: ReductionCPU.cpp:74
cloudViewer::core::Tensor::IsInf
Tensor IsInf() const
Definition: Tensor.cpp:1372
cloudViewer::core::UnaryOpCode::Exp
@ Exp
cloudViewer::core::kernel::CPUArgMinReductionKernel
static std::pair< int64_t, scalar_t > CPUArgMinReductionKernel(int64_t a_idx, scalar_t a, int64_t b_idx, scalar_t b)
Definition: ReductionCPU.cpp:51
cloudViewer::core::Tensor::Floor
Tensor Floor() const
Element-wise floor value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1411
cloudViewer::core::kernel::CPUAnyReductionKernel
static uint8_t CPUAnyReductionKernel(uint8_t a, uint8_t b)
Definition: ReductionCPU.cpp:46
cloudViewer::core::kernel::UnaryEWOpCode::IsInf
@ IsInf