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:
81 using Superclass = LightObject;
82 using Pointer = SmartPointer<Self>;
83 using ConstPointer = SmartPointer<const Self>;
84
86 itkTypeMacro(OpenCLContext, LightObject);
87
93 static Pointer
94 New();
95
97 static Pointer
99
102 static void
104
108 bool
109 IsCreated() const;
110
119 {
120 Default = 0x0000,
121 DevelopmentSingleMaximumFlopsDevice = 0x0001,
122 DevelopmentMultipleMaximumFlopsDevices = 0x0002,
123 SingleMaximumFlopsDevice = 0x0004,
124 MultipleMaximumFlopsDevices = 0x0008
125 };
126
138 bool
140
147 bool
148 Create(const std::list<OpenCLDevice> & devices);
149
155 bool
157
163 bool
164 Create(const OpenCLPlatform & platfrom, const OpenCLDevice::DeviceType type = OpenCLDevice::Default);
165
176 bool
178
182 virtual void
184
187 cl_context
189
197 void
198 SetContextId(cl_context id);
199
203 std::list<OpenCLDevice>
204 GetDevices() const;
205
212
217 cl_int
219
222 void
223 SetLastError(const cl_int error);
224
228 static std::string
229 GetErrorName(const cl_int code);
230
232 void
233 ReportError(const cl_int code, const char * fileName = "", const int lineNumber = 0, const char * location = "");
234
240
244 void
246
259
268 CreateCommandQueue(const cl_command_queue_properties properties, const OpenCLDevice & device = OpenCLDevice());
269
279 CreateBufferDevice(const OpenCLMemoryObject::Access access, const std::size_t size);
280
290 CreateBufferHost(void * data, const OpenCLMemoryObject::Access access, const std::size_t size);
291
300 CreateBufferCopy(const void * data, const OpenCLMemoryObject::Access access, const std::size_t size);
301
309 template <typename T>
311 CreateVector(const OpenCLMemoryObject::Access access, const std::size_t size)
312 {
313 return OpenCLVector<T>(this, access, size);
314 }
315
316
326
335 void * data,
336 const OpenCLSize & size,
337 const OpenCLMemoryObject::Access access);
338
347 const void * data,
348 const OpenCLSize & size,
349 const OpenCLMemoryObject::Access access);
350
355 CreateProgramFromSourceCode(const std::string & sourceCode,
356 const std::string & prefixSourceCode = std::string(),
357 const std::string & postfixSourceCode = std::string());
358
363 CreateProgramFromSourceFile(const std::string & filename,
364 const std::string & prefixSourceCode = std::string(),
365 const std::string & postfixSourceCode = std::string());
366
372 CreateProgramFromBinaryCode(const unsigned char * binary, const std::size_t size);
373
379 BuildProgramFromSourceCode(const std::string & sourceCode,
380 const std::string & prefixSourceCode = std::string(),
381 const std::string & postfixSourceCode = std::string());
382
384 BuildProgramFromSourceCode(const std::list<OpenCLDevice> & devices,
385 const std::string & sourceCode,
386 const std::string & prefixSourceCode = std::string(),
387 const std::string & postfixSourceCode = std::string(),
388 const std::string & extraBuildOptions = std::string());
389
395 BuildProgramFromSourceFile(const std::string & fileName,
396 const std::string & prefixSourceCode = std::string(),
397 const std::string & postfixSourceCode = std::string());
398
400 BuildProgramFromSourceFile(const std::list<OpenCLDevice> & devices,
401 const std::string & fileName,
402 const std::string & prefixSourceCode = std::string(),
403 const std::string & postfixSourceCode = std::string(),
404 const std::string & extraBuildOptions = std::string());
405
408 std::list<OpenCLImageFormat>
409 GetSupportedImageFormats(const OpenCLImageFormat::ImageType image_type, const cl_mem_flags flags) const;
410
414 CreateSampler(const bool normalizedCoordinates,
415 const OpenCLSampler::AddressingMode addressingMode,
416 const OpenCLSampler::FilterMode filterMode);
417
424
429 void
431
435 void
437
442 cl_int
443 Marker(const OpenCLEventList & event_list);
444
452 MarkerAsync(const OpenCLEventList & event_list);
453
458 cl_int
459 Barrier(const OpenCLEventList & event_list);
460
468 BarrierAsync(const OpenCLEventList & event_list);
469
474 static cl_int
475 WaitForFinished(const OpenCLEventList & event_list);
476
477protected:
481
484 ~OpenCLContext() override;
485
488 void
489 OpenCLProfile(cl_event clEvent, const std::string & message, const bool releaseEvent = false);
490
494 void
496
500 CreateOpenCLProgram(const std::string & filename, const std::string & source, const std::size_t sourceSize);
501
502private:
503 OpenCLContext(const Self & other) = delete;
504 const Self &
505 operator=(const Self &) = delete;
506
508
509 std::unique_ptr<OpenCLContextPimpl> d_ptr;
510 static Pointer m_Instance;
511
513 cl_command_queue
514 GetActiveQueue();
515
518 void
519 CreateContext(const std::list<OpenCLDevice> & devices, OpenCLContextPimpl * d);
520
523 void
524 CreateContext(const OpenCLPlatform & platfrom, const OpenCLDevice::DeviceType type, OpenCLContextPimpl * d);
525
528 void
529 SetUpProfiling();
530
533 void
534 OpenCLDebug(const std::string & callname);
535
537 friend class OpenCLMemoryObject;
538 friend class OpenCLBuffer;
539 friend class OpenCLImage;
540 friend class OpenCLKernel;
541 friend class OpenCLCommandQueue;
542 friend class OpenCLProgram;
543 friend class OpenCLVectorBase;
544 friend class OpenCLSampler;
545};
546
547} // end namespace itk
548
549#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.
OpenCLContext(const Self &other)=delete
cl_int Marker(const OpenCLEventList &event_list)
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)
bool Create(const OpenCLContext::CreateMethod method)
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()
LightObject Superclass
OpenCLProgram BuildProgramFromSourceFile(const std::string &fileName, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string())
const Self & operator=(const Self &)=delete
OpenCLBuffer CreateBufferCopy(const void *data, const OpenCLMemoryObject::Access access, const std::vcl_size_t size)
OpenCLDevice GetDefaultDevice() const
OpenCLUserEvent CreateUserEvent()
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)
static Pointer New()
OpenCLProgram CreateProgramFromSourceCode(const std::string &sourceCode, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string())
SmartPointer< const Self > ConstPointer
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 2023-01-13 for elastix by doxygen 1.9.6 elastix logo