ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkGPUKernelManager.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 
19 //
20 // GPU Kernel Manager Class
21 //
22 
23 #ifndef __itkGPUKernelManager_h
24 #define __itkGPUKernelManager_h
25 
26 #include <vector>
27 #include <itkLightObject.h>
28 #include <itkObjectFactory.h>
29 #include "itkOpenCLUtil.h"
30 #include "itkGPUImage.h"
31 #include "itkGPUContextManager.h"
32 #include "itkGPUDataManager.h"
33 
34 namespace itk
35 {
45 class ITK_EXPORT GPUKernelManager : public LightObject
46 {
47 public:
48 
50  {
51  bool m_IsReady;
53  };
54 
59 
60  itkNewMacro(Self);
61  itkTypeMacro(GPUKernelManager, LightObject);
62 
63  bool LoadProgramFromFile(const char* filename, const char* cPreamble="");
64 
65  bool LoadProgramFromString(const char* cSource, const char* cPreamble="");
66 
67  int CreateKernel(const char* kernelName);
68 
69  cl_int GetKernelWorkGroupInfo(int kernelIdx,
70  cl_kernel_work_group_info paramName,void *value);
71 
72  bool SetKernelArg(int kernelIdx, cl_uint argIdx, size_t argSize, const void* argVal);
73 
74  bool SetKernelArgWithImage(int kernelIdx, cl_uint argIdx, GPUDataManager::Pointer manager);
75 
76  bool LaunchKernel(int kernelIdx, int dim, size_t *globalWorkSize, size_t *localWorkSize);
77 
78  bool LaunchKernel1D(int kernelIdx, size_t globalWorkSize, size_t localWorkSize);
79 
80  bool LaunchKernel2D(int kernelIdx,
81  size_t globalWorkSizeX, size_t globalWorkSizeY,
82  size_t localWorkSizeX, size_t localWorkSizeY );
83 
84  bool LaunchKernel3D(int kernelIdx,
85  size_t globalWorkSizeX, size_t globalWorkSizeY, size_t globalWorkSizeZ,
86  size_t localWorkSizeX, size_t localWorkSizeY, size_t localWorkSizeZ );
87 
88  void SetCurrentCommandQueue( int queueid );
89 
90  int GetCurrentCommandQueueID();
91 
92 protected:
94  virtual ~GPUKernelManager() {
95  }
96 
97  bool CheckArgumentReady(int kernelIdx);
98 
99  void ResetArguments(int kernelIdx);
100 
101 private:
102  GPUKernelManager(const Self&); //purposely not implemented
103  void operator=(const Self&);
104 
105  cl_program m_Program;
106 
109 
110  std::vector< cl_kernel > m_KernelContainer;
111  std::vector< std::vector< KernelArgumentList > > m_KernelArgumentReady;
112 };
113 }
114 
115 #endif
116