OpenMPCD
SystemInformation.cpp
2 
6 
7 #include <sys/sysinfo.h>
8 #include <unistd.h>
9 
10 using namespace OpenMPCD;
11 
12 const std::string SystemInformation::getHostname()
13 {
14  static const std::size_t bufferSize = HOST_NAME_MAX + 1;
15 
16  char buffer[bufferSize];
17 
18  if(gethostname(buffer, bufferSize) != 0)
19  OPENMPCD_THROW(Exception, "Call to `gethostname` failed.");
20 
21  return buffer;
22 }
23 
25 {
26  struct sysinfo info;
27  if(sysinfo(&info) != 0)
28  OPENMPCD_THROW(Exception, "Call to `sysinfo` failed.");
29 
30  std::size_t ret = info.mem_unit;
31  ret *= info.totalram;
32 
33  return ret;
34 }
35 
36 const std::vector<SystemInformation::CUDADevice> SystemInformation::getCUDADevices()
37 {
38  int deviceCount;
39  cudaGetDeviceCount(&deviceCount);
41 
42  std::vector<CUDADevice> devices;
43  devices.reserve(deviceCount);
44 
45  for(int i=0; i < deviceCount; ++i)
46  {
47  cudaDeviceProp properties;
48  cudaGetDeviceProperties(&properties, i);
50 
51  devices.push_back(CUDADevice());
52  devices.back().name = properties.name;
53  devices.back().globalMemory = properties.totalGlobalMem;
54  }
55 
56  return devices;
57 }
OPENMPCD_CUDA_THROW_ON_ERROR
#define OPENMPCD_CUDA_THROW_ON_ERROR
Throws if the last CUDA call was not successful.
Definition: Macros.hpp:96
Exceptions.hpp
OPENMPCD_THROW
#define OPENMPCD_THROW(ExceptionType, message)
Throws the given ExceptionType, passing the given message along with file and line number information...
Definition: Exceptions.hpp:22
SystemInformation.hpp
OpenMPCD::SystemInformation::CUDADevice
Holds properties of a CUDA device.
Definition: SystemInformation.hpp:24
OpenMPCD::SystemInformation::getHostname
static const std::string getHostname()
Returns the hostname.
Definition: SystemInformation.cpp:12
OpenMPCD::SystemInformation::getCUDADevices
static const std::vector< CUDADevice > getCUDADevices()
Returns a list of cuda devices.
Definition: SystemInformation.cpp:36
Macros.hpp
OpenMPCD::Exception
The base exception class for OpenMPCD.
Definition: Exceptions.hpp:37
OpenMPCD::SystemInformation::getTotalPhysicalMainMemory
static std::size_t getTotalPhysicalMainMemory()
Returns the total number of bytes of physical main memory.
Definition: SystemInformation.cpp:24
runtime.hpp