VR-Forces Developer's Guide
 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) 2022 VT-MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
11 #pragma once
12 
13 #include <helper_cuda.h>
14 
15 #include <vrvCore/DtDe.h>
16 
17 namespace makVrv
18 {
21  template <typename T>
22  T DtCheckCuda(T result, char const *const func, const char *const file, int const line, DtDe& de)
23  {
24  if (result)
25  {
26  de.DT_LOG_WARN << "CUDA error at " << file << ":" << line <<
27  "code=" << static_cast<unsigned int>(result) << "(" << _cudaGetErrorEnum(result) <<
28  ") \"" << func << "\"" << std::endl;
29 #ifdef __rhentws8__
30  cudaDeviceReset();
31 #else
32  cudaDeviceReset();
33 #endif
34  // Make sure we call CUDA Device Reset before exiting
35  }
36  return result;
37  }
38 
43 #define DtCheckCudaErrors(val, de) DtCheckCuda((val), #val, __FILE__, __LINE__, de)
44 
47  {
48  int current_device = 0, sm_per_multiproc = 0;
49  int max_perf_device = 0;
50  int device_count = 0, best_SM_arch = 0;
51  int devices_prohibited = 0;
52 
53  uint64_t max_compute_perf = 0;
54  cudaDeviceProp deviceProp;
55  DtCheckCudaErrors(cudaGetDeviceCount(&device_count), de);
56 
57  if (device_count == 0)
58  {
59  de.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  return -1;
62  }
63 
64  // Find the best major SM Architecture GPU device
65  while (current_device < device_count)
66  {
67  cudaGetDeviceProperties(&deviceProp, current_device);
68 
69  // If this GPU is not running on Compute Mode prohibited,
70  // then we can add it to the list
71  if (deviceProp.computeMode != cudaComputeModeProhibited)
72  {
73  if (deviceProp.major > 0 && deviceProp.major < 9999)
74  {
75  best_SM_arch = MAX(best_SM_arch, deviceProp.major);
76  }
77  }
78  else
79  {
80  devices_prohibited++;
81  }
82 
83  current_device++;
84  }
85 
86  if (devices_prohibited == device_count)
87  {
88  de.DT_LOG_WARN << "gpuGetMaxGflopsDeviceId() CUDA error:" <<
89  " all devices have compute mode prohibited." << std::endl;
90  return -1;
91  }
92 
93  // Find the best CUDA capable GPU device
94  current_device = 0;
95 
96  while (current_device < device_count)
97  {
98  cudaGetDeviceProperties(&deviceProp, current_device);
99 
100  // If this GPU is not running on Compute Mode prohibited,
101  // then we can add it to the list
102  if (deviceProp.computeMode != cudaComputeModeProhibited)
103  {
104  if (deviceProp.major == 9999 && deviceProp.minor == 9999)
105  {
106  sm_per_multiproc = 1;
107  }
108  else
109  {
110  sm_per_multiproc =
111  _ConvertSMVer2Cores(deviceProp.major, deviceProp.minor);
112  }
113 
114  uint64_t compute_perf = (uint64_t)deviceProp.multiProcessorCount *
115  sm_per_multiproc * deviceProp.clockRate;
116 
117  if (compute_perf > max_compute_perf)
118  {
119  // If we find GPU with SM major > 2, search only these
120  if (best_SM_arch > 2)
121  {
122  // If our device==dest_SM_arch, choose this, or else pass
123  if (deviceProp.major == best_SM_arch)
124  {
125  max_compute_perf = compute_perf;
126  max_perf_device = current_device;
127  }
128  }
129  else
130  {
131  max_compute_perf = compute_perf;
132  max_perf_device = current_device;
133  }
134  }
135  }
136 
137  ++current_device;
138  }
139 
140  return max_perf_device;
141  }
142 }
Contains makVrv::DtDe class.
#define DtCheckCudaErrors(val, de)
This is exactly the same function as checkCudaErrors() from helper_cuda.h (From NVidia CUDA) except i...
Definition: DtHelperCuda.h:43
int DtGpuGetMaxGflopsDeviceId(DtDe &de)
This function returns the best GPU (with maximum GFLOPS)
Definition: DtHelperCuda.h:46
T DtCheckCuda(T result, char const *const func, const char *const file, int const line, DtDe &de)
This is exactly the same function as check() from helper_cuda.h (From NVidia CUDA) except it does not...
Definition: DtHelperCuda.h:22
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:72
#define MAX(x, y)
{secret}
Definition: trpage_io.h:40

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)