OpenMPCD
Device.cpp
2 
6 
7 #include <iomanip>
8 #include <sstream>
9 
10 namespace OpenMPCD
11 {
12 namespace CUDA
13 {
14 
16 {
17  cudaGetDevice(&deviceID);
19 
20  cudaGetDeviceProperties(&properties, deviceID);
22 }
23 
24 unsigned int Device::getDeviceCount()
25 {
26  int ret = 0;
27  cudaGetDeviceCount(&ret);
29 
30  OPENMPCD_DEBUG_ASSERT(ret >= 1);
31 
32  return static_cast<unsigned int>(ret);
33 }
34 
35 unsigned int Device::getPCIDomainID() const
36 {
37  OPENMPCD_DEBUG_ASSERT(properties.pciDomainID >= 0);
38 
39  return static_cast<unsigned int>(properties.pciDomainID);
40 }
41 
42 unsigned int Device::getPCIBusID() const
43 {
44  OPENMPCD_DEBUG_ASSERT(properties.pciBusID >= 0);
45 
46  return static_cast<unsigned int>(properties.pciBusID);
47 }
48 
49 unsigned int Device::getPCISlotID() const
50 {
51  OPENMPCD_DEBUG_ASSERT(properties.pciDeviceID >= 0);
52 
53  return static_cast<unsigned int>(properties.pciDeviceID);
54 }
55 
56 const std::string Device::getPCIAddressString() const
57 {
58  std::stringstream ss;
59  ss << std::hex << std::setfill('0');
60  ss << std::setw(4) <<getPCIDomainID() << ":";
61  ss << std::setw(2) <<getPCIBusID() << ":";
62  ss << std::setw(2) <<getPCISlotID();
63 
64  return ss.str();
65 }
66 
67 std::size_t Device::getStackSizePerThread() const
68 {
69  std::size_t ret;
70  if(cudaDeviceGetLimit(&ret, cudaLimitStackSize) != cudaSuccess)
71  OPENMPCD_THROW(Exception, "Failed to get stack size limit.");
72  return ret;
73 }
74 
75 void Device::setStackSizePerThread(const std::size_t value) const
76 {
78 
79  if(cudaDeviceSetLimit(cudaLimitStackSize, value) != cudaSuccess)
80  OPENMPCD_THROW(Exception, "Failed to set stack size limit.");
81 }
82 
83 
84 } //namespace CUDA
85 } //namespace OpenMPCD
OPENMPCD_CUDA_THROW_ON_ERROR
#define OPENMPCD_CUDA_THROW_ON_ERROR
Throws if the last CUDA call was not successful.
Definition: Macros.hpp:96
OpenMPCD::CUDA::Device::getPCIBusID
unsigned int getPCIBusID() const
Returns the PCI Bus ID of this Device.
Definition: Device.cpp:42
OpenMPCD::CUDA::Device::setStackSizePerThread
void setStackSizePerThread(const std::size_t value) const
Sets the stack size, in bytes, per Device thread.
Definition: Device.cpp:75
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
OpenMPCD::CUDA::Exception
Base CUDA exception.
Definition: CUDA/Exceptions.hpp:18
OPENMPCD_DEBUG_ASSERT
#define OPENMPCD_DEBUG_ASSERT(assertion)
Asserts that the given expression evaluates to true, but only if OPENMPCD_DEBUG is defined.
Definition: OPENMPCD_DEBUG_ASSERT.hpp:88
Device.hpp
OpenMPCD::CUDA::Device::getPCIAddressString
const std::string getPCIAddressString() const
Returns a string representing the PCI address.
Definition: Device.cpp:56
OpenMPCD::CUDA::Device::Device
Device()
Represents the CUDA Device active at the moment of this instance's construction on the current thread...
Definition: Device.cpp:15
OpenMPCD::CUDA::Device::getStackSizePerThread
std::size_t getStackSizePerThread() const
Returns the stack size, in bytes, per Device thread.
Definition: Device.cpp:67
OPENMPCD_DEBUG_ASSERT.hpp
OPENMPCD_DEBUG_ASSERT_EXCEPTIONTYPE
#define OPENMPCD_DEBUG_ASSERT_EXCEPTIONTYPE(assertion, ExceptionType)
Definition: OPENMPCD_DEBUG_ASSERT.hpp:76
OpenMPCD::CUDA::Device::getPCIDomainID
unsigned int getPCIDomainID() const
Returns the PCI Domain ID of this Device.
Definition: Device.cpp:35
Macros.hpp
OpenMPCD::CUDA::Device::getDeviceCount
static unsigned int getDeviceCount()
Returns the number of CUDA Devices available.
Definition: Device.cpp:24
OpenMPCD::CUDA::Device::getPCISlotID
unsigned int getPCISlotID() const
Returns the PCI Slot ID (also known as PCI Device ID) of this Device.
Definition: Device.cpp:49
OpenMPCD::InvalidArgumentException
Invalid argument exception.
Definition: Exceptions.hpp:128