VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtHelperCuda.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2018 VT-MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
11 #pragma once
12 
13 #include <helper_cuda.h>
14 
15 namespace makVrv
16 {
18  template <typename T>
19  void DtCheck(T result, char const *const func, const char *const file, int const line, DtDe* theDe)
20  {
21  if (result)
22  {
23  if (theDe != NULL)
24  {
25  theDe->DT_LOG_WARN << "CUDA error at " << file << ":" << line <<
26  "code=" << static_cast<unsigned int>(result) << "(" << _cudaGetErrorEnum(result) <<
27  ") \"" << func << "\"" << std::endl;
28  }
29 #ifdef __rhentws8__
30  cudaDeviceReset();
31 #else
32  DEVICE_RESET
33 #endif
34  // Make sure we call CUDA Device Reset before exiting
35  }
36  }
37 
41 #define DtCheckCudaErrors(val, theDe) DtCheck((val), #val, __FILE__, __LINE__, theDe)
42 
44  inline int DtGpuGetMaxGflopsDeviceId(DtDe* theDe)
45  {
46  int current_device = 0, sm_per_multiproc = 0;
47  int max_perf_device = 0;
48  int device_count = 0, best_SM_arch = 0;
49  int devices_prohibited = 0;
50 
51  uint64_t max_compute_perf = 0;
52  cudaDeviceProp deviceProp;
53  DtCheckCudaErrors(cudaGetDeviceCount(&device_count), theDe);
54 
55  if (device_count == 0)
56  {
57  if (theDe != NULL)
58  {
59  theDe->DT_LOG_WARN << "gpuGetMaxGflopsDeviceId() CUDA error:" <<
60  " no devices supporting CUDA. Try updating your NVidia driver to a more recent one that support the CUDA version of this application." << std::endl;
61  }
62  return -1;
63  }
64 
65  // Find the best major SM Architecture GPU device
66  while (current_device < device_count)
67  {
68  cudaGetDeviceProperties(&deviceProp, current_device);
69 
70  // If this GPU is not running on Compute Mode prohibited,
71  // then we can add it to the list
72  if (deviceProp.computeMode != cudaComputeModeProhibited)
73  {
74  if (deviceProp.major > 0 && deviceProp.major < 9999)
75  {
76  best_SM_arch = MAX(best_SM_arch, deviceProp.major);
77  }
78  }
79  else
80  {
81  devices_prohibited++;
82  }
83 
84  current_device++;
85  }
86 
87  if (devices_prohibited == device_count)
88  {
89  if (theDe != NULL)
90  {
91  theDe->DT_LOG_WARN << "gpuGetMaxGflopsDeviceId() CUDA error:" <<
92  " all devices have compute mode prohibited." << std::endl;
93  }
94  return -1;
95  }
96 
97  // Find the best CUDA capable GPU device
98  current_device = 0;
99 
100  while (current_device < device_count)
101  {
102  cudaGetDeviceProperties(&deviceProp, current_device);
103 
104  // If this GPU is not running on Compute Mode prohibited,
105  // then we can add it to the list
106  if (deviceProp.computeMode != cudaComputeModeProhibited)
107  {
108  if (deviceProp.major == 9999 && deviceProp.minor == 9999)
109  {
110  sm_per_multiproc = 1;
111  }
112  else
113  {
114  sm_per_multiproc =
115  _ConvertSMVer2Cores(deviceProp.major, deviceProp.minor);
116  }
117 
118  uint64_t compute_perf = (uint64_t)deviceProp.multiProcessorCount *
119  sm_per_multiproc * deviceProp.clockRate;
120 
121  if (compute_perf > max_compute_perf)
122  {
123  // If we find GPU with SM major > 2, search only these
124  if (best_SM_arch > 2)
125  {
126  // If our device==dest_SM_arch, choose this, or else pass
127  if (deviceProp.major == best_SM_arch)
128  {
129  max_compute_perf = compute_perf;
130  max_perf_device = current_device;
131  }
132  }
133  else
134  {
135  max_compute_perf = compute_perf;
136  max_perf_device = current_device;
137  }
138  }
139  }
140 
141  ++current_device;
142  }
143 
144  return max_perf_device;
145  }
146 }
void DtCheck(T result, char const *const func, const char *const file, int const line, DtDe *theDe)
This is exactly the same function as check() from helper_cuda.h (From NVidia CUDA) ...
Definition: DtHelperCuda.h:19
#define DtCheckCudaErrors(val, theDe)
This is exactly the same function as checkCudaErrors() from helper_cuda.h (From NVidia CUDA) This wil...
Definition: DtHelperCuda.h:41
int DtGpuGetMaxGflopsDeviceId(DtDe *theDe)
This function returns the best GPU (with maximum GFLOPS)
Definition: DtHelperCuda.h:44
The DtDe is the core component of any VR-Vantage application.
Definition: DtDe.h:69
#define MAX(x, y)
{secret}
Definition: trpage_io.h:40

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)