Extended CUDA Library (ecuda)  2.0
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
device.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2014-2016, Scott Zuyderduyn
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation
12  and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 The views and conclusions contained in the software and documentation are those
26 of the authors and should not be interpreted as representing official policies,
27 either expressed or implied, of the FreeBSD Project.
28 */
29 
30 //----------------------------------------------------------------------------
31 // device.hpp
32 // Holds information about a CUDA-capable device(s).
33 //
34 // Author: Scott D. Zuyderduyn, Ph.D. (scott.zuyderduyn@utoronto.ca)
35 //----------------------------------------------------------------------------
36 
37 #pragma once
38 #ifndef ECUDA_DEVICE_HPP
39 #define ECUDA_DEVICE_HPP
40 
41 #include <sstream>
42 #include <string>
43 
44 #include "global.hpp"
45 
46 namespace ecuda {
47 
51 class device {
52 
53 private:
54  int deviceNumber;
55  cudaDeviceProp deviceProperties;
56  int driverVersion, runtimeVersion;
57 
58 public:
59  static int get_device_count()
60  {
61  #ifdef __CUDACC__
62  int deviceCount = 0;
63  CUDA_CALL( cudaGetDeviceCount(&deviceCount) );
64  return deviceCount;
65  #else
66  // in CPU emulation mode say 1 and then make
67  // up the details
68  return 1;
69  #endif
70  }
71 
72 public:
73  device( const int deviceNumber ) : deviceNumber(deviceNumber)
74  {
75  CUDA_CALL( cudaGetDeviceProperties(&deviceProperties,deviceNumber) );
76  CUDA_CALL( cudaDriverGetVersion(&driverVersion) );
77  CUDA_CALL( cudaRuntimeGetVersion(&runtimeVersion) );
78  }
79  ~device() {}
80 
81  inline int get_device_number() const { return deviceNumber; }
82  inline int get_driver_version() const { return driverVersion; }
83  inline int get_runtime_version() const { return runtimeVersion; }
84  inline const cudaDeviceProp& get_properties() const { return deviceProperties; }
85 
86  std::string get_driver_version_string() const
87  {
88  std::ostringstream oss;
89  oss << (driverVersion/1000);
90  oss << ".";
91  oss << ((driverVersion%100)/10);
92  return oss.str();
93  }
94 
95  std::string get_runtime_version_string() const
96  {
97  std::ostringstream oss;
98  oss << (runtimeVersion/1000);
99  oss << ".";
100  oss << ((runtimeVersion%100)/10);
101  return oss.str();
102  }
103 
104  void print_summary( std::ostream& output = std::cout )
105  {
106  /*
107  output << "Device " << get_device_number() << ": \"" << deviceProperties.name << "\"" << std::endl;
108  output << " CUDA Driver Version / Runtime Version " << get_driver_version_string() << std::endl;
109  output << " CUDA Capability Major/Minor version number: " << deviceProperties.major << "."<< deviceProperties.minor << std::endl;
110  output << " Total amount of global memory: " << (deviceProperties.totalGlobalMem/1048576.0f) << " (" << deviceProperties.totalGlobalMem << " bytes)" << std::endl;
111  output << " (" << std::setw(2) << deviceProperties.multiProcessorCount << ") Multiprocessors, (" << std::setw(3) <<
112  */
113  #ifdef __CUDACC__
114  output << "name=" << deviceProperties.name << std::endl;
115  output << "totalGlobalMem=" << deviceProperties.totalGlobalMem << std::endl;
116  output << "sharedMemPerBlock=" << deviceProperties.sharedMemPerBlock << std::endl;
117  output << "regsPerBlock=" << deviceProperties.regsPerBlock << std::endl;
118  output << "warpSize=" << deviceProperties.warpSize << std::endl;
119  output << "memPitch=" << deviceProperties.memPitch << std::endl;
120  output << "maxThreadsPerBlock=" << deviceProperties.maxThreadsPerBlock << std::endl;
121  output << "maxThreadsDim=" << deviceProperties.maxThreadsDim[0] << "," << deviceProperties.maxThreadsDim[1] << "," << deviceProperties.maxThreadsDim[2] << std::endl;
122  output << "maxGridSize=" << deviceProperties.maxGridSize[0] << "," << deviceProperties.maxGridSize[1] << "," << deviceProperties.maxGridSize[2] << std::endl;
123  output << "clockRate=" << deviceProperties.clockRate << std::endl;
124  output << "totalConstMem=" << deviceProperties.totalConstMem << std::endl;
125  output << "major=" << deviceProperties.major << std::endl;
126  output << "minor=" << deviceProperties.minor << std::endl;
127  output << "textureAlignment=" << deviceProperties.textureAlignment << std::endl;
128  output << "texturePitchAlignment=" << deviceProperties.texturePitchAlignment << std::endl;
129  output << "deviceOverlap=" << deviceProperties.deviceOverlap << std::endl;
130  output << "multiProcessorCount=" << deviceProperties.multiProcessorCount << std::endl;
131  output << "kernelExecTimeoutEnabled=" << deviceProperties.kernelExecTimeoutEnabled << std::endl;
132  output << "integrated=" << deviceProperties.integrated << std::endl;
133  output << "canMapHostMemory=" << deviceProperties.canMapHostMemory << std::endl;
134  output << "computeMode=" << deviceProperties.computeMode << std::endl;
135  output << "maxTexture1D=" << deviceProperties.maxTexture1D << std::endl;
136  output << "maxTexture1DLinear=" << deviceProperties.maxTexture1DLinear << std::endl;
137  output << "maxTexture2D=" << deviceProperties.maxTexture2D[0] << "," << deviceProperties.maxTexture2D[1] << std::endl;
138  output << "maxTexture2DLinear=" << deviceProperties.maxTexture2DLinear[0] << "," << deviceProperties.maxTexture2DLinear[1] << "," << deviceProperties.maxTexture2DLinear[2] << std::endl;
139  output << "maxTexture2DGather=" << deviceProperties.maxTexture2DGather[0] << "," << deviceProperties.maxTexture2DGather[1] << std::endl;
140  output << "maxTexture3D=" << deviceProperties.maxTexture3D[0] << "," << deviceProperties.maxTexture3D[1] << "," << deviceProperties.maxTexture3D[2] << std::endl;
141  output << "maxTextureCubemap=" << deviceProperties.maxTextureCubemap << std::endl;
142  output << "maxTexture1DLayered=" << deviceProperties.maxTexture1DLayered[0] << "," << deviceProperties.maxTexture1DLayered[1] << std::endl;
143  output << "maxTexture2DLayered=" << deviceProperties.maxTexture2DLayered[0] << "," << deviceProperties.maxTexture2DLayered[1] << "," << deviceProperties.maxTexture2DLayered[2] << std::endl;
144  output << "maxTextureCubemapLayered=" << deviceProperties.maxTextureCubemapLayered[0] << "," << deviceProperties.maxTextureCubemapLayered[1] << std::endl;
145  output << "maxSurface1D=" << deviceProperties.maxSurface1D << std::endl;
146  output << "maxSurface2D=" << deviceProperties.maxSurface2D[0] << "," << deviceProperties.maxSurface2D[1] << std::endl;
147  output << "maxSurface3D=" << deviceProperties.maxSurface3D[0] << "," << deviceProperties.maxSurface3D[1] << "," << deviceProperties.maxSurface3D[2] << std::endl;
148  output << "maxSurface1DLayered=" << deviceProperties.maxSurface1DLayered[0] << "," << deviceProperties.maxSurface1DLayered[1] << std::endl;
149  output << "maxSurface2DLayered=" << deviceProperties.maxSurface2DLayered[0] << "," << deviceProperties.maxSurface2DLayered[1] << "," << deviceProperties.maxSurface2DLayered[2] << std::endl;
150  output << "maxSurfaceCubemap=" << deviceProperties.maxSurfaceCubemap << std::endl;
151  output << "maxSurfaceCubemapLayered=" << deviceProperties.maxSurfaceCubemapLayered[0] << "," << deviceProperties.maxSurfaceCubemapLayered[1] << std::endl;
152  output << "surfaceAlignment=" << deviceProperties.surfaceAlignment << std::endl;
153  output << "concurrentKernels=" << deviceProperties.concurrentKernels << std::endl;
154  output << "ECCEnabled=" << deviceProperties.ECCEnabled << std::endl;
155  output << "pciBusID=" << deviceProperties.pciBusID << std::endl;
156  output << "pciDeviceID=" << deviceProperties.pciDeviceID << std::endl;
157  output << "pciDomainID=" << deviceProperties.pciDomainID << std::endl;
158  output << "tccDriver=" << deviceProperties.tccDriver << std::endl;
159  output << "asyncEngineCount=" << deviceProperties.asyncEngineCount << std::endl;
160  output << "unifiedAddressing=" << deviceProperties.unifiedAddressing << std::endl;
161  output << "memoryClockRate=" << deviceProperties.memoryClockRate << std::endl;
162  output << "memoryBusWidth=" << deviceProperties.memoryBusWidth << std::endl;
163  output << "l2CacheSize=" << deviceProperties.l2CacheSize << std::endl;
164  output << "maxThreadsPerMultiProcessor=" << deviceProperties.maxThreadsPerMultiProcessor << std::endl;
165  #else
166  output << "Not using device, in ecuda host emulation mode." << std::endl;
167  #endif
168 
169  }
170 
171 };
172 
173 } // namespace ecuda
174 
175 #endif
static int get_device_count()
Definition: device.hpp:59
Encapsulates CUDA API device information functions.
Definition: device.hpp:51
#define CUDA_CALL(x)
Definition: global.hpp:83
int get_driver_version() const
Definition: device.hpp:82
int get_device_number() const
Definition: device.hpp:81
void print_summary(std::ostream &output=std::cout)
Definition: device.hpp:104
std::string get_driver_version_string() const
Definition: device.hpp:86
int get_runtime_version() const
Definition: device.hpp:83
const cudaDeviceProp & get_properties() const
Definition: device.hpp:84
std::string get_runtime_version_string() const
Definition: device.hpp:95
device(const int deviceNumber)
Definition: device.hpp:73