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