go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkOpenCLDevice.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 __itkOpenCLDevice_h
19 #define __itkOpenCLDevice_h
20 
21 #include "itkOpenCLPlatform.h"
22 #include "itkOpenCLSize.h"
23 
24 namespace itk
25 {
59 {
60 public:
61 
63  typedef OpenCLDevice Self;
64 
66  OpenCLDevice() : m_Id( 0 ), m_Version( 0 ) {}
67 
70  OpenCLDevice( cl_device_id id ) : m_Id( id ), m_Version( 0 ) {}
71 
80  enum DeviceType {
81  Default = ( 1 << 0 ),
82  CPU = ( 1 << 1 ),
83  GPU = ( 1 << 2 ),
84  Accelerator = ( 1 << 3 ),
85  Custom = ( 1 << 4 ),
86  All = 0xFFFFFFFF
87  };
88 
89  enum Endian {
91  LittleEndian
92  };
93 
95  bool IsNull() const { return this->m_Id == 0; }
96 
98  cl_device_id GetDeviceId() const { return this->m_Id; }
99 
102  OpenCLVersion GetOpenCLVersion() const;
103 
109  std::string GetVersion() const;
110 
113  OpenCLDevice::DeviceType GetDeviceType() const;
114 
116  OpenCLPlatform GetPlatform() const;
117 
119  unsigned int GetVendorId() const;
120 
122  bool IsAvailable() const;
123 
125  bool HasCompiler() const;
126 
129  bool HasNativeKernels() const;
130 
134  bool HasOutOfOrderExecution() const;
135 
138  bool HasDouble() const;
139 
146  bool HasHalfFloat() const;
147 
150  bool HasErrorCorrectingMemory() const;
151 
154  bool HasUnifiedMemory() const;
155 
157  unsigned int GetComputeUnits() const;
158 
160  unsigned int GetClockFrequency() const;
161 
164  unsigned int GetAddressBits() const;
165 
168  OpenCLDevice::Endian GetByteOrder() const;
169 
172  OpenCLSize GetMaximumWorkItemSize() const;
173 
177  std::size_t GetMaximumWorkItemsPerGroup() const;
178 
180  bool HasImage2D() const;
181 
183  bool HasImage3D() const;
184 
187  bool HasWritableImage3D() const;
188 
192  OpenCLSize GetMaximumImage2DSize() const;
193 
197  OpenCLSize GetMaximumImage3DSize() const;
198 
201  unsigned int GetMaximumSamplers() const;
202 
206  unsigned int GetMaximumReadImages() const;
207 
211  unsigned int GetMaximumWriteImages() const;
212 
216  unsigned int GetPreferredCharVectorSize() const;
217 
221  unsigned int GetPreferredShortVectorSize() const;
222 
226  unsigned int GetPreferredIntVectorSize() const;
227 
232  unsigned int GetPreferredLongVectorSize() const;
233 
238  unsigned int GetPreferredFloatVectorSize() const;
239 
246  unsigned int GetPreferredDoubleVectorSize() const;
247 
255  unsigned int GetPreferredHalfFloatVectorSize() const;
256 
261  unsigned int GetNativeCharVectorSize() const;
262 
267  unsigned int GetNativeShortVectorSize() const;
268 
273  unsigned int GetNativeIntVectorSize() const;
274 
279  unsigned int GetNativeLongVectorSize() const;
280 
285  unsigned int GetNativeFloatVectorSize() const;
286 
293  unsigned int GetNativeDoubleVectorSize() const;
294 
301  unsigned int GetNativeHalfFloatVectorSize() const;
302 
315  NotSupported = 0x0000,
316  Denorm = 0x0001,
317  InfinityNaN = 0x0002,
318  RoundNearest = 0x0004,
319  RoundZero = 0x0008,
320  RoundInfinity = 0x0010,
321  FusedMultiplyAdd = 0x0020
322  };
323 
326  FloatCapability GetFloatCapabilities() const;
327 
333  FloatCapability GetDoubleCapabilities() const;
334 
340  FloatCapability GetHalfFloatCapabilities() const;
341 
344  std::size_t GetProfilingTimerResolution() const;
345 
348  unsigned long GetMaximumAllocationSize() const;
349 
352  unsigned long GetGlobalMemorySize() const;
353 
360  enum CacheType {
361  NoCache = 0,
362  ReadOnlyCache = 1,
363  ReadWriteCache = 2
364  };
365 
368  CacheType GetGlobalMemoryCacheType() const;
369 
372  unsigned long GetGlobalMemoryCacheSize() const;
373 
376  unsigned int GetGlobalMemoryCacheLineSize() const;
377 
380  unsigned long GetLocalMemorySize() const;
381 
386  bool IsLocalMemorySeparate() const;
387 
390  unsigned long GetMaximumConstantBufferSize() const;
391 
395  unsigned int GetMaximumConstantArguments() const;
396 
399  unsigned int GetDefaultAlignment() const;
400 
403  unsigned int GetMinimumAlignment() const;
404 
407  std::size_t GetMaximumParameterBytes() const;
408 
411  bool IsFullProfile() const;
412 
415  bool IsEmbeddedProfile() const;
416 
420  std::string GetProfile() const;
421 
424  std::string GetDriverVersion() const;
425 
427  std::string GetName() const;
428 
430  std::string GetVendor() const;
431 
434  std::list< std::string > GetExtensions() const;
435 
438  std::string GetLanguageVersion() const;
439 
445  bool HasExtension( const std::string & name ) const;
446 
449  static std::list< OpenCLDevice > GetAllDevices();
450 
455  static std::list< OpenCLDevice > GetDevices( const OpenCLDevice::DeviceType types,
456  const OpenCLPlatform & platform = OpenCLPlatform() );
457 
461  static std::list< OpenCLDevice > GetDevices( const OpenCLDevice::DeviceType type,
462  const OpenCLPlatform::VendorType vendor );
463 
466  static OpenCLDevice GetMaximumFlopsDevice( const std::list< OpenCLDevice > & devices,
467  const OpenCLDevice::DeviceType type );
468 
471  static OpenCLDevice GetMaximumFlopsDevice( const OpenCLDevice::DeviceType type );
472 
476  static OpenCLDevice GetMaximumFlopsDeviceByVendor( const OpenCLDevice::DeviceType type,
477  const OpenCLPlatform::VendorType vendor );
478 
482  static OpenCLDevice GetMaximumFlopsDeviceByPlatform( const OpenCLDevice::DeviceType types,
483  const OpenCLPlatform & platform = OpenCLPlatform() );
484 
489  static std::list< OpenCLDevice > GetMaximumFlopsDevices( const OpenCLDevice::DeviceType type,
490  const OpenCLPlatform & platform = OpenCLPlatform() );
491 
492 private:
493 
494  cl_device_id m_Id;
495  mutable int m_Version;
496 };
497 
501 bool ITKOpenCL_EXPORT operator==( const OpenCLDevice & lhs, const OpenCLDevice & rhs );
502 
506 bool ITKOpenCL_EXPORT operator!=( const OpenCLDevice & lhs, const OpenCLDevice & rhs );
507 
509 template< typename charT, typename traits >
510 inline
511 std::basic_ostream< charT, traits > &
512 operator<<( std::basic_ostream< charT, traits > & strm,
513  const OpenCLDevice & device )
514 {
515  if( device.IsNull() )
516  {
517  strm << "OpenCLDevice(null)";
518  return strm;
519  }
520 
521  const char indent = ' ';
522 
523  strm << "OpenCLDevice" << std::endl
524  << indent << "Id: " << device.GetDeviceId() << std::endl;
525 
526  strm << indent << "OpenCL version: ";
527  switch( device.GetOpenCLVersion() )
528  {
529  case VERSION_1_0:
530  strm << "1.0"; break;
531  case VERSION_1_1:
532  strm << "1.1"; break;
533  case VERSION_1_2:
534  strm << "1.2"; break;
535  case VERSION_2_0:
536  strm << "2.0"; break;
537  default:
538  strm << "Unknown"; break;
539  }
540 
541  strm << std::endl << indent << "Version: " << device.GetVersion() << std::endl;
542 
543  strm << indent << "Device type: ";
544  switch( device.GetDeviceType() )
545  {
547  strm << "Default"; break;
548  case OpenCLDevice::CPU:
549  strm << "CPU"; break;
550  case OpenCLDevice::GPU:
551  strm << "GPU"; break;
553  strm << "Accelerator"; break;
554  case OpenCLDevice::All:
555  strm << "All"; break;
556  default:
557  strm << "Unknown"; break;
558  }
559 
560  // strm << device.GetPlatform() << std::endl;
561  strm << std::endl << indent << "Vendor Id: " << device.GetVendorId() << std::endl
562  << indent << "Available: " << ( device.IsAvailable() ? "Yes" : "No" ) << std::endl
563  << indent << "Has compiler: " << ( device.HasCompiler() ? "Yes" : "No" ) << std::endl
564  << indent << "Has native kernels: " << ( device.HasNativeKernels() ? "Yes" : "No" ) << std::endl
565  << indent << "Has out of order execution: " << ( device.HasOutOfOrderExecution() ? "Yes" : "No" ) << std::endl
566  << indent << "Has double: " << ( device.HasDouble() ? "Yes" : "No" ) << std::endl
567  << indent << "Has half float: " << ( device.HasHalfFloat() ? "Yes" : "No" ) << std::endl
568  << indent << "Has error correcting memory: " << ( device.HasErrorCorrectingMemory() ? "Yes" : "No" ) << std::endl
569  << indent << "Has unified memory: " << ( device.HasUnifiedMemory() ? "Yes" : "No" ) << std::endl
570  << indent << "Compute units: " << device.GetComputeUnits() << std::endl
571  << indent << "Clock frequency: " << device.GetClockFrequency() << std::endl
572  << indent << "Address bits: " << device.GetAddressBits() << std::endl;
573 
574  strm << indent << "Byte order: ";
575  switch( device.GetByteOrder() )
576  {
578  strm << "Big Endian"; break;
580  strm << "Little Endian"; break;
581  default:
582  strm << "Unknown"; break;
583  }
584 
585  strm << std::endl << indent << "Maximum work item size: " << device.GetMaximumWorkItemSize() << std::endl
586  << indent << "Maximum work items per group: " << device.GetMaximumWorkItemsPerGroup() << std::endl
587  << indent << "Maximum work items per group: " << device.GetMaximumWorkItemsPerGroup() << std::endl;
588 
589  // Has Image 2D
590  const bool hasImage2D = device.HasImage2D();
591  strm << indent << "Has image 2D: " << ( hasImage2D ? "Yes" : "No" ) << std::endl;
592  if( hasImage2D )
593  {
594  strm << indent << "Maximum image 2D size: " << device.GetMaximumImage2DSize() << std::endl;
595  }
596 
597  // Has Image 3D
598  const bool hasImage3D = device.HasImage3D();
599  strm << indent << "Has image 3D: " << ( hasImage3D ? "Yes" : "No" ) << std::endl;
600  if( hasImage3D )
601  {
602  strm << indent << "Maximum image 3D size: " << device.GetMaximumImage3DSize() << std::endl;
603  }
604 
605  strm << indent << "Has writable image 3D: " << ( device.HasWritableImage3D() ? "Yes" : "No" ) << std::endl
606  << indent << "Maximum samplers: " << device.GetMaximumSamplers() << std::endl
607  << indent << "Maximum read images: " << device.GetMaximumReadImages() << std::endl
608  << indent << "Maximum write images: " << device.GetMaximumWriteImages() << std::endl
609 
610  << indent << "Preferred char vector size: " << device.GetPreferredCharVectorSize() << std::endl
611  << indent << "Preferred short vector size: " << device.GetPreferredShortVectorSize() << std::endl
612  << indent << "Preferred int vector size: " << device.GetPreferredIntVectorSize() << std::endl
613  << indent << "Preferred long vector size: " << device.GetPreferredLongVectorSize() << std::endl
614  << indent << "Preferred float vector size: " << device.GetPreferredFloatVectorSize() << std::endl
615  << indent << "Preferred double vector size: " << device.GetPreferredDoubleVectorSize() << std::endl
616  << indent << "Preferred half float vector size: " << device.GetPreferredHalfFloatVectorSize() << std::endl
617 
618  << indent << "Native char vector size: " << device.GetNativeCharVectorSize() << std::endl
619  << indent << "Native short vector size: " << device.GetNativeShortVectorSize() << std::endl
620  << indent << "Native int vector size: " << device.GetNativeIntVectorSize() << std::endl
621  << indent << "Native long vector size: " << device.GetNativeLongVectorSize() << std::endl
622  << indent << "Native float vector size: " << device.GetNativeFloatVectorSize() << std::endl
623  << indent << "Native double vector size: " << device.GetNativeDoubleVectorSize() << std::endl
624  << indent << "Native half float vector size: " << device.GetNativeHalfFloatVectorSize() << std::endl;
625 
626  strm << indent << "Float capabilities: ";
627  switch( device.GetFloatCapabilities() )
628  {
630  strm << "Not supported"; break;
632  strm << "Denorm"; break;
634  strm << "Infinity nan"; break;
636  strm << "Round nearest"; break;
638  strm << "Round zero"; break;
640  strm << "Round infinity"; break;
642  strm << "Fused multiply add"; break;
643  default:
644  strm << "Unknown"; break;
645  }
646 
647  strm << std::endl << indent << "Double capabilities: ";
648  switch( device.GetDoubleCapabilities() )
649  {
651  strm << "Not supported"; break;
653  strm << "Denorm"; break;
655  strm << "Infinity NaN"; break;
657  strm << "Round nearest"; break;
659  strm << "Round zero"; break;
661  strm << "Round infinity"; break;
663  strm << "Fused multiply add"; break;
664  default:
665  strm << "Unknown"; break;
666  }
667 
668  strm << std::endl << indent << "Half float capabilities: ";
669  switch( device.GetHalfFloatCapabilities() )
670  {
672  strm << "Not supported"; break;
674  strm << "Denorm"; break;
676  strm << "Infinity NaN"; break;
678  strm << "Round nearest"; break;
680  strm << "Round zero"; break;
682  strm << "Round infinity"; break;
684  strm << "Fused multiply add"; break;
685  default:
686  strm << "Unknown"; break;
687  }
688 
689  strm << std::endl << indent << "Profiling timer resolution: " << device.GetProfilingTimerResolution() << std::endl
690  << indent << "Maximum allocation size: " << device.GetMaximumAllocationSize() << std::endl
691  << indent << "Global memory size: " << device.GetGlobalMemorySize() << std::endl;
692 
693  strm << indent << "Global memory cache type: ";
694  switch( device.GetGlobalMemoryCacheType() )
695  {
697  strm << "No cache"; break;
699  strm << "Read only cache"; break;
701  strm << "Read write cache"; break;
702  default:
703  strm << "Unknown"; break;
704  }
705 
706  strm << std::endl << indent << "Global memory cache size: " << device.GetGlobalMemoryCacheSize() << std::endl
707  << indent << "Global memory cache line size: " << device.GetGlobalMemoryCacheLineSize() << std::endl
708  << indent << "Local memory size: " << device.GetLocalMemorySize() << std::endl
709  << indent << "Local memory separated: " << ( device.IsLocalMemorySeparate() ? "Yes" : "No" ) << std::endl
710  << indent << "Maximum constant buffer size: " << device.GetMaximumConstantBufferSize() << std::endl
711  << indent << "Maximum constant arguments: " << device.GetMaximumConstantArguments() << std::endl
712  << indent << "Default alignment: " << device.GetDefaultAlignment() << std::endl
713  << indent << "Minimum alignment: " << device.GetMinimumAlignment() << std::endl
714  << indent << "Maximum parameter bytes: " << device.GetMaximumParameterBytes() << std::endl
715  << indent << "Full profile: " << ( device.IsFullProfile() ? "Yes" : "No" ) << std::endl
716  << indent << "Embedded profile: " << ( device.IsEmbeddedProfile() ? "Yes" : "No" ) << std::endl
717  << indent << "Profile: " << device.GetProfile() << std::endl
718  << indent << "Driver version: " << device.GetDriverVersion() << std::endl
719  << indent << "Name: " << device.GetName() << std::endl
720  << indent << "Vendor: " << device.GetVendor() << std::endl
721  << indent << "Language Version: " << device.GetLanguageVersion() << std::endl;
722 
723  const std::list< std::string > extensions = device.GetExtensions();
724  const std::size_t extensionsSize = extensions.size();
725  strm << indent << "Extensions(" << extensionsSize << "): ";
726  if( extensionsSize == 0 )
727  {
728  strm << "none";
729  }
730  else
731  {
732  strm << std::endl;
733  for( std::list< std::string >::const_iterator it = extensions.begin(); it != extensions.end(); ++it )
734  {
735  strm << indent << indent << "- " << *it << std::endl;
736  }
737  }
738 
739  return strm;
740 }
741 
742 
743 } // end namespace itk
744 
745 #endif /* __itkOpenCLDevice_h */
The OpenCLSize class defines the size of an item of work for an OpenCL kernel.
Definition: itkOpenCLSize.h:49
OpenCLDevice(cl_device_id id)
bool IsNull() const
OpenCLVersion
Definition: itkOpenCL.h:40
OpenCLDevice Self
bool ITKOpenCL_EXPORT operator==(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)
bool ITKOpenCL_EXPORT operator!=(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)
The OpenCLPlatform represent platform model for OpenCL.
The OpenCLDevice class represents the collection of OpenCL devices to be used by the host...
cl_device_id GetDeviceId() const
#define ITKOpenCL_EXPORT


Generated on 04-09-2015 for elastix by doxygen 1.8.9.1 elastix logo