Loading...
Searching...
No Matches
itkOpenCLContext.h
Go to the documentation of this file.
/*=========================================================================
*
* Copyright UMC Utrecht and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkOpenCLContext_h
#define itkOpenCLContext_h
#include "itkLightObject.h"
#include "itkObjectFactory.h"
#include "itkOpenCLDevice.h"
#include "itkOpenCLCommandQueue.h"
#include "itkOpenCLBuffer.h"
#include "itkOpenCLVector.h"
#include "itkOpenCLImage.h"
#include "itkOpenCLSampler.h"
#include "itkOpenCLProgram.h"
#include "itkOpenCLUserEvent.h"
namespace itk
{
// Forward declaration
class OpenCLKernel;
class OpenCLVectorBase;
class OpenCLContextPimpl; // OpenCLContext private implementation idiom.
class ITKOpenCL_EXPORT OpenCLContext : public LightObject
{
public:
using Self = OpenCLContext;
using Superclass = LightObject;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
itkTypeMacro(OpenCLContext, LightObject);
static Pointer
New();
static Pointer
GetInstance();
static void
SetInstance(OpenCLContext * instance);
bool
IsCreated() const;
enum CreateMethod
{
Default = 0x0000,
DevelopmentSingleMaximumFlopsDevice = 0x0001,
DevelopmentMultipleMaximumFlopsDevices = 0x0002,
SingleMaximumFlopsDevice = 0x0004,
MultipleMaximumFlopsDevices = 0x0008
};
bool
Create(const OpenCLDevice::DeviceType type);
bool
Create(const std::list<OpenCLDevice> & devices);
bool
Create(const OpenCLContext::CreateMethod method);
bool
Create(const OpenCLPlatform & platfrom, const OpenCLDevice::DeviceType type = OpenCLDevice::Default);
bool
Create();
virtual void
Release();
cl_context
GetContextId() const;
void
SetContextId(cl_context id);
std::list<OpenCLDevice>
GetDevices() const;
OpenCLDevice
GetDefaultDevice() const;
cl_int
GetLastError() const;
void
SetLastError(const cl_int error);
static std::string
GetErrorName(const cl_int code);
void
ReportError(const cl_int code, const char * fileName = "", const int lineNumber = 0, const char * location = "");
OpenCLCommandQueue
GetCommandQueue();
void
SetCommandQueue(const OpenCLCommandQueue & queue);
OpenCLCommandQueue
GetDefaultCommandQueue();
OpenCLCommandQueue
CreateCommandQueue(const cl_command_queue_properties properties, const OpenCLDevice & device = OpenCLDevice());
OpenCLBuffer
CreateBufferDevice(const OpenCLMemoryObject::Access access, const std::size_t size);
OpenCLBuffer
CreateBufferHost(void * data, const OpenCLMemoryObject::Access access, const std::size_t size);
OpenCLBuffer
CreateBufferCopy(const void * data, const OpenCLMemoryObject::Access access, const std::size_t size);
template <typename T>
OpenCLVector<T>
CreateVector(const OpenCLMemoryObject::Access access, const std::size_t size)
{
return OpenCLVector<T>(this, access, size);
}
OpenCLImage
CreateImageDevice(const OpenCLImageFormat & format, const OpenCLMemoryObject::Access access, const OpenCLSize & size);
OpenCLImage
CreateImageHost(const OpenCLImageFormat & format,
void * data,
const OpenCLSize & size,
const OpenCLMemoryObject::Access access);
OpenCLImage
CreateImageCopy(const OpenCLImageFormat & format,
const void * data,
const OpenCLSize & size,
const OpenCLMemoryObject::Access access);
OpenCLProgram
CreateProgramFromSourceCode(const std::string & sourceCode,
const std::string & prefixSourceCode = std::string(),
const std::string & postfixSourceCode = std::string());
OpenCLProgram
CreateProgramFromSourceFile(const std::string & filename,
const std::string & prefixSourceCode = std::string(),
const std::string & postfixSourceCode = std::string());
OpenCLProgram
CreateProgramFromBinaryCode(const unsigned char * binary, const std::size_t size);
OpenCLProgram
BuildProgramFromSourceCode(const std::string & sourceCode,
const std::string & prefixSourceCode = std::string(),
const std::string & postfixSourceCode = std::string());
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());
OpenCLProgram
BuildProgramFromSourceFile(const std::string & fileName,
const std::string & prefixSourceCode = std::string(),
const std::string & postfixSourceCode = std::string());
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());
std::list<OpenCLImageFormat>
GetSupportedImageFormats(const OpenCLImageFormat::ImageType image_type, const cl_mem_flags flags) const;
OpenCLSampler
CreateSampler(const bool normalizedCoordinates,
const OpenCLSampler::AddressingMode addressingMode,
const OpenCLSampler::FilterMode filterMode);
OpenCLUserEvent
CreateUserEvent();
void
Flush();
void
Finish();
cl_int
Marker(const OpenCLEventList & event_list);
OpenCLEvent
MarkerAsync(const OpenCLEventList & event_list);
cl_int
Barrier(const OpenCLEventList & event_list);
OpenCLEvent
BarrierAsync(const OpenCLEventList & event_list);
static cl_int
WaitForFinished(const OpenCLEventList & event_list);
protected:
OpenCLContext();
~OpenCLContext() override;
void
OpenCLProfile(cl_event clEvent, const std::string & message, const bool releaseEvent = false);
void
SetDefaultDevice(const OpenCLDevice & device);
OpenCLProgram
CreateOpenCLProgram(const std::string & filename, const std::string & source, const std::size_t sourceSize);
private:
OpenCLContext(const Self & other) = delete;
const Self &
operator=(const Self &) = delete;
ITK_OPENCL_DECLARE_PRIVATE(OpenCLContext)
std::unique_ptr<OpenCLContextPimpl> d_ptr;
static Pointer m_Instance;
cl_command_queue
GetActiveQueue();
void
CreateContext(const std::list<OpenCLDevice> & devices, OpenCLContextPimpl * d);
void
CreateContext(const OpenCLPlatform & platfrom, const OpenCLDevice::DeviceType type, OpenCLContextPimpl * d);
void
SetUpProfiling();
void
OpenCLDebug(const std::string & callname);
friend class OpenCLMemoryObject;
friend class OpenCLBuffer;
friend class OpenCLImage;
friend class OpenCLKernel;
friend class OpenCLCommandQueue;
friend class OpenCLProgram;
friend class OpenCLVectorBase;
friend class OpenCLSampler;
};
} // end namespace itk
#endif /* itkOpenCLContext_h */
itk::OpenCLContext::OpenCLContext
OpenCLContext(const Self &other)=delete
itk::OpenCLContext::Marker
cl_int Marker(const OpenCLEventList &event_list)
itk::OpenCLContext::CreateImageCopy
OpenCLImage CreateImageCopy(const OpenCLImageFormat &format, const void *data, const OpenCLSize &size, const OpenCLMemoryObject::Access access)
itk::OpenCLContext::GetDevices
std::list< OpenCLDevice > GetDevices() const
itk::OpenCLContext::GetLastError
cl_int GetLastError() const
itk::OpenCLContext::SetUpProfiling
void SetUpProfiling()
itk::OpenCLContext::CreateProgramFromBinaryCode
OpenCLProgram CreateProgramFromBinaryCode(const unsigned char *binary, const std::vcl_size_t size)
itk::OpenCLContext::d_ptr
std::unique_ptr< OpenCLContextPimpl > d_ptr
Definition itkOpenCLContext.h:509
itk::OpenCLContext::Create
bool Create(const OpenCLPlatform &platfrom, const OpenCLDevice::DeviceType type=OpenCLDevice::Default)
itk::OpenCLContext::BuildProgramFromSourceFile
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())
itk::OpenCLContext::~OpenCLContext
~OpenCLContext() override
itk::OpenCLContext::CreateImageDevice
OpenCLImage CreateImageDevice(const OpenCLImageFormat &format, const OpenCLMemoryObject::Access access, const OpenCLSize &size)
itk::OpenCLContext::Create
bool Create(const OpenCLContext::CreateMethod method)
itk::OpenCLContext::Create
bool Create()
itk::OpenCLContext::OpenCLImage
friend class OpenCLImage
Definition itkOpenCLContext.h:539
itk::OpenCLContext::GetErrorName
static std::string GetErrorName(const cl_int code)
itk::OpenCLContext::BarrierAsync
OpenCLEvent BarrierAsync(const OpenCLEventList &event_list)
itk::OpenCLContext::OpenCLBuffer
friend class OpenCLBuffer
Definition itkOpenCLContext.h:538
itk::OpenCLContext::GetCommandQueue
OpenCLCommandQueue GetCommandQueue()
itk::OpenCLContext::CreateVector
OpenCLVector< T > CreateVector(const OpenCLMemoryObject::Access access, const std::vcl_size_t size)
Definition itkOpenCLContext.h:311
itk::OpenCLContext::GetActiveQueue
cl_command_queue GetActiveQueue()
itk::OpenCLContext::SetLastError
void SetLastError(const cl_int error)
itk::OpenCLContext::Self
OpenCLContext Self
Definition itkOpenCLContext.h:80
itk::OpenCLContext::SetContextId
void SetContextId(cl_context id)
itk::OpenCLContext::BuildProgramFromSourceCode
OpenCLProgram BuildProgramFromSourceCode(const std::string &sourceCode, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string())
itk::OpenCLContext::CreateSampler
OpenCLSampler CreateSampler(const bool normalizedCoordinates, const OpenCLSampler::AddressingMode addressingMode, const OpenCLSampler::FilterMode filterMode)
itk::OpenCLContext::OpenCLKernel
friend class OpenCLKernel
Definition itkOpenCLContext.h:540
itk::OpenCLContext::OpenCLDebug
void OpenCLDebug(const std::string &callname)
itk::OpenCLContext::SetCommandQueue
void SetCommandQueue(const OpenCLCommandQueue &queue)
itk::OpenCLContext::Barrier
cl_int Barrier(const OpenCLEventList &event_list)
itk::OpenCLContext::BuildProgramFromSourceCode
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())
itk::OpenCLContext::CreateBufferDevice
OpenCLBuffer CreateBufferDevice(const OpenCLMemoryObject::Access access, const std::vcl_size_t size)
itk::OpenCLContext::CreateProgramFromSourceFile
OpenCLProgram CreateProgramFromSourceFile(const std::string &filename, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string())
itk::OpenCLContext::Pointer
SmartPointer< Self > Pointer
Definition itkOpenCLContext.h:82
itk::OpenCLContext::Release
virtual void Release()
itk::OpenCLContext::Flush
void Flush()
itk::OpenCLContext::OpenCLProgram
friend class OpenCLProgram
Definition itkOpenCLContext.h:542
itk::OpenCLContext::GetContextId
cl_context GetContextId() const
itk::OpenCLContext::SetDefaultDevice
void SetDefaultDevice(const OpenCLDevice &device)
itk::OpenCLContext::CreateMethod
CreateMethod
Definition itkOpenCLContext.h:119
itk::OpenCLContext::MultipleMaximumFlopsDevices
@ MultipleMaximumFlopsDevices
Definition itkOpenCLContext.h:124
itk::OpenCLContext::SingleMaximumFlopsDevice
@ SingleMaximumFlopsDevice
Definition itkOpenCLContext.h:123
itk::OpenCLContext::Default
@ Default
Definition itkOpenCLContext.h:120
itk::OpenCLContext::DevelopmentMultipleMaximumFlopsDevices
@ DevelopmentMultipleMaximumFlopsDevices
Definition itkOpenCLContext.h:122
itk::OpenCLContext::DevelopmentSingleMaximumFlopsDevice
@ DevelopmentSingleMaximumFlopsDevice
Definition itkOpenCLContext.h:121
itk::OpenCLContext::GetInstance
static Pointer GetInstance()
itk::OpenCLContext::Superclass
LightObject Superclass
Definition itkOpenCLContext.h:81
itk::OpenCLContext::BuildProgramFromSourceFile
OpenCLProgram BuildProgramFromSourceFile(const std::string &fileName, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string())
itk::OpenCLContext::OpenCLMemoryObject
friend class OpenCLMemoryObject
Definition itkOpenCLContext.h:537
itk::OpenCLContext::operator=
const Self & operator=(const Self &)=delete
itk::OpenCLContext::OpenCLSampler
friend class OpenCLSampler
Definition itkOpenCLContext.h:544
itk::OpenCLContext::OpenCLContext
OpenCLContext()
itk::OpenCLContext::CreateBufferCopy
OpenCLBuffer CreateBufferCopy(const void *data, const OpenCLMemoryObject::Access access, const std::vcl_size_t size)
itk::OpenCLContext::GetDefaultDevice
OpenCLDevice GetDefaultDevice() const
itk::OpenCLContext::CreateUserEvent
OpenCLUserEvent CreateUserEvent()
itk::OpenCLContext::CreateContext
void CreateContext(const std::list< OpenCLDevice > &devices, OpenCLContextPimpl *d)
itk::OpenCLContext::OpenCLVectorBase
friend class OpenCLVectorBase
Definition itkOpenCLContext.h:543
itk::OpenCLContext::CreateOpenCLProgram
OpenCLProgram CreateOpenCLProgram(const std::string &filename, const std::string &source, const std::vcl_size_t sourceSize)
itk::OpenCLContext::CreateImageHost
OpenCLImage CreateImageHost(const OpenCLImageFormat &format, void *data, const OpenCLSize &size, const OpenCLMemoryObject::Access access)
itk::OpenCLContext::WaitForFinished
static cl_int WaitForFinished(const OpenCLEventList &event_list)
itk::OpenCLContext::New
static Pointer New()
itk::OpenCLContext::CreateProgramFromSourceCode
OpenCLProgram CreateProgramFromSourceCode(const std::string &sourceCode, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string())
itk::OpenCLContext::ConstPointer
SmartPointer< const Self > ConstPointer
Definition itkOpenCLContext.h:83
itk::OpenCLContext::IsCreated
bool IsCreated() const
itk::OpenCLContext::MarkerAsync
OpenCLEvent MarkerAsync(const OpenCLEventList &event_list)
itk::OpenCLContext::CreateBufferHost
OpenCLBuffer CreateBufferHost(void *data, const OpenCLMemoryObject::Access access, const std::vcl_size_t size)
itk::OpenCLContext::Create
bool Create(const OpenCLDevice::DeviceType type)
itk::OpenCLContext::ReportError
void ReportError(const cl_int code, const char *fileName="", const int lineNumber=0, const char *location="")
itk::OpenCLContext::Finish
void Finish()
itk::OpenCLContext::CreateCommandQueue
OpenCLCommandQueue CreateCommandQueue(const cl_command_queue_properties properties, const OpenCLDevice &device=OpenCLDevice())
itk::OpenCLContext::GetSupportedImageFormats
std::list< OpenCLImageFormat > GetSupportedImageFormats(const OpenCLImageFormat::ImageType image_type, const cl_mem_flags flags) const
itk::OpenCLContext::Create
bool Create(const std::list< OpenCLDevice > &devices)
itk::OpenCLContext::OpenCLCommandQueue
friend class OpenCLCommandQueue
Definition itkOpenCLContext.h:541
itk::OpenCLContext::GetDefaultCommandQueue
OpenCLCommandQueue GetDefaultCommandQueue()
itk::OpenCLContext::SetInstance
static void SetInstance(OpenCLContext *instance)
itk::OpenCLContext::m_Instance
static Pointer m_Instance
Definition itkOpenCLContext.h:510
itk::OpenCLContext::OpenCLProfile
void OpenCLProfile(cl_event clEvent, const std::string &message, const bool releaseEvent=false)
itk::OpenCLDevice
The OpenCLDevice class represents the collection of OpenCL devices to be used by the host.
Definition itkOpenCLDevice.h:59
itk::OpenCLDevice::DeviceType
DeviceType
Definition itkOpenCLDevice.h:86
itk::OpenCLDevice::Default
@ Default
Definition itkOpenCLDevice.h:87
itk::OpenCLEventList
OpenCLEventList class represents a list of OpenCLEvent objects.
Definition itkOpenCLEventList.h:33
itk::OpenCLEvent
OpenCLEvent class represents an OpenCL event object.
Definition itkOpenCLEvent.h:93
itk::OpenCLImageFormat
The OpenCLImageFormat class represents the format of a OpenCLImage.
Definition itkOpenCLImageFormat.h:35
itk::OpenCLImageFormat::ImageType
ImageType
Definition itkOpenCLImageFormat.h:50
itk::OpenCLImage
The OpenCLImage class represents an image object is used to store a one, two or three dimensional tex...
Definition itkOpenCLImage.h:39
itk::OpenCLKernel
The OpenCLKernel class represents an executable entry point function in an OpenCL program.
Definition itkOpenCLKernel.h:136
itk::OpenCLMemoryObject::Access
Access
Definition itkOpenCLMemoryObject.h:87
itk::OpenCLPlatform
The OpenCLPlatform represent platform model for OpenCL.
Definition itkOpenCLPlatform.h:45
itk::OpenCLSampler::FilterMode
FilterMode
Definition itkOpenCLSampler.h:128
itk::OpenCLSampler::AddressingMode
AddressingMode
Definition itkOpenCLSampler.h:113
itk::OpenCLSize
The OpenCLSize class defines the size of an item of work for an OpenCL kernel.
Definition itkOpenCLSize.h:50
itk::OpenCLUserEvent
The OpenCLUserEvent class represents OpenCL user events.
Definition itkOpenCLUserEvent.h:67
itk::OpenCLVectorBase
The base class for the OpenCLVector implementation.
Definition itkOpenCLVectorBase.h:38
itk::OpenCLVector
The OpenCLVector class represents a templated OpenCL buffer object.
Definition itkOpenCLVector.h:53
itkOpenCLBuffer.h
itkOpenCLCommandQueue.h
itkOpenCLDevice.h
ITKOpenCL_EXPORT
#define ITKOpenCL_EXPORT
Definition itkOpenCLExport.h:33
ITK_OPENCL_DECLARE_PRIVATE
#define ITK_OPENCL_DECLARE_PRIVATE(Class)
Definition itkOpenCLGlobal.h:38
itkOpenCLImage.h
itkOpenCLProgram.h
itkOpenCLSampler.h
itkOpenCLUserEvent.h
itkOpenCLVector.h
itk
Definition itkAdvancedImageToImageMetric.h:43

Generated on 1768596610 for elastix by 1.15.0 |