ITK  4.13.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 
46  typedef GPUReduction Self;
47  typedef Object Superclass;
50 
52  itkNewMacro(Self);
53 
55  itkTypeMacro(GPUReduction,
57 
59 
60  itkGetMacro(GPUDataManager, GPUDataPointer);
61  itkGetMacro(GPUResult, TElement);
62  itkGetMacro(CPUResult, TElement);
63 
65  itkGetOpenCLSourceFromKernelMacro(GPUReductionKernel);
66 
67  unsigned int NextPow2( unsigned int x );
68  bool isPow2(unsigned int x);
69  void GetNumBlocksAndThreads(int whichKernel, int n, int maxBlocks, int maxThreads, int &blocks, int &threads);
70  unsigned int GetReductionKernel(int whichKernel, int blockSize, int isPowOf2);
71 
72  void AllocateGPUInputBuffer(TElement *h_idata = ITK_NULLPTR);
73  void ReleaseGPUInputBuffer();
74  void InitializeKernel(unsigned int size);
75 
76  TElement RandomTest();
77  TElement GPUGenerateData();
78  TElement CPUGenerateData(TElement *data, int size);
79 
80  TElement GPUReduce( cl_int n,
81  int numThreads,
82  int numBlocks,
83  int maxThreads,
84  int maxBlocks,
85  int whichKernel,
86  bool cpuFinalReduction,
87  int cpuFinalThreshold,
88  double* dTotalTime,
89  GPUDataPointer idata,
90  GPUDataPointer odata);
91 
92 protected:
93  GPUReduction();
94  ~GPUReduction() ITK_OVERRIDE;
95  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
96 
98  GPUKernelManager::Pointer m_GPUKernelManager;
99  GPUDataPointer m_GPUDataManager;
100 
101  /* GPU kernel handle for GPUComputeUpdate */
102  int m_ReduceGPUKernelHandle;
103  int m_TestGPUKernelHandle;
104 
105  unsigned int m_Size;
106  bool m_SmallBlock;
107 
108  TElement m_GPUResult, m_CPUResult;
109 
110 private:
111  ITK_DISALLOW_COPY_AND_ASSIGN(GPUReduction);
112 
113 };
114 } // end namespace itk
115 
116 #ifndef ITK_MANUAL_INSTANTIATION
117 #include "itkGPUReduction.hxx"
118 #endif
119 
120 #endif
Light weight base class for most itk classes.
SmartPointer< Self > Pointer
GPUDataManager::Pointer GPUDataPointer
SmartPointer< const Self > ConstPointer
itkGPUKernelClassMacro(GPUImageOpsKernel)
GPU memory manager implemented using OpenCL. Required by GPUImage class.
GPU kernel manager implemented using OpenCL.
GPUReduction Self
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Base class for most ITK classes.
Definition: itkObject.h:59