![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsOpenCL.hpp 00003 ******************************************************************************/ 00009 /****************************************************************************** 00010 SUKITTI PUNAK (03/23/2011) 00011 UPDATE (07/07/2011) 00012 ******************************************************************************/ 00013 #ifndef TAPs_OPENCL_HPP 00014 #define TAPs_OPENCL_HPP 00015 00016 #include "../Core/TAPsStdLib.hpp" 00017 #include "CL/opencl.h" 00018 00019 00020 BEGIN_NAMESPACE_TAPs__OpenCL 00021 00022 //============================================================================= 00026 //============================================================================= 00027 class OpenCL_Util { 00028 public: 00029 00031 static std::string StrOpenCLErrorCode ( cl_int errCode ); 00032 00034 static bool CheckOpenCLErrorCode ( cl_int errCode ) 00035 #ifdef _DEBUG 00036 { 00037 if ( errCode == CL_SUCCESS ) return true; 00038 std::cerr << StrOpenCLErrorCode( errCode ) << std::endl; 00039 exit( errCode ); 00040 return false; 00041 } 00042 #else //_DEBUG 00043 { 00044 return true; 00045 } 00046 #endif//_DEBUG 00047 00049 static std::string StrOpenCLDeviceTypeCode ( cl_device_type deviceType ); 00050 00051 //============================================================================= 00052 }; // END CLASS OpenCL_Util 00053 //============================================================================= 00054 00055 00056 00057 00058 //============================================================================= 00064 class OpenCL_Device { 00065 //============================================================================= 00066 public: 00067 // Member Functions ------------------------------------------------------- 00069 friend std::ostream & operator<< ( std::ostream &output, OpenCL_Device const &obj ) 00070 { 00071 output << obj.StrInfo(); 00072 return output; 00073 } 00074 00076 OpenCL_Device ( cl_device_id deviceID ); 00077 00079 virtual ~OpenCL_Device (); 00080 00082 virtual std::string StrInfo () const; 00083 00085 cl_platform_id PlatformID () const { return m_PlatformID; } 00087 cl_device_id DeviceID () const { return m_DeviceID; } 00088 00090 std::string DeviceName () const { return m_DeviceName; } 00092 std::string DeviceVendor () const { return m_DeviceVendor; } 00094 std::string DeviceVersion () const { return m_DeviceVersion; } 00095 00097 cl_device_type DeviceType () const { return m_DeviceType; } 00099 cl_uint DeviceMaxComputeUnits () const { return m_DeviceMaxComputeUnits; } 00101 cl_uint DeviceMaxWorkItemDimensions () const { return m_DeviceMaxWorkItemDimensions; } 00103 std::vector< size_t > DeviceMaxWorkItemSizes () const { return m_DeviceMaxWorkItemSizes; } 00105 size_t DeviceMaxWorkItemSizeInDemension ( unsigned int d ) const { return m_DeviceMaxWorkItemSizes[d]; } 00107 size_t DeviceMaxWorkGroupSize () const { return m_DeviceMaxWorkGroupSize; } 00108 00109 //--------------------------------------------------------------- 00110 // Get functions for the OpenCL device info that is not stored in this object 00111 00112 // 00113 // Image 00114 00116 cl_bool DeviceImageSupport () const; 00120 cl_uint DeviceMaxReadImageArguments () const; 00124 cl_uint DeviceMaxWriteImageArguments () const; 00126 size_t DeviceImage2DMaxWidth () const; 00128 size_t DeviceImage2DMaxHeight () const; 00130 size_t DeviceImage3DMaxWidth () const; 00132 size_t DeviceImage3DMaxHeight () const; 00134 size_t DeviceImage3DMaxDepth () const; 00136 cl_uint DeviceMaxSamplers () const; 00137 00138 // 00139 // Mem 00140 00142 cl_uint DeviceAddressBits () const; 00144 cl_uint DeviceMaxClockFrequency () const; 00146 cl_ulong DeviceGlobalMemSize () const; 00148 cl_ulong DeviceLocalMemSize () const; 00150 cl_ulong DeviceMaxMemAllocSize () const; 00154 cl_uint DeviceMemBaseAddrAlign () const; 00158 cl_uint DeviceMinDataAlignSize () const; 00162 cl_device_fp_config DeviceSingleFPConfig () const; 00164 std::string StrOfDeviceSingleFPConfig () const; 00166 cl_device_mem_cache_type DeviceGlobalMemCacheType () const; 00168 std::string OpenCL_Device::StrOfDeviceGlobalMemCacheType () const; 00170 cl_ulong DeviceGlobalMemCacheSize () const; 00172 cl_uint DeviceGlobalMemCachelineSize () const; 00174 cl_device_local_mem_type DeviceLocalMemType () const; 00176 std::string StrOfDeviceLocalMemType () const; 00178 cl_bool DeviceErrCorrectionSupport () const; 00180 cl_bool DeviceHostUnifiedMem () const; 00181 00182 // 00183 // Limitation 00184 00189 size_t DeviceMaxParameterSize () const; 00191 cl_ulong DeviceMaxConstBufferSize () const; 00193 cl_uint DeviceMaxConstArgs () const; 00195 cl_bool DeviceAvailable () const; 00197 cl_bool DeviceEndainLittle () const; 00199 size_t DeviceProfilingTimerResolution () const; 00201 cl_bool DeviceCompilerAvailable () const; 00203 cl_device_exec_capabilities DeviceExecCapabilities () const; 00205 std::string StrOfDeviceExecCapabilities () const; 00207 cl_command_queue_properties DeviceQueueProperties () const; 00209 std::string StrOfDeviceQueueProperties () const; 00211 std::string DeviceExtensions () const; 00212 00213 00214 // 00215 // Misc 00216 00218 cl_uint DeviceVendorID () const; 00220 std::vector< cl_uint > DevicePreferredVectorWidthSizes () const; 00222 std::vector< cl_uint > DeviceNativeVectorWidthSizes () const; 00224 std::string StrOfOpenCLDevicePreferredVectorWidthSizes () const; 00226 std::string StrOfOpenCLDeviceNativeVectorWidthSizes () const; 00227 00228 // Data Members ----------------------------------------------------------- 00229 //============================================================================= 00230 protected: 00231 // Member Functions ------------------------------------------------------- 00232 void GetOpenCLDeviceInfo (); 00233 00234 // Data Members ----------------------------------------------------------- 00235 cl_platform_id m_PlatformID; 00236 cl_device_id m_DeviceID; 00237 00238 std::string m_DeviceName; 00239 std::string m_DeviceVendor; 00240 cl_device_type m_DeviceType; 00241 std::string m_DeviceProfile; 00242 std::string m_DeviceVersion; 00243 std::string m_DeviceOpenCL_C_Version; 00244 00245 cl_uint m_DeviceMaxComputeUnits; 00246 cl_uint m_DeviceMaxWorkItemDimensions; 00247 std::vector< size_t > m_DeviceMaxWorkItemSizes; 00248 size_t m_DeviceMaxWorkGroupSize; 00249 00250 00251 //============================================================================= 00252 private: 00253 // Member Functions ------------------------------------------------------- 00254 // Data Members ----------------------------------------------------------- 00255 //============================================================================= 00256 00257 00258 //============================================================================= 00259 // OpenGL 00260 #if defined(__gl_h_) || defined(__GL_H__) 00261 //----------------------------------------------------------------------------- 00262 public: 00264 //virtual void Draw () const; 00265 //----------------------------------------------------------------------------- 00266 #endif // OpenGL 00267 //============================================================================= 00268 00269 00270 //============================================================================= 00271 }; // END CLASS OpenCL_Device 00272 //============================================================================= 00273 00274 00275 00276 00277 //============================================================================= 00283 class OpenCL_Platform { 00284 //============================================================================= 00285 public: 00286 // Member Functions ------------------------------------------------------- 00288 friend std::ostream & operator<< ( std::ostream &output, OpenCL_Platform const &obj ) 00289 { 00290 output << obj.StrInfo(); 00291 return output; 00292 } 00293 00295 OpenCL_Platform ( cl_platform_id id ); 00296 00298 virtual ~OpenCL_Platform (); 00299 00301 virtual std::string StrInfo () const; 00302 00304 cl_platform_id PlatformID () const { return m_PlatformID; } 00305 00307 std::string PlatformName () const { return m_PlatformName; } 00309 std::string PlatformVersion () const { return m_PlatformVersion; } 00311 std::string PlatformProfile () const { return m_PlatformProfile; } 00313 std::string PlatformVendor () const { return m_PlatformVendor; } 00315 std::string PlatformExtensions () const; 00316 00318 cl_uint NumOfOpenCLDevices () const { return m_OpenCLDeviceIDs.size(); } 00320 cl_device_id OpenCLDeviceID ( cl_uint i ) const { return m_OpenCLDeviceIDs[i]; } 00322 OpenCL_Device const & OpenCLDevice ( cl_uint i ) const { return m_OpenCLDevices[i]; } 00324 OpenCL_Device & OpenCLDevice ( cl_uint i ) { return m_OpenCLDevices[i]; } 00325 00326 00327 // Data Members ----------------------------------------------------------- 00328 //============================================================================= 00329 protected: 00330 // Member Functions ------------------------------------------------------- 00332 void GetOpenCLPlatformInfo (); 00333 00335 void GetListOfOpenCLDevices (); 00336 00337 // Data Members ----------------------------------------------------------- 00338 cl_platform_id m_PlatformID; 00339 00340 std::string m_PlatformName; 00341 std::string m_PlatformVersion; 00342 std::string m_PlatformProfile; 00343 std::string m_PlatformVendor; 00344 00345 std::vector< cl_device_id > m_OpenCLDeviceIDs; 00346 00347 std::vector< OpenCL_Device > m_OpenCLDevices; 00348 //============================================================================= 00349 private: 00350 // Member Functions ------------------------------------------------------- 00351 // Data Members ----------------------------------------------------------- 00352 //============================================================================= 00353 00354 00355 //============================================================================= 00356 // OpenGL 00357 #if defined(__gl_h_) || defined(__GL_H__) 00358 //----------------------------------------------------------------------------- 00359 public: 00361 //virtual void Draw () const; 00362 //----------------------------------------------------------------------------- 00363 #endif // OpenGL 00364 //============================================================================= 00365 00366 00367 //============================================================================= 00368 }; // END CLASS OpenCL_Platform 00369 //============================================================================= 00370 00371 00372 00373 00374 //============================================================================= 00375 END_NAMESPACE_TAPs__OpenCL 00376 //----------------------------------------------------------------------------- 00378 //#include "TAPsOpenCL.cpp" 00379 00381 // Include definition if TAPs_USE_EXPORT is not defined 00382 #if !defined( TAPs_USE_EXPORT ) 00383 #include "TAPsOpenCL.cpp" 00384 #endif 00385 //----------------------------------------------------------------------------- 00386 #endif 00387 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00388 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----