ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkGPUDataManager.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 #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 #include <mutex>
29 
30 namespace itk
31 {
43 class GPUDataManager : public Object //DataObject//
44 {
46  friend class GPUKernelManager;
47 
48 public:
49  ITK_DISALLOW_COPY_AND_ASSIGN(GPUDataManager);
50 
52  using Superclass = Object;
55 
56  itkNewMacro(Self);
57  itkTypeMacro(GPUDataManager, Object);
58 
59  using MutexHolderType = std::lock_guard<std::mutex>;
60 
62  void SetBufferSize( unsigned int num );
63 
64  unsigned int GetBufferSize() {
65  return m_BufferSize;
66  }
67 
68  void SetBufferFlag( cl_mem_flags flags );
69 
70  void SetCPUBufferPointer( void* ptr );
71 
72  void SetCPUDirtyFlag( bool isDirty );
73 
74  void SetGPUDirtyFlag( bool isDirty );
75 
78  void SetCPUBufferDirty();
79 
82  void SetGPUBufferDirty();
83 
85  return m_IsCPUBufferDirty;
86  }
87 
89  return m_IsGPUBufferDirty;
90  }
91 
93  virtual void UpdateCPUBuffer();
94 
96  virtual void UpdateGPUBuffer();
97 
98  void Allocate();
99 
100  void SetCurrentCommandQueue( int queueid );
101 
103 
105  bool Update();
106 
108  virtual void Graft(const GPUDataManager* data);
109 
111  virtual void Initialize();
112 
114  cl_mem* GetGPUBufferPointer();
115 
117  void* GetCPUBufferPointer();
118 
119 protected:
120 
121  GPUDataManager();
122  ~GPUDataManager() override;
123  void PrintSelf(std::ostream & os, Indent indent) const override;
124 
125 protected:
126  /* NOTE: ivars are protected instead of private to improve performance access in child classes*/
127 
128  unsigned int m_BufferSize; // # of bytes
129 
131 
133 
135  cl_mem_flags m_MemFlags;
136 
138  cl_mem m_GPUBuffer;
139  void* m_CPUBuffer;
140 
144 
146  std::mutex m_Mutex;
147 };
148 
149 } // namespace itk
150 
151 #endif
void * GetCPUBufferPointer()
virtual void Graft(const GPUDataManager *data)
~GPUDataManager() override
Light weight base class for most itk classes.
std::lock_guard< std::mutex > MutexHolderType
virtual void UpdateGPUBuffer()
void SetBufferFlag(cl_mem_flags flags)
virtual void UpdateCPUBuffer()
GPU memory manager implemented using OpenCL. Required by GPUImage class.
void SetCPUDirtyFlag(bool isDirty)
int GetCurrentCommandQueueID()
void SetCurrentCommandQueue(int queueid)
GPU kernel manager implemented using OpenCL.
GPUContextManager * m_ContextManager
Singleton class to store the GPU context.
void PrintSelf(std::ostream &os, Indent indent) const override
void SetCPUBufferPointer(void *ptr)
Control indentation during Print() invocation.
Definition: itkIndent.h:49
cl_mem * GetGPUBufferPointer()
Base class for most ITK classes.
Definition: itkObject.h:60
virtual void Initialize()
void SetBufferSize(unsigned int num)
unsigned int GetBufferSize()
void SetGPUDirtyFlag(bool isDirty)