Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoCpuDevice.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2017 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20
21#if !defined SOCPUDEVICE_H
22#define SOCPUDEVICE_H
23
24#include <Inventor/devices/SoDevice.h>
25
26#include <Inventor/STL/vector>
27#include <Inventor/STL/string>
28#include <Inventor/STL/map>
29
30#include <Inventor/threads/SbThreadMutex.h>
31
32#include <Inventor/SbString.h>
33#include <Inventor/errors/SoDebugError.h>
34
50class SoCpuDevice : public SoDevice
51{
52 friend class SoDevice;
53
54 // ----------------------- Public usage --------------------------------------
55
56public:
57
63 virtual SbString getDeviceName() const;
64
77
79 virtual unsigned long long getTotalMemory() const;
80
84 virtual unsigned long long getAvailableMemory() const;
85
90 virtual SbString getDriverVersion() const { return SbString("0.0"); };
91
94
96 bool isActive() const;
97
99 bool hasMMX() const;
100
102 bool hasSSE() const;
103
105 int getSSELevel() const;
106
113 virtual unsigned int getLogicalUnits() const;
114
123 unsigned int getCacheSize( int cacheLevel ) const;
124
130 static SoCpuDevice* getDevice( int index = 0 );
131
135 static unsigned int getDevicesCount();
136
139
143 static void initClass();
144
148 static void exitClass();
149
153 friend std::ostream& operator << ( std::ostream& os, const SoCpuDevice& dev )
154 {
155 unsigned long long allocatedMem, freeMem;
156 dev.getMemoryInfo( allocatedMem, freeMem );
157
158 return os << "[CPU name]: " << dev.m_name.toLatin1() << "\n" << \
159 "[RAM Size]: " << (dev.m_totalMemory)/(1024*1024) << "MB" << "\n" << // memory size returned in Mbytes.
160 "[Available RAM size]: " << freeMem /(1024*1024) << "MB" << "\n" << // memory size returned in Mbytes.
161 "[Cores number]: " << dev.m_coresCount << "\n" << \
162 "[L1 cache size]: " << dev.m_cacheSize[0]/1024 << "KB\n" << \
163 "[L2 cache size]: " << dev.m_cacheSize[1]/1024 << "KB\n" << \
164 "[L3 cache size]: " << dev.m_cacheSize[2]/1024 << "KB\n" << \
165 "[MMX]: " << (dev.m_hasMMX?"available":"not available") << "\n" << \
166 "[SSE level]: " << dev.m_sseLevel;
167 }
168
169 // ----------------------- Protected usage --------------------------------------
170
171 private:
172 static unsigned int s_sse_alignement;
173
174 // return the total memory used by the caller process
175 virtual unsigned long long getProcessMemory() const;
176
177 // return the peak memory used by the caller process
178 virtual unsigned long long getPeakProcessMemory() const;
179
180private:
181
185 SoCpuDevice();
186
190 virtual ~SoCpuDevice();
191
193 static bool findFirstDeviceFunc( SoDevice* device );
194
196 static bool findDevicesCount( SoDevice* device );
197
198 // ----------------------- Private usage --------------------------------------
199
200private:
201 void getMemoryInfo( unsigned long long& allocatedMem, unsigned long long& freeMem ) const;
202
203 typedef std::map<std::string, unsigned long long> MemInfoMap;
204
206 static void fetchMemInfos( MemInfoMap& memInfo );
207
212 static bool getTotalAndFreeMem( unsigned long long& totalMem, unsigned long long& freeMem );
213
215 unsigned long long m_totalMemory;
216
217 // CPU name
218 SbString m_name;
219
221 ProcessorArchitecture m_architecture;
222
224 bool m_isActive;
225
227 bool m_hasMMX;
228
230 bool m_hasSSE;
231
233 int m_sseLevel;
234
236 unsigned int m_coresCount;
237
239 unsigned int m_cacheSize[3];
240
242 static SbThreadMutex s_initThreadMutex;
243
245 static unsigned int s_processorsCount;
246
248 static int s_initRefCount;
249};
250
251// ----------------------- Inline functions --------------------------------------
252
253inline unsigned long long
255{
256 return m_totalMemory;
257}
258
259//------------------------------------------------------------------------------
262{
263 return m_architecture;
264}
265
266
267//------------------------------------------------------------------------------
268inline bool
270{
271 return m_isActive;
272}
273
274
275//------------------------------------------------------------------------------
276inline bool
278{
279 return m_hasSSE;
280}
281
282
283//------------------------------------------------------------------------------
284inline int
286{
287 return m_sseLevel;
288}
289
290//------------------------------------------------------------------------------
291inline bool
293{
294 return m_hasMMX;
295}
296
297
298//------------------------------------------------------------------------------
299
300#endif // SOCPUDEVICE_H
301
Class for smart character strings.
Definition SbString.h:202
const char * toLatin1() const
Returns the string as a Latin-1/ASCII C string.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> CPU device manag...
Definition SoCpuDevice.h:51
ProcessorArchitecture getArchitecture() const
Returns the architecture of the processor.
static void initClass()
This function detects the CPU available in the system.
virtual SbString getDeviceName() const
Returns the device name.
bool isActive() const
Returns true if the CPU is active in the system.
virtual unsigned int getLogicalUnits() const
Returns the number of cores available on this device.
static unsigned int getDevicesCount()
Returns the total number of cores available in the sytem.
virtual unsigned long long getAvailableMemory() const
Returns the current available memory of this device in bytes.
static SoCpuDevice * getDevice(int index=0)
Returns the SoCpuDevice.
int getSSELevel() const
Returns the SSE instruction level available on this device.
static SoCpuDevice * findFirstAvailableDevice()
Returns the first available device found in the system.
friend std::ostream & operator<<(std::ostream &os, const SoCpuDevice &dev)
Prints information about the device.
bool hasMMX() const
Returns true if MMX instructions are supported on this device.
bool hasSSE() const
Returns if SSE instructions are supported on this device.
ProcessorArchitecture
This enum contains the list of possible architectures for the CPU.
Definition SoCpuDevice.h:69
virtual unsigned long long getTotalMemory() const
Returns the total memory of this device in bytes.
virtual SbString getDriverVersion() const
Returns the driver version of this device.
Definition SoCpuDevice.h:90
static void exitClass()
This function frees the allocated memory.
unsigned int getCacheSize(int cacheLevel) const
Returns the size of the cache on this device in bytes.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract device ...
Definition SoDevice.h:82