18 #ifndef __itkOpenCLKernel_h 19 #define __itkOpenCLKernel_h 31 #include "itkVector.h" 32 #include "itkCovariantVector.h" 33 #include "itkMatrix.h" 111 #define OpenCLKernelSetArgMacroH( type ) \ 112 cl_int SetArg( const cl_uint index, const type value ); \ 114 #define OpenCLKernelSetArgMacroCXX( type ) \ 115 cl_int OpenCLKernel::SetArg( const cl_uint index, const type value ) \ 117 return clSetKernelArg( this->m_KernelId, index, sizeof( value ), (const void *)&value ); \ 120 #define OpenCLKernelSetArgsMacroH( type0, type1, type2, type3, type4 ) \ 121 OpenCLKernelSetArgMacroH( type0 ) OpenCLKernelSetArgMacroH( type1 ) \ 122 OpenCLKernelSetArgMacroH( type2 ) OpenCLKernelSetArgMacroH( type3 ) \ 123 OpenCLKernelSetArgMacroH( type4 ) \ 125 #define OpenCLKernelSetArgsMacroCXX( type0, type1, type2, type3, type4 ) \ 126 OpenCLKernelSetArgMacroCXX( type0 ) OpenCLKernelSetArgMacroCXX( type1 ) \ 127 OpenCLKernelSetArgMacroCXX( type2 ) OpenCLKernelSetArgMacroCXX( type3 ) \ 128 OpenCLKernelSetArgMacroCXX( type4 ) \ 133 class OpenCLVectorBase;
136 class OpenCLKernelPimpl;
167 cl_kernel GetKernelId()
const;
176 std::string GetName()
const;
180 std::size_t GetNumberOfArguments()
const;
198 void SetGlobalWorkSize(
const OpenCLSize & size );
208 void SetRoundedGlobalWorkSize(
const OpenCLSize & size );
212 void SetLocalWorkSize(
const OpenCLSize & size );
216 void SetGlobalWorkOffset(
const OpenCLSize & offset );
233 OpenCLSize GetBestLocalWorkSizeImage1D()
const;
239 OpenCLSize GetBestLocalWorkSizeImage2D()
const;
245 OpenCLSize GetBestLocalWorkSizeImage3D()
const;
249 OpenCLSize GetBestLocalWorkSizeImage(
const std::size_t dimension )
const;
255 size_t GetPreferredWorkSizeMultiple()
const;
303 cl_int SetArg( const cl_uint index, const
void * data, const
size_t size );
307 cl_int SetArg( const cl_uint index, const Size1DType & value );
310 cl_int SetArg( const cl_uint index, const Size2DType & value );
313 cl_int SetArg( const cl_uint index, const Size3DType & value );
316 cl_int SetArg( const cl_uint index, const Size4DType & value );
320 cl_int SetArg( const cl_uint index, const Index1DType & value );
323 cl_int SetArg( const cl_uint index, const Index2DType & value );
326 cl_int SetArg( const cl_uint index, const Index3DType & value );
329 cl_int SetArg( const cl_uint index, const Index4DType & value );
333 cl_int SetArg( const cl_uint index, const Offset1DType & value );
336 cl_int SetArg( const cl_uint index, const Offset2DType & value );
339 cl_int SetArg( const cl_uint index, const Offset3DType & value );
342 cl_int SetArg( const cl_uint index, const Offset4DType & value );
346 cl_int SetArg( const cl_uint index, const PointInt1DType & value );
349 cl_int SetArg( const cl_uint index, const PointFloat1DType & value );
352 cl_int SetArg( const cl_uint index, const PointDouble1DType & value );
355 cl_int SetArg( const cl_uint index, const PointInt2DType & value );
358 cl_int SetArg( const cl_uint index, const PointFloat2DType & value );
361 cl_int SetArg( const cl_uint index, const PointDouble2DType & value );
364 cl_int SetArg( const cl_uint index, const PointInt3DType & value );
367 cl_int SetArg( const cl_uint index, const PointFloat3DType & value );
370 cl_int SetArg( const cl_uint index, const PointDouble3DType & value );
373 cl_int SetArg( const cl_uint index, const PointInt4DType & value );
376 cl_int SetArg( const cl_uint index, const PointFloat4DType & value );
379 cl_int SetArg( const cl_uint index, const PointDouble4DType & value );
384 cl_int SetArg( const cl_uint index, const VectorInt1DType & value );
387 cl_int SetArg( const cl_uint index, const VectorFloat1DType & value );
390 cl_int SetArg( const cl_uint index, const VectorDouble1DType & value );
393 cl_int SetArg( const cl_uint index, const VectorInt2DType & value );
396 cl_int SetArg( const cl_uint index, const VectorFloat2DType & value );
399 cl_int SetArg( const cl_uint index, const VectorDouble2DType & value );
402 cl_int SetArg( const cl_uint index, const VectorInt3DType & value );
405 cl_int SetArg( const cl_uint index, const VectorFloat3DType & value );
408 cl_int SetArg( const cl_uint index, const VectorDouble3DType & value );
411 cl_int SetArg( const cl_uint index, const VectorInt4DType & value );
414 cl_int SetArg( const cl_uint index, const VectorFloat4DType & value );
417 cl_int SetArg( const cl_uint index, const VectorDouble4DType & value );
421 cl_int SetArg( const cl_uint index, const CovariantVectorInt1DType & value );
424 cl_int SetArg( const cl_uint index, const CovariantVectorFloat1DType & value );
427 cl_int SetArg( const cl_uint index, const CovariantVectorDouble1DType & value );
430 cl_int SetArg( const cl_uint index, const CovariantVectorInt2DType & value );
433 cl_int SetArg( const cl_uint index, const CovariantVectorFloat2DType & value );
436 cl_int SetArg( const cl_uint index, const CovariantVectorDouble2DType & value );
439 cl_int SetArg( const cl_uint index, const CovariantVectorInt3DType & value );
442 cl_int SetArg( const cl_uint index, const CovariantVectorFloat3DType & value );
445 cl_int SetArg( const cl_uint index, const CovariantVectorDouble3DType & value );
448 cl_int SetArg( const cl_uint index, const CovariantVectorInt4DType & value );
451 cl_int SetArg( const cl_uint index, const CovariantVectorFloat4DType & value );
454 cl_int SetArg( const cl_uint index, const CovariantVectorDouble4DType & value );
458 cl_int SetArg( const cl_uint index, const MatrixFloat1x1Type & value );
461 cl_int SetArg( const cl_uint index, const MatrixDouble1x1Type & value );
464 cl_int SetArg( const cl_uint index, const MatrixFloat2x2Type & value );
467 cl_int SetArg( const cl_uint index, const MatrixDouble2x2Type & value );
470 cl_int SetArg( const cl_uint index, const MatrixFloat3x3Type & value );
473 cl_int SetArg( const cl_uint index, const MatrixDouble3x3Type & value );
476 cl_int SetArg( const cl_uint index, const MatrixFloat4x4Type & value );
479 cl_int SetArg( const cl_uint index, const MatrixDouble4x4Type & value );
494 cl_int SetArg( const cl_uint index, const
OpenCLSampler & value );
545 template<
typename T1 >
548 this->SetArg( 0, arg1 );
549 return this->LaunchKernel();
556 template<
typename T1,
typename T2 >
559 this->SetArg( 0, arg1 );
560 this->SetArg( 1, arg2 );
561 return this->LaunchKernel();
568 template<
typename T1,
typename T2,
typename T3 >
570 (
const T1 & arg1,
const T2 & arg2,
const T3 & arg3 )
572 this->SetArg( 0, arg1 );
573 this->SetArg( 1, arg2 );
574 this->SetArg( 2, arg3 );
575 return this->LaunchKernel();
582 template<
typename T1,
typename T2,
typename T3,
typename T4 >
584 (
const T1 & arg1,
const T2 & arg2,
const T3 & arg3,
const T4 & arg4 )
586 this->SetArg( 0, arg1 );
587 this->SetArg( 1, arg2 );
588 this->SetArg( 2, arg3 );
589 this->SetArg( 3, arg4 );
590 return this->LaunchKernel();
597 template<
typename T1,
typename T2,
typename T3,
typename T4,
600 (
const T1 & arg1,
const T2 & arg2,
const T3 & arg3,
const T4 & arg4,
603 this->SetArg( 0, arg1 );
604 this->SetArg( 1, arg2 );
605 this->SetArg( 2, arg3 );
606 this->SetArg( 3, arg4 );
607 this->SetArg( 4, arg5 );
608 return this->LaunchKernel();
615 template<
typename T1,
typename T2,
typename T3,
typename T4,
616 typename T5,
typename T6 >
618 (
const T1 & arg1,
const T2 & arg2,
const T3 & arg3,
const T4 & arg4,
619 const T5 & arg5,
const T6 & arg6 )
621 this->SetArg( 0, arg1 );
622 this->SetArg( 1, arg2 );
623 this->SetArg( 2, arg3 );
624 this->SetArg( 3, arg4 );
625 this->SetArg( 4, arg5 );
626 this->SetArg( 5, arg6 );
627 return this->LaunchKernel();
634 template<
typename T1,
typename T2,
typename T3,
typename T4,
635 typename T5,
typename T6,
typename T7 >
637 (
const T1 & arg1,
const T2 & arg2,
const T3 & arg3,
const T4 & arg4,
638 const T5 & arg5,
const T6 & arg6,
const T7 & arg7 )
640 this->SetArg( 0, arg1 );
641 this->SetArg( 1, arg2 );
642 this->SetArg( 2, arg3 );
643 this->SetArg( 3, arg4 );
644 this->SetArg( 4, arg5 );
645 this->SetArg( 5, arg6 );
646 this->SetArg( 6, arg7 );
647 return this->LaunchKernel();
654 template<
typename T1,
typename T2,
typename T3,
typename T4,
655 typename T5,
typename T6,
typename T7,
typename T8 >
657 (
const T1 & arg1,
const T2 & arg2,
const T3 & arg3,
const T4 & arg4,
658 const T5 & arg5,
const T6 & arg6,
const T7 & arg7,
const T8 & arg8 )
660 this->SetArg( 0, arg1 );
661 this->SetArg( 1, arg2 );
662 this->SetArg( 2, arg3 );
663 this->SetArg( 3, arg4 );
664 this->SetArg( 4, arg5 );
665 this->SetArg( 5, arg6 );
666 this->SetArg( 6, arg7 );
667 this->SetArg( 7, arg8 );
668 return this->LaunchKernel();
676 template<
typename T1,
typename T2,
typename T3,
typename T4,
677 typename T5,
typename T6,
typename T7,
typename T8,
680 (
const T1 & arg1,
const T2 & arg2,
const T3 & arg3,
const T4 & arg4,
681 const T5 & arg5,
const T6 & arg6,
const T7 & arg7,
const T8 & arg8,
684 this->SetArg( 0, arg1 );
685 this->SetArg( 1, arg2 );
686 this->SetArg( 2, arg3 );
687 this->SetArg( 3, arg4 );
688 this->SetArg( 4, arg5 );
689 this->SetArg( 5, arg6 );
690 this->SetArg( 6, arg7 );
691 this->SetArg( 7, arg8 );
692 this->SetArg( 8, arg9 );
693 return this->LaunchKernel();
701 template<
typename T1,
typename T2,
typename T3,
typename T4,
702 typename T5,
typename T6,
typename T7,
typename T8,
703 typename T9,
typename T10 >
705 (
const T1 & arg1,
const T2 & arg2,
const T3 & arg3,
const T4 & arg4,
706 const T5 & arg5,
const T6 & arg6,
const T7 & arg7,
const T8 & arg8,
707 const T9 & arg9,
const T10 & arg10 )
709 this->SetArg( 0, arg1 );
710 this->SetArg( 1, arg2 );
711 this->SetArg( 2, arg3 );
712 this->SetArg( 3, arg4 );
713 this->SetArg( 4, arg5 );
714 this->SetArg( 5, arg6 );
715 this->SetArg( 6, arg7 );
716 this->SetArg( 7, arg8 );
717 this->SetArg( 8, arg9 );
718 this->SetArg( 9, arg10 );
719 return this->LaunchKernel();
725 std::auto_ptr< OpenCLKernelPimpl >
d_ptr;
743 template<
typename charT,
typename traits >
745 std::basic_ostream< charT, traits > &
746 operator<<( std::basic_ostream< charT, traits > & strm,
749 if( kernel.IsNull() )
751 strm <<
"OpenCLKernel(null)";
755 const char indent =
' ';
757 strm <<
"OpenCLKernel" << std::endl
758 << indent <<
"Id: " << kernel.
GetKernelId() << std::endl
759 << indent <<
"Name: " << kernel.GetName() << std::endl
760 << indent <<
"Number of arguments: " << kernel.GetNumberOfArguments() << std::endl
761 << indent <<
"Global work size: " << kernel.GetGlobalWorkSize() << std::endl
762 << indent <<
"Local work size: " << kernel.GetLocalWorkSize() << std::endl
763 << indent <<
"Global work offset: " << kernel.GetGlobalWorkOffset() << std::endl
764 << indent <<
"Compile work group size: " << kernel.GetCompileWorkGroupSize() << std::endl
765 << indent <<
"Best local work size image 2D: " << kernel.GetBestLocalWorkSizeImage2D() << std::endl
766 << indent <<
"Best local work size image 3D: " << kernel.GetBestLocalWorkSizeImage3D() << std::endl
767 << indent <<
"Preferred work size multiple: " << kernel.GetPreferredWorkSizeMultiple() << std::endl;
Matrix< float, 4, 4 > MatrixFloat4x4Type
Point< float, 4 > PointFloat4DType
Point< double, 2 > PointDouble2DType
Vector< int, 2 > VectorInt2DType
Vector< double, 3 > VectorDouble3DType
CovariantVector< double, 3 > CovariantVectorDouble3DType
cl_kernel GetKernelId() const
Vector< float, 3 > VectorFloat3DType
CovariantVector< float, 4 > CovariantVectorFloat4DType
Point< int, 1 > PointInt1DType
OpenCLEventList class represents a list of OpenCLEvent objects.
The OpenCLSize class defines the size of an item of work for an OpenCL kernel.
OpenCLEvent operator()(const T1 &arg1, const T2 &arg2)
Vector< float, 1 > VectorFloat1DType
The base class for the OpenCLVector implementation.
CovariantVector< int, 1 > CovariantVectorInt1DType
Matrix< double, 2, 2 > MatrixDouble2x2Type
Point< double, 3 > PointDouble3DType
CovariantVector< double, 2 > CovariantVectorDouble2DType
CovariantVector< int, 3 > CovariantVectorInt3DType
The OpenCLContext class represents an OpenCL context.
Matrix< float, 1, 1 > MatrixFloat1x1Type
Vector< double, 2 > VectorDouble2DType
Vector< double, 4 > VectorDouble4DType
Point< float, 1 > PointFloat1DType
Point< float, 3 > PointFloat3DType
CovariantVector< float, 3 > CovariantVectorFloat3DType
Matrix< double, 4, 4 > MatrixDouble4x4Type
void SetDoubleAsFloat(const bool value)
bool ITKOpenCL_EXPORT operator==(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)
CovariantVector< int, 2 > CovariantVectorInt2DType
Matrix< float, 3, 3 > MatrixFloat3x3Type
#define ITK_OPENCL_DECLARE_PRIVATE(Class)
CovariantVector< double, 4 > CovariantVectorDouble4DType
bool ITKOpenCL_EXPORT operator!=(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)
Vector< int, 4 > VectorInt4DType
Point< int, 4 > PointInt4DType
CovariantVector< float, 2 > CovariantVectorFloat2DType
void SetDoubleAsFloatDisable()
CovariantVector< double, 1 > CovariantVectorDouble1DType
The OpenCLSampler class represents an OpenCL sampler object.
std::auto_ptr< OpenCLKernelPimpl > d_ptr
void SetDoubleAsFloatEnable()
The OpenCLDevice class represents the collection of OpenCL devices to be used by the host...
bool GetDoubleAsFloatEnabled()
CovariantVector< float, 1 > CovariantVectorFloat1DType
Vector< double, 1 > VectorDouble1DType
Matrix< double, 1, 1 > MatrixDouble1x1Type
CovariantVector< int, 4 > CovariantVectorInt4DType
Point< float, 2 > PointFloat2DType
The OpenCLKernel class represents an executable entry point function in an OpenCL program...
Matrix< float, 2, 2 > MatrixFloat2x2Type
#define OpenCLKernelSetArgsMacroH(type0, type1, type2, type3, type4)
The OpenCLMemoryObject class represents all common memory objects such as buffers and image objects...
Vector< float, 4 > VectorFloat4DType
Vector< int, 3 > VectorInt3DType
OpenCLEvent operator()(const T1 &arg1)
Point< double, 1 > PointDouble1DType
Vector< int, 1 > VectorInt1DType
The OpenCLProgram class represents an OpenCL program object.
OpenCLEvent class represents an OpenCL event object.
Point< int, 2 > PointInt2DType
Point< int, 3 > PointInt3DType
Vector< float, 2 > VectorFloat2DType
Matrix< double, 3, 3 > MatrixDouble3x3Type
Point< double, 4 > PointDouble4DType