ITK  4.2.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 "itkSimpleFastMutexLock.h"
28 #include "itkMutexLockHolder.h"
29 
30 namespace itk
31 {
43 class ITK_EXPORT GPUDataManager : public Object //DataObject//
44 {
46  friend class GPUKernelManager;
47 public:
48 
50  typedef Object Superclass;
53 
54  itkNewMacro(Self);
55  itkTypeMacro(GPUDataManager, Object);
56 
58 
60  void SetBufferSize( unsigned int num );
61 
62  unsigned int GetBufferSize() {
63  return m_BufferSize;
64  }
65 
66  void SetBufferFlag( cl_mem_flags flags );
67 
68  void SetCPUBufferPointer( void* ptr );
69 
70  void SetCPUDirtyFlag( bool isDirty );
71 
72  void SetGPUDirtyFlag( bool isDirty );
73 
76  void SetCPUBufferDirty();
77 
80  void SetGPUBufferDirty();
81 
83  return m_IsCPUBufferDirty;
84  }
85 
87  return m_IsGPUBufferDirty;
88  }
89 
91  virtual void UpdateCPUBuffer();
92 
94  virtual void UpdateGPUBuffer();
95 
96  void Allocate();
97 
98  void SetCurrentCommandQueue( int queueid );
99 
100  int GetCurrentCommandQueueID();
101 
103  bool Update();
104 
106  virtual void Graft(const GPUDataManager* data);
107 
109  virtual void Initialize();
110 
112  cl_mem* GetGPUBufferPointer();
113 
115  void* GetCPUBufferPointer();
116 
117 protected:
118 
119  GPUDataManager();
120  virtual ~GPUDataManager();
121  virtual void PrintSelf(std::ostream & os, Indent indent) const;
122 private:
123 
124  GPUDataManager(const Self&); //purposely not implemented
125  void operator=(const Self&);
126 
127 protected:
128 
129  unsigned int m_BufferSize; // # of bytes
130 
132 
134 
136  cl_mem_flags m_MemFlags;
137 
139  cl_mem m_GPUBuffer;
140  void* m_CPUBuffer;
141 
145 
148 };
149 
150 } // namespace itk
151 
152 #endif
153