ITK  4.9.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 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();
95  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
96 
100 
101  /* GPU kernel handle for GPUComputeUpdate */
104 
105  unsigned int m_Size;
107 
109 
110 private:
111  GPUReduction(const Self &) ITK_DELETE_FUNCTION;
112  void operator=(const Self &) ITK_DELETE_FUNCTION;
113 
114 };
115 } // end namespace itk
116 
117 #ifndef ITK_MANUAL_INSTANTIATION
118 #include "itkGPUReduction.hxx"
119 #endif
120 
121 #endif
Light weight base class for most itk classes.
GPUDataPointer m_GPUDataManager
TElement GPUReduce(cl_int n, int numThreads, int numBlocks, int maxThreads, int maxBlocks, int whichKernel, bool cpuFinalReduction, int cpuFinalThreshold, double *dTotalTime, GPUDataPointer idata, GPUDataPointer odata)
SmartPointer< Self > Pointer
TElement CPUGenerateData(TElement *data, int size)
unsigned int NextPow2(unsigned int x)
GPUDataManager::Pointer GPUDataPointer
itkGetOpenCLSourceFromKernelMacro(GPUReductionKernel)
SmartPointer< const Self > ConstPointer
itkGPUKernelClassMacro(GPUImageOpsKernel)
void AllocateGPUInputBuffer(TElement *h_idata=nullptr)
GPU memory manager implemented using OpenCL. Required by GPUImage class.
GPUKernelManager::Pointer m_GPUKernelManager
TElement GPUGenerateData()
void PrintSelf(std::ostream &os, Indent indent) const override
bool isPow2(unsigned int x)
void InitializeKernel(unsigned int size)
TElement RandomTest()
GPUReduction Self
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void ReleaseGPUInputBuffer()
Base class for most ITK classes.
Definition: itkObject.h:57
unsigned int m_Size
void GetNumBlocksAndThreads(int whichKernel, int n, int maxBlocks, int maxThreads, int &blocks, int &threads)
unsigned int GetReductionKernel(int whichKernel, int blockSize, int isPowOf2)