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  case VERSION_2_1:
538  strm << "2.1"; break;
539  default:
540  strm << "Unknown"; break;
541  }
542 
543  strm << std::endl << indent << "Version: " << device.GetVersion() << std::endl;
544 
545  strm << indent << "Device type: ";
546  switch( device.GetDeviceType() )
547  {
549  strm << "Default"; break;
550  case OpenCLDevice::CPU:
551  strm << "CPU"; break;
552  case OpenCLDevice::GPU:
553  strm << "GPU"; break;
555  strm << "Accelerator"; break;
556  case OpenCLDevice::All:
557  strm << "All"; break;
558  default:
559  strm << "Unknown"; break;
560  }
561 
562  // strm << device.GetPlatform() << std::endl;
563  strm << std::endl << indent << "Vendor Id: " << device.GetVendorId() << std::endl
564  << indent << "Available: " << ( device.IsAvailable() ? "Yes" : "No" ) << std::endl
565  << indent << "Has compiler: " << ( device.HasCompiler() ? "Yes" : "No" ) << std::endl
566  << indent << "Has native kernels: " << ( device.HasNativeKernels() ? "Yes" : "No" ) << std::endl
567  << indent << "Has out of order execution: " << ( device.HasOutOfOrderExecution() ? "Yes" : "No" ) << std::endl
568  << indent << "Has double: " << ( device.HasDouble() ? "Yes" : "No" ) << std::endl
569  << indent << "Has half float: " << ( device.HasHalfFloat() ? "Yes" : "No" ) << std::endl
570  << indent << "Has error correcting memory: " << ( device.HasErrorCorrectingMemory() ? "Yes" : "No" ) << std::endl
571  << indent << "Has unified memory: " << ( device.HasUnifiedMemory() ? "Yes" : "No" ) << std::endl
572  << indent << "Compute units: " << device.GetComputeUnits() << std::endl
573  << indent << "Clock frequency: " << device.GetClockFrequency() << std::endl
574  << indent << "Address bits: " << device.GetAddressBits() << std::endl;
575 
576  strm << indent << "Byte order: ";
577  switch( device.GetByteOrder() )
578  {
580  strm << "Big Endian"; break;
582  strm << "Little Endian"; break;
583  default:
584  strm << "Unknown"; break;
585  }
586 
587  strm << std::endl << indent << "Maximum work item size: " << device.GetMaximumWorkItemSize() << std::endl
588  << indent << "Maximum work items per group: " << device.GetMaximumWorkItemsPerGroup() << std::endl
589  << indent << "Maximum work items per group: " << device.GetMaximumWorkItemsPerGroup() << std::endl;
590 
591  // Has Image 2D
592  const bool hasImage2D = device.HasImage2D();
593  strm << indent << "Has image 2D: " << ( hasImage2D ? "Yes" : "No" ) << std::endl;
594  if( hasImage2D )
595  {
596  strm << indent << "Maximum image 2D size: " << device.GetMaximumImage2DSize() << std::endl;
597  }
598 
599  // Has Image 3D
600  const bool hasImage3D = device.HasImage3D();
601  strm << indent << "Has image 3D: " << ( hasImage3D ? "Yes" : "No" ) << std::endl;
602  if( hasImage3D )
603  {
604  strm << indent << "Maximum image 3D size: " << device.GetMaximumImage3DSize() << std::endl;
605  }
606 
607  strm << indent << "Has writable image 3D: " << ( device.HasWritableImage3D() ? "Yes" : "No" ) << std::endl
608  << indent << "Maximum samplers: " << device.GetMaximumSamplers() << std::endl
609  << indent << "Maximum read images: " << device.GetMaximumReadImages() << std::endl
610  << indent << "Maximum write images: " << device.GetMaximumWriteImages() << std::endl
611 
612  << indent << "Preferred char vector size: " << device.GetPreferredCharVectorSize() << std::endl
613  << indent << "Preferred short vector size: " << device.GetPreferredShortVectorSize() << std::endl
614  << indent << "Preferred int vector size: " << device.GetPreferredIntVectorSize() << std::endl
615  << indent << "Preferred long vector size: " << device.GetPreferredLongVectorSize() << std::endl
616  << indent << "Preferred float vector size: " << device.GetPreferredFloatVectorSize() << std::endl
617  << indent << "Preferred double vector size: " << device.GetPreferredDoubleVectorSize() << std::endl
618  << indent << "Preferred half float vector size: " << device.GetPreferredHalfFloatVectorSize() << std::endl
619 
620  << indent << "Native char vector size: " << device.GetNativeCharVectorSize() << std::endl
621  << indent << "Native short vector size: " << device.GetNativeShortVectorSize() << std::endl
622  << indent << "Native int vector size: " << device.GetNativeIntVectorSize() << std::endl
623  << indent << "Native long vector size: " << device.GetNativeLongVectorSize() << std::endl
624  << indent << "Native float vector size: " << device.GetNativeFloatVectorSize() << std::endl
625  << indent << "Native double vector size: " << device.GetNativeDoubleVectorSize() << std::endl
626  << indent << "Native half float vector size: " << device.GetNativeHalfFloatVectorSize() << std::endl;
627 
628  strm << indent << "Float capabilities: ";
629  switch( device.GetFloatCapabilities() )
630  {
632  strm << "Not supported"; break;
634  strm << "Denorm"; break;
636  strm << "Infinity nan"; break;
638  strm << "Round nearest"; break;
640  strm << "Round zero"; break;
642  strm << "Round infinity"; break;
644  strm << "Fused multiply add"; break;
645  default:
646  strm << "Unknown"; break;
647  }
648 
649  strm << std::endl << indent << "Double capabilities: ";
650  switch( device.GetDoubleCapabilities() )
651  {
653  strm << "Not supported"; break;
655  strm << "Denorm"; break;
657  strm << "Infinity NaN"; break;
659  strm << "Round nearest"; break;
661  strm << "Round zero"; break;
663  strm << "Round infinity"; break;
665  strm << "Fused multiply add"; break;
666  default:
667  strm << "Unknown"; break;
668  }
669 
670  strm << std::endl << indent << "Half float capabilities: ";
671  switch( device.GetHalfFloatCapabilities() )
672  {
674  strm << "Not supported"; break;
676  strm << "Denorm"; break;
678  strm << "Infinity NaN"; break;
680  strm << "Round nearest"; break;
682  strm << "Round zero"; break;
684  strm << "Round infinity"; break;
686  strm << "Fused multiply add"; break;
687  default:
688  strm << "Unknown"; break;
689  }
690 
691  strm << std::endl << indent << "Profiling timer resolution: " << device.GetProfilingTimerResolution() << std::endl
692  << indent << "Maximum allocation size: " << device.GetMaximumAllocationSize() << std::endl
693  << indent << "Global memory size: " << device.GetGlobalMemorySize() << std::endl;
694 
695  strm << indent << "Global memory cache type: ";
696  switch( device.GetGlobalMemoryCacheType() )
697  {
699  strm << "No cache"; break;
701  strm << "Read only cache"; break;
703  strm << "Read write cache"; break;
704  default:
705  strm << "Unknown"; break;
706  }
707 
708  strm << std::endl << indent << "Global memory cache size: " << device.GetGlobalMemoryCacheSize() << std::endl
709  << indent << "Global memory cache line size: " << device.GetGlobalMemoryCacheLineSize() << std::endl
710  << indent << "Local memory size: " << device.GetLocalMemorySize() << std::endl
711  << indent << "Local memory separated: " << ( device.IsLocalMemorySeparate() ? "Yes" : "No" ) << std::endl
712  << indent << "Maximum constant buffer size: " << device.GetMaximumConstantBufferSize() << std::endl
713  << indent << "Maximum constant arguments: " << device.GetMaximumConstantArguments() << std::endl
714  << indent << "Default alignment: " << device.GetDefaultAlignment() << std::endl
715  << indent << "Minimum alignment: " << device.GetMinimumAlignment() << std::endl
716  << indent << "Maximum parameter bytes: " << device.GetMaximumParameterBytes() << std::endl
717  << indent << "Full profile: " << ( device.IsFullProfile() ? "Yes" : "No" ) << std::endl
718  << indent << "Embedded profile: " << ( device.IsEmbeddedProfile() ? "Yes" : "No" ) << std::endl
719  << indent << "Profile: " << device.GetProfile() << std::endl
720  << indent << "Driver version: " << device.GetDriverVersion() << std::endl
721  << indent << "Name: " << device.GetName() << std::endl
722  << indent << "Vendor: " << device.GetVendor() << std::endl
723  << indent << "Language Version: " << device.GetLanguageVersion() << std::endl;
724 
725  const std::list< std::string > extensions = device.GetExtensions();
726  const std::size_t extensionsSize = extensions.size();
727  strm << indent << "Extensions(" << extensionsSize << "): ";
728  if( extensionsSize == 0 )
729  {
730  strm << "none";
731  }
732  else
733  {
734  strm << std::endl;
735  for( std::list< std::string >::const_iterator it = extensions.begin(); it != extensions.end(); ++it )
736  {
737  strm << indent << indent << "- " << *it << std::endl;
738  }
739  }
740 
741  return strm;
742 }
743 
744 
745 } // end namespace itk
746 
747 #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)
OpenCLVersion
Definition: itkOpenCL.h:41
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
bool IsNull() const


Generated on OURCE_DATE_EPOCH for elastix by doxygen 1.8.13 elastix logo