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"
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
33namespace itk
34{
71// Forward declaration
72class OpenCLKernel;
73class OpenCLVectorBase;
74class OpenCLContextPimpl; // OpenCLContext private implementation idiom.
75
76class ITKOpenCL_EXPORT OpenCLContext : public LightObject
77{
78public:
79
82 typedef LightObject Superclass;
84 typedef SmartPointer< const Self > ConstPointer;
85
87 itkTypeMacro( OpenCLContext, LightObject );
88
94 static Pointer New();
95
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
135
142 bool Create( const std::list< OpenCLDevice > & devices );
143
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
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
223
227 void SetCommandQueue( const OpenCLCommandQueue & queue );
228
240
248 OpenCLCommandQueue CreateCommandQueue( const cl_command_queue_properties properties,
249 const OpenCLDevice & device = OpenCLDevice() );
250
260 const std::size_t size );
261
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
306 const OpenCLMemoryObject::Access access, const OpenCLSize & size );
307
315 void * data, const OpenCLSize & size,
316 const OpenCLMemoryObject::Access access );
317
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
393
398 void Flush();
399
403 void Finish();
404
409 cl_int Marker( const OpenCLEventList & event_list );
410
418
423 cl_int Barrier( const OpenCLEventList & event_list );
424
432
437 static cl_int WaitForFinished( const OpenCLEventList & event_list );
438
439protected:
440
444
447 ~OpenCLContext() override;
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
465private:
466
467 OpenCLContext( const Self & other ); // purposely not implemented
468 const Self & operator=( const Self & ); // purposely not implemented
469
471
472 std::unique_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 */
The OpenCLBuffer class represents an OpenCL buffer object.
The OpenCLCommandQueue class represents an OpenCL a command-queue on a specific device and valid Open...
The OpenCLContext class represents an OpenCL context.
cl_int Marker(const OpenCLEventList &event_list)
SmartPointer< const Self > ConstPointer
OpenCLImage CreateImageCopy(const OpenCLImageFormat &format, const void *data, const OpenCLSize &size, const OpenCLMemoryObject::Access access)
std::list< OpenCLDevice > GetDevices() const
cl_int GetLastError() const
OpenCLProgram CreateProgramFromBinaryCode(const unsigned char *binary, const std::vcl_size_t size)
bool Create(const OpenCLPlatform &platfrom, const OpenCLDevice::DeviceType type=OpenCLDevice::Default)
OpenCLProgram BuildProgramFromSourceFile(const std::list< OpenCLDevice > &devices, const std::string &fileName, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string(), const std::string &extraBuildOptions=std::string())
~OpenCLContext() override
OpenCLImage CreateImageDevice(const OpenCLImageFormat &format, const OpenCLMemoryObject::Access access, const OpenCLSize &size)
const Self & operator=(const Self &)
bool Create(const OpenCLContext::CreateMethod method)
LightObject Superclass
static std::string GetErrorName(const cl_int code)
OpenCLEvent BarrierAsync(const OpenCLEventList &event_list)
OpenCLCommandQueue GetCommandQueue()
OpenCLVector< T > CreateVector(const OpenCLMemoryObject::Access access, const std::vcl_size_t size)
void SetLastError(const cl_int error)
void SetContextId(cl_context id)
OpenCLProgram BuildProgramFromSourceCode(const std::string &sourceCode, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string())
OpenCLSampler CreateSampler(const bool normalizedCoordinates, const OpenCLSampler::AddressingMode addressingMode, const OpenCLSampler::FilterMode filterMode)
void SetCommandQueue(const OpenCLCommandQueue &queue)
cl_int Barrier(const OpenCLEventList &event_list)
OpenCLProgram BuildProgramFromSourceCode(const std::list< OpenCLDevice > &devices, const std::string &sourceCode, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string(), const std::string &extraBuildOptions=std::string())
OpenCLBuffer CreateBufferDevice(const OpenCLMemoryObject::Access access, const std::vcl_size_t size)
OpenCLProgram CreateProgramFromSourceFile(const std::string &filename, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string())
virtual void Release()
cl_context GetContextId() const
void SetDefaultDevice(const OpenCLDevice &device)
static Pointer GetInstance()
OpenCLProgram BuildProgramFromSourceFile(const std::string &fileName, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string())
OpenCLBuffer CreateBufferCopy(const void *data, const OpenCLMemoryObject::Access access, const std::vcl_size_t size)
OpenCLDevice GetDefaultDevice() const
OpenCLUserEvent CreateUserEvent()
OpenCLContext(const Self &other)
SmartPointer< Self > Pointer
OpenCLProgram CreateOpenCLProgram(const std::string &filename, const std::string &source, const std::vcl_size_t sourceSize)
OpenCLImage CreateImageHost(const OpenCLImageFormat &format, void *data, const OpenCLSize &size, const OpenCLMemoryObject::Access access)
static cl_int WaitForFinished(const OpenCLEventList &event_list)
OpenCLContext Self
static Pointer New()
OpenCLProgram CreateProgramFromSourceCode(const std::string &sourceCode, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string())
bool IsCreated() const
OpenCLEvent MarkerAsync(const OpenCLEventList &event_list)
OpenCLBuffer CreateBufferHost(void *data, const OpenCLMemoryObject::Access access, const std::vcl_size_t size)
bool Create(const OpenCLDevice::DeviceType type)
void ReportError(const cl_int code, const char *fileName="", const int lineNumber=0, const char *location="")
OpenCLCommandQueue CreateCommandQueue(const cl_command_queue_properties properties, const OpenCLDevice &device=OpenCLDevice())
std::list< OpenCLImageFormat > GetSupportedImageFormats(const OpenCLImageFormat::ImageType image_type, const cl_mem_flags flags) const
bool Create(const std::list< OpenCLDevice > &devices)
OpenCLCommandQueue GetDefaultCommandQueue()
static void SetInstance(OpenCLContext *instance)
void OpenCLProfile(cl_event clEvent, const std::string &message, const bool releaseEvent=false)
The OpenCLDevice class represents the collection of OpenCL devices to be used by the host.
OpenCLEventList class represents a list of OpenCLEvent objects.
OpenCLEvent class represents an OpenCL event object.
The OpenCLImageFormat class represents the format of a OpenCLImage.
The OpenCLImage class represents an image object is used to store a one, two or three dimensional tex...
The OpenCLKernel class represents an executable entry point function in an OpenCL program.
The OpenCLMemoryObject class represents all common memory objects such as buffers and image objects.
The OpenCLPlatform represent platform model for OpenCL.
The OpenCLProgram class represents an OpenCL program object.
The OpenCLSampler class represents an OpenCL sampler object.
The OpenCLSize class defines the size of an item of work for an OpenCL kernel.
Definition: itkOpenCLSize.h:50
The OpenCLUserEvent class represents OpenCL user events.
The base class for the OpenCLVector implementation.
The OpenCLVector class represents a templated OpenCL buffer object.
#define ITKOpenCL_EXPORT
#define ITK_OPENCL_DECLARE_PRIVATE(Class)


Generated on 1667476801 for elastix by doxygen 1.9.4 elastix logo