ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkGPUReduction.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 :
41  public Object
42 {
43 public:
44  ITK_DISALLOW_COPY_AND_ASSIGN(GPUReduction);
45 
47  using Self = GPUReduction;
48  using Superclass = Object;
51 
53  itkNewMacro(Self);
54 
56  itkTypeMacro(GPUReduction,
57  Object);
58 
60 
61  itkGetMacro(GPUDataManager, GPUDataPointer);
62  itkGetMacro(GPUResult, TElement);
63  itkGetMacro(CPUResult, TElement);
64 
66  itkGetOpenCLSourceFromKernelMacro(GPUReductionKernel);
67 
68  unsigned int NextPow2( unsigned int x );
69  bool isPow2(unsigned int x);
70  void GetNumBlocksAndThreads(int whichKernel, int n, int maxBlocks, int maxThreads, int &blocks, int &threads);
71  unsigned int GetReductionKernel(int whichKernel, int blockSize, int isPowOf2);
72 
73  void AllocateGPUInputBuffer(TElement *h_idata = nullptr);
74  void ReleaseGPUInputBuffer();
75  void InitializeKernel(unsigned int size);
76 
77  TElement RandomTest();
78  TElement GPUGenerateData();
79  TElement CPUGenerateData(TElement *data, int size);
80 
81  TElement GPUReduce( cl_int n,
82  int numThreads,
83  int numBlocks,
84  int maxThreads,
85  int maxBlocks,
86  int whichKernel,
87  bool cpuFinalReduction,
88  int cpuFinalThreshold,
89  double* dTotalTime,
90  GPUDataPointer idata,
91  GPUDataPointer odata);
92 
93 protected:
94  GPUReduction();
95  ~GPUReduction() override;
96  void PrintSelf(std::ostream & os, Indent indent) const override;
97 
101 
102  /* GPU kernel handle for GPUComputeUpdate */
105 
106  unsigned int m_Size;
108 
109  TElement m_GPUResult, m_CPUResult;
110 };
111 } // end namespace itk
112 
113 #ifndef ITK_MANUAL_INSTANTIATION
114 #include "itkGPUReduction.hxx"
115 #endif
116 
117 #endif
Light weight base class for most itk classes.
GPUDataPointer m_GPUDataManager
itkGPUKernelClassMacro(GPUImageOpsKernel)
GPU memory manager implemented using OpenCL. Required by GPUImage class.
GPUKernelManager::Pointer m_GPUKernelManager
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Base class for most ITK classes.
Definition: itkObject.h:60
unsigned int m_Size
SmartPointer< Self > Pointer