00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #if !defined SoOpenCLDEVICE_H
00024 #define SoOpenCLDEVICE_H
00025 
00026 #include <Inventor/SoDB.h>
00027 
00028 #include <Inventor/devices/SoDevice.h>
00029 
00030 #include <Inventor/threads/SbThreadMutex.h>
00031 
00032 #include <Inventor/OpenCL/SoOpenCLDefs.h>
00033 
00034 #include <Inventor/STL/vector>
00035 #include <Inventor/STL/string>
00036 
00037 #include <Inventor/sys/SoCL.h>
00038 
00039 #ifdef _WIN32
00040 #pragma warning( push )
00041 #pragma warning(disable:4251)
00042 #endif
00043 
00069 class INVENTOROPENCL_API SoOpenCLDevice : public SoDevice
00070 {
00071   friend class SoDevice;
00072 
00073   
00074 
00075 public:
00076 
00077 
00082   enum OpenCLDeviceType
00083   {
00084     DEVICE_CPU = 1,
00085     DEVICE_GPU = 2,
00086     DEVICE_ACCELERATOR = 4,
00087     DEVICE_DEFAULT = 8
00088   };
00089 
00093   static void init();
00094 
00098   static bool isInitialized();
00099 
00103   static void finish();
00104 
00109   static SoOpenCLDevice* findFirstAvailableDevice();
00110 
00116   static SoOpenCLDevice* getDevice( int index );
00117 
00122   static unsigned int getDevicesCount();
00123 
00127   OpenCLDeviceType getDeviceType() const;
00128 
00132   SbString getDeviceTypeString() const;
00133 
00139   float getComputingVersion() const;
00140 
00144   virtual unsigned long long getTotalMemory() const;
00145 
00149   virtual unsigned long long getAvailableMemory() const;
00150 
00155   virtual unsigned int getLogicalUnits() const;
00156 
00160   virtual SbString getDriverVersion() const;
00161 
00167   virtual SbString getDeviceName() const;
00168 
00174   cl_device_id getOpenCLDeviceId() const;
00175 
00179   void getMaxWorkItemSizes( int& x, int& y, int& z ) const;
00180 
00184   unsigned long getMaxWorkGroupSize() const;
00185 
00189   unsigned long getMaxMemoryAllocationSize() const;
00190 
00194   friend std::ostream& operator << ( std::ostream& os, const SoOpenCLDevice& dev )
00195   {
00196     return os << "[Device name]: " << dev.m_name.toLatin1() << "\n" <<
00197                  "[Device type ]: " << dev.getDeviceTypeString() << "\n" <<
00198                  "[Driver ver]: " << dev.m_drvVer << "\n" <<
00199                  "[Computing ver]: " << dev.m_computingVersion << "\n" << \
00200                  "[Vram size]: " << (dev.m_totalMemory)/(1024*1024) << "MB" << "\n" << 
00201                  "[Available Vram size]: " << (dev.m_totalMemory)/(1024*1024) << "MB" << "\n" << 
00202                  "[Compute units]: " << dev.getLogicalUnits() << "\n" <<
00203                  "[Max memory allocation size]: " << dev.m_maxMemAllocSize/(1024*1024) << "MB\n" <<
00204                  "[Max work group size]: " << dev.m_maxWorkGroupSize << "\n" <<
00205                  "[Max work items sizes]: " << dev.m_maxWorkItemSizes[0] << " / " <<
00206                  dev.m_maxWorkItemSizes[1] << " / " <<
00207                  dev.m_maxWorkItemSizes[2] << "\n";
00208   }
00209 
00210   
00211 
00212 private:
00213 
00217   SoOpenCLDevice();
00218 
00219 
00223   virtual ~SoOpenCLDevice();
00224 
00225   
00226 
00227 private:
00228 
00229   static bool findFirstDeviceFunc( SoDevice* device );
00230 
00231 
00232   
00233 
00234 private:
00235 
00237   cl_ulong m_totalMemory;
00238 
00240   float m_computingVersion;
00241 
00242   
00243   SbString m_drvVer;
00244 
00246   cl_device_id m_devicePtr;
00247 
00249   OpenCLDeviceType m_deviceType;
00250 
00252   SbString m_name;
00253 
00255   int m_maxWorkItemSizes[ 3 ];
00256 
00258   int m_maxWorkGroupSize;
00259 
00261   unsigned long m_maxMemAllocSize;
00262 
00264   unsigned int m_maxComputeUnits;
00265 
00267   static std::vector< SoOpenCLDevice * > s_openCLDevices;
00268 
00269   
00270   static SbThreadMutex s_initThreadMutex;
00271 
00272   
00273   static int s_initRefCount;
00274 };
00275 
00276 #ifdef _WIN32
00277 #pragma warning( pop )
00278 #endif
00279 
00280 #endif // SoOpenCLDEVICE_H
00281 
00282