ITK  6.0.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 * 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
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"
27#include <mutex>
28
29namespace itk
30{
42class GPUDataManager : public Object // DataObject//
43{
45 friend class GPUKernelManager;
46
47public:
48 ITK_DISALLOW_COPY_AND_MOVE(GPUDataManager);
49
54
55 itkNewMacro(Self);
56 itkOverrideGetNameOfClassMacro(GPUDataManager);
57
58 using MutexHolderType = std::lock_guard<std::mutex>;
59
61 void
62 SetBufferSize(unsigned int num);
63
64 unsigned int
66 {
67 return m_BufferSize;
68 }
69
70 void
71 SetBufferFlag(cl_mem_flags flags);
72
73 void
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
107
109 virtual void
111
112 void
114
115 void
117
118 int
120
122 bool
124
126 virtual void
127 Graft(const GPUDataManager * data);
128
130 virtual void
132
134 cl_mem *
136
138 void *
140
141protected:
143 ~GPUDataManager() override;
144 void
145 PrintSelf(std::ostream & os, Indent indent) const override;
146
147protected:
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
Singleton class to store the GPU context.
GPU memory manager implemented using OpenCL. Required by GPUImage class.
void SetBufferSize(unsigned int num)
void SetCPUBufferPointer(void *ptr)
unsigned int GetBufferSize() const
bool IsCPUBufferDirty() const
bool IsGPUBufferDirty() const
int GetCurrentCommandQueueID() const
virtual void UpdateGPUBuffer()
virtual void Initialize()
void * GetCPUBufferPointer()
void SetCurrentCommandQueue(int queueid)
void PrintSelf(std::ostream &os, Indent indent) const override
virtual void Graft(const GPUDataManager *data)
cl_mem * GetGPUBufferPointer()
void SetCPUDirtyFlag(bool isDirty)
virtual void UpdateCPUBuffer()
void SetBufferFlag(cl_mem_flags flags)
void SetGPUDirtyFlag(bool isDirty)
GPUContextManager * m_ContextManager
~GPUDataManager() override
std::lock_guard< std::mutex > MutexHolderType
GPU kernel manager implemented using OpenCL.
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....