ITK  5.2.0
Insight Toolkit
itkGPUReduction.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkGPUReduction_h
19 #define itkGPUReduction_h
20 
21 #include "itkObject.h"
22 #include "itkGPUDataManager.h"
23 #include "itkGPUKernelManager.h"
24 #include "itkOpenCLUtil.h"
25 
26 namespace itk
27 {
29 itkGPUKernelClassMacro(GPUReductionKernel);
30 
39 template <typename TElement>
40 class ITK_TEMPLATE_EXPORT GPUReduction : public Object
41 {
42 public:
43  ITK_DISALLOW_COPY_AND_MOVE(GPUReduction);
44 
46  using Self = GPUReduction;
47  using Superclass = Object;
50 
52  itkNewMacro(Self);
53 
55  itkTypeMacro(GPUReduction, Object);
56 
58 
59  itkGetMacro(GPUDataManager, GPUDataPointer);
60  itkGetMacro(GPUResult, TElement);
61  itkGetMacro(CPUResult, TElement);
62 
64  itkGetOpenCLSourceFromKernelMacro(GPUReductionKernel);
65 
66  unsigned int
67  NextPow2(unsigned int x);
68  bool
69  isPow2(unsigned int x);
70  void
71  GetNumBlocksAndThreads(int whichKernel, int n, int maxBlocks, int maxThreads, int & blocks, int & threads);
72  unsigned int
73  GetReductionKernel(int whichKernel, int blockSize, int isPowOf2);
74 
75  void
76  AllocateGPUInputBuffer(TElement * h_idata = nullptr);
77  void
78  ReleaseGPUInputBuffer();
79  void
80  InitializeKernel(unsigned int size);
81 
82  TElement
83  RandomTest();
84  TElement
85  GPUGenerateData();
86  TElement
87  CPUGenerateData(TElement * data, int size);
88 
89  TElement
90  GPUReduce(cl_int n,
91  int numThreads,
92  int numBlocks,
93  int maxThreads,
94  int maxBlocks,
95  int whichKernel,
96  bool cpuFinalReduction,
97  int cpuFinalThreshold,
98  double * dTotalTime,
99  GPUDataPointer idata,
100  GPUDataPointer odata);
101 
102 protected:
103  GPUReduction();
104  ~GPUReduction() override;
105  void
106  PrintSelf(std::ostream & os, Indent indent) const override;
107 
111 
112  /* GPU kernel handle for GPUComputeUpdate */
115 
116  unsigned int m_Size;
118 
119  TElement m_GPUResult, m_CPUResult;
120 };
121 } // end namespace itk
122 
123 #ifndef ITK_MANUAL_INSTANTIATION
124 # include "itkGPUReduction.hxx"
125 #endif
126 
127 #endif
itk::GPUReduction::m_GPUDataManager
GPUDataPointer m_GPUDataManager
Definition: itkGPUReduction.h:110
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itkGPUKernelManager.h
itk::GPUReduction::m_GPUResult
TElement m_GPUResult
Definition: itkGPUReduction.h:119
itkOpenCLUtil.h
itk::GPUReduction::m_Size
unsigned int m_Size
Definition: itkGPUReduction.h:116
itk::GPUReduction::m_SmallBlock
bool m_SmallBlock
Definition: itkGPUReduction.h:117
itk::GPUDataManager
GPU memory manager implemented using OpenCL. Required by GPUImage class.
Definition: itkGPUDataManager.h:42
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::GPUReduction::m_GPUKernelManager
GPUKernelManager::Pointer m_GPUKernelManager
Definition: itkGPUReduction.h:109
itk::GPUReduction::m_ReduceGPUKernelHandle
int m_ReduceGPUKernelHandle
Definition: itkGPUReduction.h:113
itk::GPUDataManager::Pointer
SmartPointer< Self > Pointer
Definition: itkGPUDataManager.h:52
itk::GPUReduction
Definition: itkGPUReduction.h:40
itkObject.h
itk::itkGPUKernelClassMacro
itkGPUKernelClassMacro(GPUImageOpsKernel)
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itkGPUDataManager.h
itk::GPUReduction::m_TestGPUKernelHandle
int m_TestGPUKernelHandle
Definition: itkGPUReduction.h:114