Optimized Belief Propagation (CPU and GPU)
RunCUDASettings.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2024 Scott Grauer-Gray
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
29 #ifndef RUN_CUDA_SETTINGS_H_
30 #define RUN_CUDA_SETTINGS_H_
31 
32 #include <vector>
33 #include <array>
34 #include <set>
35 #include "RunEval/RunData.h"
36 
37 //set data type used for half-precision with CUDA
38 #if defined(USE_BFLOAT16_FOR_HALF_PRECISION)
39 #include <cuda_bf16.h>
40 using halftype = __nv_bfloat16;
41 #else
42 #include <cuda_fp16.h>
43 using halftype = half;
44 #endif //USE_BFLOAT16_FOR_HALF_PRECISION
45 
51 namespace run_cuda {
52 
53 constexpr std::string_view kOptimizeCUDADesc{"CUDA"};
54 constexpr std::string_view kCUDAVersionHeader{"Cuda version"};
55 constexpr std::string_view kCUDARuntimeHeader{"Cuda Runtime Version"};
56 
57 inline RunData retrieveDeviceProperties(int num_device)
58 {
59  cudaDeviceProp prop;
60  std::array<int, 2> cuda_version_driver_runtime;
61  cudaGetDeviceProperties(&prop, num_device);
62  cudaDriverGetVersion(&(cuda_version_driver_runtime[0]));
63  cudaRuntimeGetVersion(&(cuda_version_driver_runtime[1]));
64 
65  RunData run_data;
66  run_data.AddDataWHeader(
67  "Device " + std::to_string(num_device),
68  std::string(prop.name) + " with " +
69  std::to_string(prop.multiProcessorCount) +
70  " multiprocessors");
71  run_data.AddDataWHeader(
72  std::string(kCUDAVersionHeader),
73  std::to_string(cuda_version_driver_runtime[0]));
74  run_data.AddDataWHeader(
75  std::string(kCUDARuntimeHeader),
76  std::to_string(cuda_version_driver_runtime[1]));
77  return run_data;
78 }
79 
82 constexpr std::array<unsigned int, 2> kParallelParamsDefault{{32, 4}};
83 
84 #if defined(DEFAULT_PARALLEL_PARAMS_ONLY)
85 
88 const std::set<std::array<unsigned int, 2>> kParallelParameterAltOptions{};
89 
90 #elif defined(LIMITED_ALT_PARALLEL_PARAMS)
91 
96 const std::set<std::array<unsigned int, 2>> kParallelParameterAltOptions{
97  {16, 1}, {32, 4}, {64, 4}};
98 
99 #else
100 
105 const std::set<std::array<unsigned int, 2>> kParallelParameterAltOptions{
106  {16, 1}, {32, 1}, {32, 2}, {32, 3}, {32, 4}, {32, 5},
107  {32, 6}, {32, 8}, {64, 1}, {64, 2}, {64, 3}, {64, 4},
108  {128, 1}, {128, 2}, {256, 1}, {32, 10}, {32, 12}, {32, 14}, {32, 16},
109  {64, 5}, {64, 6}, {64, 7}, {64, 8}, {128, 3}, {128, 4}, {256, 2}};
110 
111 #endif
112 
113 };
114 
115 #endif /* RUN_CUDA_SETTINGS_H_ */
half halftype
Declares class to store headers with data corresponding to current program run and evaluation.
Class to store headers with data corresponding to current program run and evaluation.
Definition: RunData.h:42
void AddDataWHeader(const std::string &header, const std::string &data)
Add string data with header describing added data.
Definition: RunData.cpp:49
Namespace with constants and functions to get CUDA device properties as well as default and test para...
constexpr std::string_view kCUDAVersionHeader
constexpr std::array< unsigned int, 2 > kParallelParamsDefault
Default thread block dimensions (which is what parallel parameters corresponds to in CUDA implementat...
const std::set< std::array< unsigned int, 2 > > kParallelParameterAltOptions
Parallel parameter alternative options to run to retrieve optimized parallel parameters in CUDA imple...
RunData retrieveDeviceProperties(int num_device)
constexpr std::string_view kOptimizeCUDADesc
constexpr std::string_view kCUDARuntimeHeader