Medical Imaging Interaction Toolkit
2018.4.99-389bf124
Medical Imaging Interaction Toolkit
|
Superclass for all OpenCL based filter. More...
#include <mitkOclFilter.h>
Public Member Functions | |
void | AddSourceFile (const char *filename) |
Add a source file from the resource files to the OpenCL shader file list. Multiple files can be added to the list. More... | |
void | SetCompilerFlags (const char *flags) |
Set specific compilerflags to compile the CL source. Default is set to nullptr; example: "-cl-fast-relaxed-math -cl-mad-enable -cl-strict-aliasing". More... | |
virtual bool | IsInitialized () |
Returns true if the initialization was successfull. More... | |
virtual unsigned long | GetDeviceMemory () |
Returns the amount of global memory of the used device in bytes. More... | |
virtual | ~OclFilter () |
Destructor. More... | |
Protected Types | |
typedef std::vector< const char * > | CStringList |
typedef std::vector< vcl_size_t > | ClSizeList |
Protected Member Functions | |
OclFilter () | |
Constructor. More... | |
OclFilter (const char *filename) | |
Constructor ( overloaded ) More... | |
void | SetWorkingSize (unsigned int locx, unsigned int dimx, unsigned int locy=1, unsigned int dimy=1, unsigned int locz=1, unsigned int dimz=1) |
Set the working size for the following OpenCL kernel call. More... | |
bool | ExecuteKernel (cl_kernel kernel, unsigned int workSizeDim) |
Execute the given kernel on the OpenCL Index-Space defined by the local and global work sizes. More... | |
bool | ExecuteKernelChunks (cl_kernel kernel, unsigned int workSizeDim, vcl_size_t *chunksDim) |
Execute the given kernel on the OpenCL Index-Space defined by the local and global work sizes, but divide it into chunks of dimension chunksDim. More... | |
bool | ExecuteKernelChunksInBatches (cl_kernel kernel, unsigned int workSizeDim, vcl_size_t *chunksDim, vcl_size_t batchSize, int waitTimems) |
Execute the given kernel on the OpenCL Index-Space defined by the local and global work sizes, but divide it into chunks of dimension chunksDim and wait between batches of batchSize chunks a time of waitTimems milliseconds. More... | |
bool | Initialize () |
Initialize all necessary parts of the filter. More... | |
void | CompileSource () |
Compile the program source. More... | |
void | SetSourcePreambel (const char *preambel) |
Add some source code on the beginning of the loaded source. More... | |
virtual us::Module * | GetModule ()=0 |
Get the Module of the filter. Needs to be implemented by every subclass. The filter will load the OpenCL sourcefiles from this module context. More... | |
void | LoadSourceFiles (CStringList &SourceCodeList, ClSizeList &SourceCodeSizeList) |
Helper functions that load sourcefiles from the module context in the Initialize function. More... | |
Protected Attributes | |
const char * | m_ClCompilerFlags |
String that contains the compiler flags. More... | |
cl_program | m_ClProgram |
The compiled OpenCL program. More... | |
cl_command_queue | m_CommandQue |
Command queue for the filter. More... | |
std::string | m_FilterID |
Unique ID of the filter, needs to be specified in the constructor of the derived class. More... | |
const char * | m_Preambel |
source preambel for e.g. #define commands to be inserted into the OpenCL source More... | |
CStringList | m_ClFiles |
List of sourcefiles that will be compiled for this filter. More... | |
bool | m_Initialized |
status of the filter More... | |
vcl_size_t | m_LocalWorkSize [3] |
The local work size fo the filter. More... | |
vcl_size_t | m_GlobalWorkSize [3] |
The global work size of the filter. More... | |
Superclass for all OpenCL based filter.
This class takes care of loading and compiling the external GPU program code.
Definition at line 33 of file mitkOclFilter.h.
|
protected |
Definition at line 68 of file mitkOclFilter.h.
|
protected |
Definition at line 67 of file mitkOclFilter.h.
|
virtual |
Destructor.
Definition at line 56 of file mitkOclFilter.cpp.
References us::GetModuleContext(), ModuleContext::GetService(), ModuleContext::GetServiceReference(), m_ClProgram, m_FilterID, MITK_DEBUG, and OclResourceService::RemoveProgram().
|
protected |
Constructor.
Definition at line 35 of file mitkOclFilter.cpp.
|
protected |
void mitk::OclFilter::AddSourceFile | ( | const char * | filename | ) |
Add a source file from the resource files to the OpenCL shader file list. Multiple files can be added to the list.
name | of the file in the resource system |
Definition at line 330 of file mitkOclFilter.cpp.
References m_ClFiles.
Referenced by mitk::OclBinaryThresholdImageFilter::OclBinaryThresholdImageFilter().
|
protected |
Compile the program source.
preambel | e.g. defines for the shader code |
Definition at line 243 of file mitkOclFilter.cpp.
References CHECK_OCL_ERR, OclResourceService::GetContext(), us::GetModuleContext(), ModuleContext::GetService(), ModuleContext::GetServiceReference(), LoadSourceFiles(), m_ClCompilerFlags, m_ClFiles, m_ClProgram, m_FilterID, m_Initialized, MITK_DEBUG, MITK_ERROR, oclLogBinary(), and oclLogBuildInfo().
Referenced by Initialize().
|
protected |
Execute the given kernel on the OpenCL Index-Space defined by the local and global work sizes.
Definition at line 71 of file mitkOclFilter.cpp.
References CHECK_OCL_ERR, m_CommandQue, m_GlobalWorkSize, and m_LocalWorkSize.
Referenced by mitk::OclBinaryThresholdImageFilter::Execute().
|
protected |
Execute the given kernel on the OpenCL Index-Space defined by the local and global work sizes, but divide it into chunks of dimension chunksDim.
Definition at line 83 of file mitkOclFilter.cpp.
References CHECK_OCL_ERR, m_CommandQue, m_GlobalWorkSize, m_LocalWorkSize, and offset.
|
protected |
Execute the given kernel on the OpenCL Index-Space defined by the local and global work sizes, but divide it into chunks of dimension chunksDim and wait between batches of batchSize chunks a time of waitTimems milliseconds.
Definition at line 119 of file mitkOclFilter.cpp.
References CHECK_OCL_ERR, m_CommandQue, m_GlobalWorkSize, m_LocalWorkSize, and offset.
|
virtual |
Returns the amount of global memory of the used device in bytes.
Definition at line 346 of file mitkOclFilter.cpp.
References OclResourceService::GetCurrentDevice(), us::GetModuleContext(), ModuleContext::GetService(), ModuleContext::GetServiceReference(), and oclGetGlobalMemSize().
|
protectedpure virtual |
Get the Module of the filter. Needs to be implemented by every subclass. The filter will load the OpenCL sourcefiles from this module context.
Implemented in mitk::OclBinaryThresholdImageFilter.
Referenced by LoadSourceFiles().
|
protected |
Initialize all necessary parts of the filter.
The Initialize() method creates the command queue and the m_clProgram. The program is either compiled from the given source or taken from the OclResourceManager if the program was compiled already.
Definition at line 180 of file mitkOclFilter.cpp.
References CHECK_OCL_ERR, CompileSource(), us::GetModuleContext(), ModuleContext::GetService(), ModuleContext::GetServiceReference(), m_ClFiles, m_ClProgram, m_CommandQue, m_FilterID, m_Initialized, MITK_ERROR, and MITK_INFO.
Referenced by mitk::OclBinaryThresholdImageFilter::Initialize().
|
virtual |
Returns true if the initialization was successfull.
Definition at line 341 of file mitkOclFilter.cpp.
References m_Initialized.
Referenced by mitk::OclBinaryThresholdImageFilter::Initialize().
|
protected |
Helper functions that load sourcefiles from the module context in the Initialize function.
SourceCodeList | holds the sourcecode for every file as string, the SourceCodeSizeList holst the size of every file in bytes. |
Definition at line 212 of file mitkOclFilter.cpp.
References GetModule(), us::ModuleResource::GetName(), us::Module::GetResource(), us::ModuleResource::IsValid(), m_ClFiles, m_Preambel, MITK_DEBUG, and MITK_WARN.
Referenced by CompileSource().
void mitk::OclFilter::SetCompilerFlags | ( | const char * | flags | ) |
Set specific compilerflags to compile the CL source. Default is set to nullptr; example: "-cl-fast-relaxed-math -cl-mad-enable -cl-strict-aliasing".
flags | to the modulefolder that contains the gpuSource |
Definition at line 335 of file mitkOclFilter.cpp.
References m_ClCompilerFlags.
|
protected |
Add some source code on the beginning of the loaded source.
In this way, some preprocessor flags for the CL compiler can at the beginning of the filter
preambel | Source preambel for e.g. #define commands to be inserted into the OpenCL source |
Definition at line 325 of file mitkOclFilter.cpp.
References m_Preambel.
|
protected |
Set the working size for the following OpenCL kernel call.
Definition at line 305 of file mitkOclFilter.cpp.
References iDivUp(), m_GlobalWorkSize, and m_LocalWorkSize.
Referenced by mitk::OclDataSetToDataSetFilter::InitExec(), mitk::OclImageToImageFilter::InitExec(), and mitk::OclDataSetToDataSetFilter::InitExecNoInput().
|
protected |
String that contains the compiler flags.
Definition at line 77 of file mitkOclFilter.h.
Referenced by CompileSource(), and SetCompilerFlags().
|
protected |
List of sourcefiles that will be compiled for this filter.
Definition at line 92 of file mitkOclFilter.h.
Referenced by AddSourceFile(), CompileSource(), Initialize(), LoadSourceFiles(), and OclFilter().
|
protected |
The compiled OpenCL program.
Definition at line 80 of file mitkOclFilter.h.
Referenced by CompileSource(), mitk::OclBinaryThresholdImageFilter::Initialize(), Initialize(), and ~OclFilter().
|
protected |
Command queue for the filter.
Definition at line 83 of file mitkOclFilter.h.
Referenced by ExecuteKernel(), ExecuteKernelChunks(), ExecuteKernelChunksInBatches(), mitk::OclImageToImageFilter::GetOutput(), mitk::OclDataSetToDataSetFilter::GetOutput(), mitk::OclDataSetToDataSetFilter::InitExec(), mitk::OclImageToImageFilter::InitExec(), and Initialize().
|
protected |
Unique ID of the filter, needs to be specified in the constructor of the derived class.
Definition at line 86 of file mitkOclFilter.h.
Referenced by CompileSource(), Initialize(), mitk::OclBinaryThresholdImageFilter::OclBinaryThresholdImageFilter(), and ~OclFilter().
|
protected |
The global work size of the filter.
Definition at line 101 of file mitkOclFilter.h.
Referenced by ExecuteKernel(), ExecuteKernelChunks(), ExecuteKernelChunksInBatches(), and SetWorkingSize().
|
protected |
status of the filter
Definition at line 95 of file mitkOclFilter.h.
Referenced by CompileSource(), Initialize(), and IsInitialized().
|
protected |
The local work size fo the filter.
Definition at line 98 of file mitkOclFilter.h.
Referenced by ExecuteKernel(), ExecuteKernelChunks(), ExecuteKernelChunksInBatches(), and SetWorkingSize().
|
protected |
source preambel for e.g. #define commands to be inserted into the OpenCL source
Definition at line 89 of file mitkOclFilter.h.
Referenced by LoadSourceFiles(), and SetSourcePreambel().