-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhwCheck.cpp
133 lines (104 loc) · 3.22 KB
/
hwCheck.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*!
* \file hwCheck.cpp
* \brief checks available hardware (GPUs)
* \author Ville Pitkäkangas, ville.pitkakangas@oulu.fi
* \par Copyright:
* Copyright (c) 2012-2013, University of Oulu.
* All rights reserved.
*/
#include "hwCheck.h"
// TODO: move this to header file. Does some other header already contain this <-> #include <cufft.h>
#include "cuda_runtime.h" // needed for cudaGetDeviceCount() and others
#include <cstdio> // for printf()
#include <cstring> // for memcpy() and memset()
/*
Notice about the CUDA hardware name lengths in this file and
HardwareChecker.cu:
The length is taken from the file "device_types.h" in the CUDA SDK.
It has not been defined there, so the value 256 must be used.
The lines where the length is mentioned in "device_types.h"
(copyright 1993-2012 NVIDIA corporation, all rights reserved):
struct __device_builtin__ cudaDeviceProp
{
char name[256];
...
};
*/
int checkHardware(int &mode, int &devices, int **deviceIDs, char **deviceNames, bool force)
{
//cuInit(0);
int status = 0;
int firstDevice = -1;
int devicesFound = 0;
//int potentialUVADevices = 0, actualUVADevices = 0;
// Find GPU devices.
int gpuDeviceCount = 0;
int deviceCount, device;
struct cudaDeviceProp properties;
cudaError_t cudaResultCode = cudaGetDeviceCount(&deviceCount);
if (cudaResultCode != cudaSuccess)
deviceCount = 0;
/* machines with no GPUs can still report one emulation device */
for (device = 0; device < deviceCount; ++device) {
cudaGetDeviceProperties(&properties, device);
if (properties.major != 9999) /* 9999 means emulation only */
{
if (firstDevice == -1)
firstDevice = device;
++gpuDeviceCount;
}
}
#ifdef _DEBUG
printf("%d GPU CUDA device(s) found\n", gpuDeviceCount);
#endif
int *device_ids = NULL;
if (gpuDeviceCount > 0)
device_ids = new int[gpuDeviceCount];
char *device_names = NULL;
if (gpuDeviceCount > 0)
{
// 256 is defined as maximum length for device name
// (see file driver_types.h in CUDA SDK)
device_names = new char[256 * gpuDeviceCount];
/*device_names = */memset(device_names, 0, 256 * gpuDeviceCount);
}
if (gpuDeviceCount == 0)
{
#ifdef _DEBUG
printf("***WARNING! No CUDA-capable devices found!***\n");
system("pause");
#endif
mode = 0; // no devices
// TODO: create our own static Error states -> new header file
status = -2; // Error
}
else
{
/*
Check device capabilities (most importantly P2P).
*/
for (device = 0; device < deviceCount; ++device) {
#ifdef _DEBUG
if (device == 0)
printf("\n--------------------\n");
#endif
cudaGetDeviceProperties(&properties, device);
if (properties.major != 9999)
{
device_ids[devicesFound++] = device;
// 256 is defined as maximum length for device name
// (see file driver_types.h in CUDA SDK)
strcpy(&device_names[256 * (devicesFound - 1)], properties.name);
// TODO: VS recomends using strcpy_s()
//strcpy_s(&device_names[256 * (devicesFound - 1)], properties.name);
}
#ifdef _DEBUG
printf("Device %d properties:\n", device);
printf("Name: %s\n", properties.name);
printf("CUDA Capability Version: %d.%d\n", properties.major, properties.minor);
printf("TCC? %s\n", properties.tccDriver ? "Yes" : "No");
#endif
}
}
return status;
}