go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkOpenCLContext.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright UMC Utrecht and contributors
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 #ifndef __itkOpenCLContext_h
19 #define __itkOpenCLContext_h
20 
21 #include "itkLightObject.h"
22 #include "itkObjectFactory.h"
23 
24 #include "itkOpenCLDevice.h"
25 #include "itkOpenCLCommandQueue.h"
26 #include "itkOpenCLBuffer.h"
27 #include "itkOpenCLVector.h"
28 #include "itkOpenCLImage.h"
29 #include "itkOpenCLSampler.h"
30 #include "itkOpenCLProgram.h"
31 #include "itkOpenCLUserEvent.h"
32 
33 namespace itk
34 {
71 // Forward declaration
72 class OpenCLKernel;
73 class OpenCLVectorBase;
74 class OpenCLContextPimpl; // OpenCLContext private implementation idiom.
75 
77 {
78 public:
79 
84  typedef SmartPointer< const Self > ConstPointer;
85 
87  itkTypeMacro( OpenCLContext, LightObject );
88 
94  static Pointer New();
95 
97  static Pointer GetInstance();
98 
101  static void SetInstance( OpenCLContext * instance );
102 
106  bool IsCreated() const;
107 
116  Default = 0x0000,
117  DevelopmentSingleMaximumFlopsDevice = 0x0001,
118  DevelopmentMultipleMaximumFlopsDevices = 0x0002,
119  SingleMaximumFlopsDevice = 0x0004,
120  MultipleMaximumFlopsDevices = 0x0008
121  };
122 
134  bool Create( const OpenCLDevice::DeviceType type );
135 
142  bool Create( const std::list< OpenCLDevice > & devices );
143 
149  bool Create( const OpenCLContext::CreateMethod method );
150 
156  bool Create( const OpenCLPlatform & platfrom,
158 
169  bool Create();
170 
174  virtual void Release();
175 
178  cl_context GetContextId() const;
179 
187  void SetContextId( cl_context id );
188 
192  std::list< OpenCLDevice > GetDevices() const;
193 
198  OpenCLDevice GetDefaultDevice() const;
199 
204  cl_int GetLastError() const;
205 
208  void SetLastError( const cl_int error );
209 
213  static std::string GetErrorName( const cl_int code );
214 
216  void ReportError( const cl_int code, const char * fileName = "",
217  const int lineNumber = 0, const char * location = "" );
218 
222  OpenCLCommandQueue GetCommandQueue();
223 
227  void SetCommandQueue( const OpenCLCommandQueue & queue );
228 
239  OpenCLCommandQueue GetDefaultCommandQueue();
240 
248  OpenCLCommandQueue CreateCommandQueue( const cl_command_queue_properties properties,
249  const OpenCLDevice & device = OpenCLDevice() );
250 
259  OpenCLBuffer CreateBufferDevice( const OpenCLMemoryObject::Access access,
260  const std::size_t size );
261 
270  OpenCLBuffer CreateBufferHost( void * data,
271  const OpenCLMemoryObject::Access access, const std::size_t size );
272 
280  OpenCLBuffer CreateBufferCopy( const void * data,
281  const OpenCLMemoryObject::Access access, const std::size_t size );
282 
290  template< typename T >
292  const std::size_t size )
293  {
294  return OpenCLVector< T >( this, access, size );
295  }
296 
297 
305  OpenCLImage CreateImageDevice( const OpenCLImageFormat & format,
306  const OpenCLMemoryObject::Access access, const OpenCLSize & size );
307 
314  OpenCLImage CreateImageHost( const OpenCLImageFormat & format,
315  void * data, const OpenCLSize & size,
316  const OpenCLMemoryObject::Access access );
317 
324  OpenCLImage CreateImageCopy( const OpenCLImageFormat & format,
325  const void * data, const OpenCLSize & size,
326  const OpenCLMemoryObject::Access access );
327 
331  OpenCLProgram CreateProgramFromSourceCode( const std::string & sourceCode,
332  const std::string & prefixSourceCode = std::string(),
333  const std::string & postfixSourceCode = std::string() );
334 
338  OpenCLProgram CreateProgramFromSourceFile( const std::string & filename,
339  const std::string & prefixSourceCode = std::string(),
340  const std::string & postfixSourceCode = std::string() );
341 
346  OpenCLProgram CreateProgramFromBinaryCode( const unsigned char * binary,
347  const std::size_t size );
348 
353  OpenCLProgram BuildProgramFromSourceCode( const std::string & sourceCode,
354  const std::string & prefixSourceCode = std::string(),
355  const std::string & postfixSourceCode = std::string() );
356 
357  OpenCLProgram BuildProgramFromSourceCode( const std::list< OpenCLDevice > & devices,
358  const std::string & sourceCode,
359  const std::string & prefixSourceCode = std::string(),
360  const std::string & postfixSourceCode = std::string(),
361  const std::string & extraBuildOptions = std::string() );
362 
367  OpenCLProgram BuildProgramFromSourceFile( const std::string & fileName,
368  const std::string & prefixSourceCode = std::string(),
369  const std::string & postfixSourceCode = std::string() );
370 
371  OpenCLProgram BuildProgramFromSourceFile( const std::list< OpenCLDevice > & devices,
372  const std::string & fileName,
373  const std::string & prefixSourceCode = std::string(),
374  const std::string & postfixSourceCode = std::string(),
375  const std::string & extraBuildOptions = std::string() );
376 
379  std::list< OpenCLImageFormat > GetSupportedImageFormats(
380  const OpenCLImageFormat::ImageType image_type, const cl_mem_flags flags ) const;
381 
384  OpenCLSampler CreateSampler( const bool normalizedCoordinates,
385  const OpenCLSampler::AddressingMode addressingMode,
386  const OpenCLSampler::FilterMode filterMode );
387 
392  OpenCLUserEvent CreateUserEvent();
393 
398  void Flush();
399 
403  void Finish();
404 
409  cl_int Marker( const OpenCLEventList & event_list );
410 
417  OpenCLEvent MarkerAsync( const OpenCLEventList & event_list );
418 
423  cl_int Barrier( const OpenCLEventList & event_list );
424 
431  OpenCLEvent BarrierAsync( const OpenCLEventList & event_list );
432 
437  static cl_int WaitForFinished( const OpenCLEventList & event_list );
438 
439 protected:
440 
443  OpenCLContext();
444 
447  virtual ~OpenCLContext();
448 
451  void OpenCLProfile( cl_event clEvent, const std::string & message,
452  const bool releaseEvent = false );
453 
457  void SetDefaultDevice( const OpenCLDevice & device );
458 
461  OpenCLProgram CreateOpenCLProgram( const std::string & filename,
462  const std::string & source,
463  const std::size_t sourceSize );
464 
465 private:
466 
467  OpenCLContext( const Self & other ); // purposely not implemented
468  const Self & operator=( const Self & ); // purposely not implemented
469 
471 
472  std::auto_ptr< OpenCLContextPimpl > d_ptr;
473  static Pointer m_Instance;
474 
476  cl_command_queue GetActiveQueue();
477 
480  void CreateContext( const std::list< OpenCLDevice > & devices,
481  OpenCLContextPimpl * d );
482 
485  void CreateContext( const OpenCLPlatform & platfrom,
486  const OpenCLDevice::DeviceType type,
487  OpenCLContextPimpl * d );
488 
491  void SetUpProfiling();
492 
495  void OpenCLDebug( const std::string & callname );
496 
498  friend class OpenCLMemoryObject;
499  friend class OpenCLBuffer;
500  friend class OpenCLImage;
501  friend class OpenCLKernel;
502  friend class OpenCLCommandQueue;
503  friend class OpenCLProgram;
504  friend class OpenCLVectorBase;
505  friend class OpenCLSampler;
506 };
507 
508 } // end namespace itk
509 
510 #endif /* __itkOpenCLContext_h */
LightObject Superclass
The OpenCLImage class represents an image object is used to store a one, two or three dimensional tex...
OpenCLEventList class represents a list of OpenCLEvent objects.
The OpenCLSize class defines the size of an item of work for an OpenCL kernel.
Definition: itkOpenCLSize.h:49
The OpenCLImageFormat class represents the format of a OpenCLImage.
The OpenCLBuffer class represents an OpenCL buffer object.
The base class for the OpenCLVector implementation.
The OpenCLUserEvent class represents OpenCL user events.
The OpenCLCommandQueue class represents an OpenCL a command-queue on a specific device and valid Open...
The OpenCLContext class represents an OpenCL context.
OpenCLContext Self
#define ITK_OPENCL_DECLARE_PRIVATE(Class)
The OpenCLPlatform represent platform model for OpenCL.
OpenCLVector< T > CreateVector(const OpenCLMemoryObject::Access access, const std::vcl_size_t size)
The OpenCLSampler class represents an OpenCL sampler object.
The OpenCLDevice class represents the collection of OpenCL devices to be used by the host...
SmartPointer< const Self > ConstPointer
The OpenCLKernel class represents an executable entry point function in an OpenCL program...
SmartPointer< Self > Pointer
The OpenCLMemoryObject class represents all common memory objects such as buffers and image objects...
#define ITKOpenCL_EXPORT
The OpenCLVector class represents a templated OpenCL buffer object.
The OpenCLProgram class represents an OpenCL program object.
OpenCLEvent class represents an OpenCL event object.


Generated on 04-09-2015 for elastix by doxygen 1.8.9.1 elastix logo