ITK  4.3.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 {
38  itkGPUKernelClassMacro(GPUReductionKernel);
39 
40 template< class TElement >
41 class ITK_EXPORT GPUReduction :
42  public Object
43 {
44 public:
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 = NULL);
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();
95  void PrintSelf(std::ostream & os, Indent indent) const;
96 
100 
101  /* GPU kernel handle for GPUComputeUpdate */
104 
105  unsigned int m_Size;
107 
108  TElement m_GPUResult, m_CPUResult;
109 
110 private:
111  GPUReduction(const Self &); //purposely not implemented
112  void operator=(const Self &); //purposely not implemented
113 
114 };
115 } // end namespace itk
116 
117 #ifndef ITK_MANUAL_INSTANTIATION
118 #include "itkGPUReduction.hxx"
119 #endif
120 
121 #endif
122