GPU Workshop Sample Code
 All Data Structures Namespaces Files Functions Variables Macros Pages
devQuery.cu
Go to the documentation of this file.
1 
11 /*
12  * Copyright 1993-2012 NVIDIA Corporation. All rights reserved.
13  *
14  * Please refer to the NVIDIA end user license agreement (EULA) associated
15  * with this source code for terms and conditions that govern your use of
16  * this software. Any use, reproduction, disclosure, or distribution of
17  * this software and related documentation outside the terms of the EULA
18  * is strictly prohibited.
19  *
20  */
21 
22 
23 #include <memory>
24 #include "../include/mycuda.h"
25 #include "helper_cuda.h"
26 
27 
28 int main()
29 {
30  printf("CUDA Device Query (Runtime API) version (CUDART static linking)\n\n");
31 
32  int deviceCount=0;
33  cudaError_t err = cudaGetDeviceCount(&deviceCount);
34 
35  if (err != cudaSuccess) {
36  printf("cudaGetDeviceCount returned %d\n-> %s\n", (int)err, cudaGetErrorString(err));
37  exit(-1);
38  }
39 
40  if (deviceCount == 0) {
41  printf("There are no available device(s) that support CUDA\n");
42  } else {
43  printf("Detected %d CUDA Capable device(s)\n", deviceCount);
44  }
45 
46  int driverVersion=0, runtimeVersion=0;
47 
48  for (int dev = 0; dev < deviceCount; ++dev)
49  {
50  cudaDeviceProp deviceProp;
51  CUDA_SAFE_CALL( cudaSetDevice(dev) );
52  CUDA_SAFE_CALL( cudaGetDeviceProperties(&deviceProp, dev) );
53 
54  printf("\nDevice %d: \"%s\"\n", dev, deviceProp.name);
55 
56  CUDA_SAFE_CALL( cudaDriverGetVersion(&driverVersion) );
57  CUDA_SAFE_CALL( cudaRuntimeGetVersion(&runtimeVersion ));
58 
59  printf(" CUDA Driver Version / Runtime Version %d.%d / %d.%d\n",
60  driverVersion/1000,
61  (driverVersion%100)/10,
62  runtimeVersion/1000,
63  (runtimeVersion%100)/10);
64  printf(" CUDA Capability Major/Minor version number: %d.%d\n",
65  deviceProp.major,
66  deviceProp.minor);
67  printf(" Total amount of global memory: %.0f MBytes (%llu bytes)\n",
68  (float)deviceProp.totalGlobalMem/1048576.0f,
69  (unsigned long long) deviceProp.totalGlobalMem);
70  printf(" (%2d) Multiprocessors x (%3d) CUDA Cores/MP: %d CUDA Cores\n",
71  deviceProp.multiProcessorCount,
72  _ConvertSMVer2Cores(deviceProp.major, deviceProp.minor),
73  _ConvertSMVer2Cores(deviceProp.major, deviceProp.minor) * deviceProp.multiProcessorCount);
74  printf(" GPU Clock rate: %.0f MHz (%0.2f GHz)\n",
75  deviceProp.clockRate * 1e-3f,
76  deviceProp.clockRate * 1e-6f);
77  printf(" Memory Clock rate: %.0f Mhz\n",
78  deviceProp.memoryClockRate * 1e-3f);
79  printf(" Memory Bus Width: %d-bit\n",
80  deviceProp.memoryBusWidth);
81  printf(" L2 Cache Size: %d bytes\n",
82  deviceProp.l2CacheSize);
83  printf(" Max Texture Dimension Size (x,y,z) 1D=(%d), 2D=(%d,%d), 3D=(%d,%d,%d)\n",
84  deviceProp.maxTexture1D ,
85  deviceProp.maxTexture2D[0],
86  deviceProp.maxTexture2D[1],
87  deviceProp.maxTexture3D[0],
88  deviceProp.maxTexture3D[1],
89  deviceProp.maxTexture3D[2]);
90  printf(" Max Layered Texture Size (dim) x layers 1D=(%d) x %d, 2D=(%d,%d) x %d\n",
91  deviceProp.maxTexture1DLayered[0],
92  deviceProp.maxTexture1DLayered[1],
93  deviceProp.maxTexture2DLayered[0],
94  deviceProp.maxTexture2DLayered[1],
95  deviceProp.maxTexture2DLayered[2]);
96  printf(" Total amount of constant memory: %lu bytes\n",
97  deviceProp.totalConstMem);
98  printf(" Total amount of shared memory per block: %lu bytes\n",
99  deviceProp.sharedMemPerBlock);
100  printf(" Total number of registers available per block: %d\n",
101  deviceProp.regsPerBlock);
102  printf(" Warp size: %d\n",
103  deviceProp.warpSize);
104  printf(" Maximum number of threads per multiprocessor: %d\n",
105  deviceProp.maxThreadsPerMultiProcessor);
106  printf(" Maximum number of threads per block: %d\n",
107  deviceProp.maxThreadsPerBlock);
108  printf(" Maximum sizes of each dimension of a block: %d x %d x %d\n",
109  deviceProp.maxThreadsDim[0],
110  deviceProp.maxThreadsDim[1],
111  deviceProp.maxThreadsDim[2]);
112  printf(" Maximum sizes of each dimension of a grid: %d x %d x %d\n",
113  deviceProp.maxGridSize[0],
114  deviceProp.maxGridSize[1],
115  deviceProp.maxGridSize[2]);
116  printf(" Maximum memory pitch: %lu bytes\n",
117  deviceProp.memPitch);
118  printf(" Texture alignment: %lu bytes\n",
119  deviceProp.textureAlignment);
120  printf(" Concurrent copy and kernel execution: %s with %d copy engine(s)\n",
121  (deviceProp.deviceOverlap ? "Yes" : "No"),
122  deviceProp.asyncEngineCount);
123  printf(" Run time limit on kernels: %s\n",
124  deviceProp.kernelExecTimeoutEnabled ? "Yes" : "No");
125  printf(" Integrated GPU sharing Host Memory: %s\n",
126  deviceProp.integrated ? "Yes" : "No");
127  printf(" Support host page-locked memory mapping: %s\n",
128  deviceProp.canMapHostMemory ? "Yes" : "No");
129  printf(" Alignment requirement for Surfaces: %s\n",
130  deviceProp.surfaceAlignment ? "Yes" : "No");
131  printf(" Device has ECC support: %s\n",
132  deviceProp.ECCEnabled ? "Enabled" : "Disabled");
133  printf(" Device supports Unified Addressing (UVA): %s\n",
134  deviceProp.unifiedAddressing ? "Yes" : "No");
135  printf(" Device PCI Bus ID / PCI location ID: %d / %d\n",
136  deviceProp.pciBusID,
137  deviceProp.pciDeviceID);
138 
139  const char *sComputeMode[] =
140  {
141  "Default (multiple host threads can use ::cudaSetDevice() with device simultaneously)",
142  "Exclusive (only one host thread in one process is able to use ::cudaSetDevice() with this device)",
143  "Prohibited (no host thread can use ::cudaSetDevice() with this device)",
144  "Exclusive Process (many threads in one process is able to use ::cudaSetDevice() with this device)",
145  "Unknown",
146  NULL
147  };
148  printf(" Compute Mode:\n");
149  printf(" < %s >\n", sComputeMode[deviceProp.computeMode]);
150  }
151  exit(0);
152 }