ITK  6.0.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 * https://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
26namespace itk
27{
29itkGPUKernelClassMacro(GPUReductionKernel);
30
39template <typename TElement>
40class ITK_TEMPLATE_EXPORT GPUReduction : public Object
41{
42public:
43 ITK_DISALLOW_COPY_AND_MOVE(GPUReduction);
44
50
52 itkNewMacro(Self);
53
55 itkOverrideGetNameOfClassMacro(GPUReduction);
56
58
60 itkGetMacro(GPUResult, TElement);
61 itkGetMacro(CPUResult, TElement);
62
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
79 void
80 InitializeKernel(unsigned int size);
81
82 TElement
84 TElement
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
102protected:
104 ~GPUReduction() override;
105 void
106 PrintSelf(std::ostream & os, Indent indent) const override;
107
109 GPUKernelManager::Pointer m_GPUKernelManager{};
110 GPUDataPointer m_GPUDataManager{};
111
112 /* GPU kernel handle for GPUComputeUpdate */
113 int m_ReduceGPUKernelHandle{};
114 int m_TestGPUKernelHandle{};
115
116 unsigned int m_Size{};
117 bool m_SmallBlock{};
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
GPU memory manager implemented using OpenCL. Required by GPUImage class.
SmartPointer< Self > Pointer
unsigned int NextPow2(unsigned int x)
void PrintSelf(std::ostream &os, Indent indent) const override
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)
TElement CPUGenerateData(TElement *data, int size)
void ReleaseGPUInputBuffer()
unsigned int GetReductionKernel(int whichKernel, int blockSize, int isPowOf2)
~GPUReduction() override
void GetNumBlocksAndThreads(int whichKernel, int n, int maxBlocks, int maxThreads, int &blocks, int &threads)
TElement RandomTest()
bool isPow2(unsigned int x)
TElement GPUGenerateData()
void AllocateGPUInputBuffer(TElement *h_idata=nullptr)
void InitializeKernel(unsigned int size)
itkGetOpenCLSourceFromKernelMacro(GPUReductionKernel)
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Base class for most ITK classes.
Definition: itkObject.h:62
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
itkGPUKernelClassMacro(GPUImageOpsKernel)