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 SOCUDADEVICE_H
00024 #define SOCUDADEVICE_H
00025
00026 #include <Inventor/SbVec.h>
00027 #include <Inventor/SoDB.h>
00028
00029 #include <Inventor/cuda/SoCudaDefs.h>
00030 #include <Inventor/devices/SoDevice.h>
00031 #include <Inventor/threads/SbThreadMutex.h>
00032
00033
00034 #include <Inventor/STL/vector>
00035 #include <Inventor/STL/string>
00036
00037 #ifdef _WIN32
00038 #pragma warning( push )
00039 #pragma warning(disable:4251)
00040 #endif
00041
00067 class SoCudaDevice : public SoDevice
00068 {
00069 friend class SoDevice;
00070
00071
00072
00073 public:
00074
00078 static void init();
00079
00083 static bool isInitialized();
00084
00088 static void finish();
00089
00094 static SoCudaDevice* findFirstAvailableDevice();
00095
00101 static SoCudaDevice* getDevice( int index );
00102
00107 static unsigned int getDevicesCount();
00108
00114 virtual unsigned long long getTotalMemory() const;
00115
00119 virtual unsigned long long getAvailableMemory() const;
00120
00125 virtual unsigned int getLogicalUnits() const;
00126
00130 virtual SbString getDriverVersion() const;
00131
00137 float getComputingVersion() const;
00138
00144 virtual SbString getDeviceName() const;
00145
00151 int getCudaDeviceId() const;
00152
00156 void getMaxGridSize( int& x, int& y, int& z ) const;
00157
00161 SbVec3i32 getMaxGridSize() const;
00162
00166 SbVec3i32 getMaxBlockSize() const;
00167
00171 int getMaxThreads() const;
00172
00176 unsigned long long getMaxSharedMemoryPerBlock() const;
00177
00181 unsigned long long getMemPitch() const;
00182
00186 friend std::ostream& operator << ( std::ostream& os, const SoCudaDevice& dev )
00187 {
00188 unsigned long long allocatedMemory, availableMemory;
00189 dev.getMemoryInfo( allocatedMemory, availableMemory );
00190
00191 return os << "[GPU name]: " << dev.m_name.toLatin1() << "\n" << \
00192 "[Driver ver]: " << dev.m_drvVer << "\n" << \
00193 "[Vram size]: " << (dev.m_totalMemory)/(1024*1024) << "MB" << "\n" <<
00194 "[Available Vram size]: " << availableMemory/(1024*1024) << "MB" << "\n" <<
00195 "[LogicalUnits]: " << dev.m_logicalUnits;
00196 }
00197
00198
00199
00200 private:
00201
00205 SoCudaDevice();
00206
00207
00211 virtual ~SoCudaDevice();
00212
00213
00214
00215 private:
00216
00217 static bool findFirstDeviceFunc( SoDevice* device );
00218
00219
00220
00221
00222 private:
00223
00224 void getMemoryInfo( unsigned long long& allocatedMemory, unsigned long long& availableMemory ) const;
00225
00227 unsigned long long m_totalMemory;
00228
00229 unsigned int m_logicalUnits;
00230
00232 float m_computingVersion;
00233
00234
00235 SbString m_drvVer;
00236
00238 unsigned int m_devicePtr;
00239
00241 SbString m_name;
00242
00244 SbVec3i32 m_maxGridSize;
00245
00247 SbVec3i32 m_maxBlockSize;
00248
00250 int m_maxThreadsPerBlock;
00251
00253 unsigned long long m_maxSharedMemoryPerBlock;
00254
00256 unsigned long long m_memPitch;
00257
00259 static std::vector< SoCudaDevice * > s_cudaDevices;
00260
00261
00262 static SbThreadMutex s_initThreadMutex;
00263
00264
00265 static int s_initRefCount;
00266 };
00267
00268 #ifdef _WIN32
00269 #pragma warning( pop )
00270 #endif
00271
00272 #endif // SOCUDADEVICE_H
00273
00274