ITK  5.2.0
Insight Toolkit
itkGPUDataManager.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  * 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 #ifndef itkGPUDataManager_h
20 #define itkGPUDataManager_h
21 
22 #include "itkObject.h"
23 #include "itkDataObject.h"
24 #include "itkObjectFactory.h"
25 #include "itkOpenCLUtil.h"
26 #include "itkGPUContextManager.h"
27 #include <mutex>
28 
29 namespace itk
30 {
42 class GPUDataManager : public Object // DataObject//
43 {
45  friend class GPUKernelManager;
46 
47 public:
48  ITK_DISALLOW_COPY_AND_MOVE(GPUDataManager);
49 
51  using Superclass = Object;
54 
55  itkNewMacro(Self);
56  itkTypeMacro(GPUDataManager, Object);
57 
58  using MutexHolderType = std::lock_guard<std::mutex>;
59 
61  void
62  SetBufferSize(unsigned int num);
63 
64  unsigned int
65  GetBufferSize() const
66  {
67  return m_BufferSize;
68  }
69 
70  void
71  SetBufferFlag(cl_mem_flags flags);
72 
73  void
74  SetCPUBufferPointer(void * ptr);
75 
76  void
77  SetCPUDirtyFlag(bool isDirty);
78 
79  void
80  SetGPUDirtyFlag(bool isDirty);
81 
84  void
86 
89  void
91 
92  bool
94  {
95  return m_IsCPUBufferDirty;
96  }
97 
98  bool
100  {
101  return m_IsGPUBufferDirty;
102  }
103 
105  virtual void
106  UpdateCPUBuffer();
107 
109  virtual void
110  UpdateGPUBuffer();
111 
112  void
113  Allocate();
114 
115  void
116  SetCurrentCommandQueue(int queueid);
117 
118  int
119  GetCurrentCommandQueueID() const;
120 
122  bool
123  Update();
124 
126  virtual void
127  Graft(const GPUDataManager * data);
128 
130  virtual void
131  Initialize();
132 
134  cl_mem *
136 
138  void *
140 
141 protected:
142  GPUDataManager();
143  ~GPUDataManager() override;
144  void
145  PrintSelf(std::ostream & os, Indent indent) const override;
146 
147 protected:
148  /* NOTE: ivars are protected instead of private to improve performance access in child classes*/
149 
150  unsigned int m_BufferSize; // # of bytes
151 
153 
155 
157  cl_mem_flags m_MemFlags;
158 
160  cl_mem m_GPUBuffer;
161  void * m_CPUBuffer;
162 
166 
168  std::mutex m_Mutex;
169 };
170 
171 } // namespace itk
172 
173 #endif
itk::GPUDataManager::Graft
virtual void Graft(const GPUDataManager *data)
itkObjectFactory.h
itk::GPUDataManager::SetBufferSize
void SetBufferSize(unsigned int num)
itk::GPUDataManager::UpdateCPUBuffer
virtual void UpdateCPUBuffer()
itk::GPUDataManager::m_ContextManager
GPUContextManager * m_ContextManager
Definition: itkGPUDataManager.h:152
itk::GPUDataManager::Initialize
virtual void Initialize()
itk::GPUDataManager::UpdateGPUBuffer
virtual void UpdateGPUBuffer()
itk::GPUDataManager::GetGPUBufferPointer
cl_mem * GetGPUBufferPointer()
itk::GPUDataManager::SetBufferFlag
void SetBufferFlag(cl_mem_flags flags)
itk::GPUDataManager::m_IsGPUBufferDirty
bool m_IsGPUBufferDirty
Definition: itkGPUDataManager.h:164
itk::GPUDataManager::SetCPUDirtyFlag
void SetCPUDirtyFlag(bool isDirty)
itk::GPUDataManager::IsGPUBufferDirty
bool IsGPUBufferDirty() const
Definition: itkGPUDataManager.h:99
itk::GPUDataManager::GPUDataManager
GPUDataManager()
itk::GPUDataManager::SetCPUBufferPointer
void SetCPUBufferPointer(void *ptr)
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itkDataObject.h
itk::GPUDataManager::m_CommandQueueId
int m_CommandQueueId
Definition: itkGPUDataManager.h:154
itk::GPUDataManager::GetCPUBufferPointer
void * GetCPUBufferPointer()
itkOpenCLUtil.h
itk::GPUDataManager::Update
bool Update()
itk::GPUDataManager::Allocate
void Allocate()
itk::GPUDataManager
GPU memory manager implemented using OpenCL. Required by GPUImage class.
Definition: itkGPUDataManager.h:42
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::GPUDataManager::m_BufferSize
unsigned int m_BufferSize
Definition: itkGPUDataManager.h:150
itk::GPUDataManager::m_MemFlags
cl_mem_flags m_MemFlags
Definition: itkGPUDataManager.h:157
itk::GPUDataManager::m_GPUBuffer
cl_mem m_GPUBuffer
Definition: itkGPUDataManager.h:160
itk::GPUDataManager::SetCPUBufferDirty
void SetCPUBufferDirty()
itk::GPUDataManager::SetGPUDirtyFlag
void SetGPUDirtyFlag(bool isDirty)
itk::GPUDataManager::m_IsCPUBufferDirty
bool m_IsCPUBufferDirty
Definition: itkGPUDataManager.h:165
itk::GPUDataManager::MutexHolderType
std::lock_guard< std::mutex > MutexHolderType
Definition: itkGPUDataManager.h:58
itk::GPUContextManager
Singleton class to store the GPU context.
Definition: itkGPUContextManager.h:34
itk::GPUDataManager::SetGPUBufferDirty
void SetGPUBufferDirty()
itk::GPUDataManager::m_Mutex
std::mutex m_Mutex
Definition: itkGPUDataManager.h:168
itkObject.h
itk::GPUKernelManager
GPU kernel manager implemented using OpenCL.
Definition: itkGPUKernelManager.h:44
itk::GPUDataManager::GetCurrentCommandQueueID
int GetCurrentCommandQueueID() const
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::GPUDataManager::GetBufferSize
unsigned int GetBufferSize() const
Definition: itkGPUDataManager.h:65
itk::GPUDataManager::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::GPUDataManager::~GPUDataManager
~GPUDataManager() override
itk::GPUDataManager::SetCurrentCommandQueue
void SetCurrentCommandQueue(int queueid)
itkGPUContextManager.h
itk::Object::Object
Object()
itk::GPUDataManager::IsCPUBufferDirty
bool IsCPUBufferDirty() const
Definition: itkGPUDataManager.h:93
itk::GPUDataManager::m_CPUBuffer
void * m_CPUBuffer
Definition: itkGPUDataManager.h:161