Optimized Belief Propagation (CPU and GPU)
ParallelParamsBp.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 
28 #ifndef BP_PARALLEL_PARAMS_H
29 #define BP_PARALLEL_PARAMS_H
30 
31 #include <array>
32 #include <vector>
33 #include <thread>
34 #include <iostream>
35 #include <cmath>
36 #include <string>
39 #include "RunEval/RunData.h"
41 
42 namespace beliefprop {
43  //constant strings for headers and text related to parallel processing
44  constexpr std::string_view kBlurImagesPDimsHeader{"Blur Images Parallel Dimensions"};
45  constexpr std::string_view kInitMValsPDimsHeader{"Init Message Values Parallel Dimensions"};
46  constexpr std::string_view kDataCostsPDimsHeader{"Data Costs Parallel Dimensions"};
47  constexpr std::string_view kBpItersPDimsHeader{"BP Thread Parallel Dimensions"};
48  constexpr std::string_view kCopyToNextLevelPDimsHeader{"Copy Thread Parallel Dimensions"};
49  constexpr std::string_view kCompOutputDispPDimsHeader{"Get Output Disparity Parallel Dimensions"};
50  constexpr std::string_view kLevelText{"Level"};
51 };
52 
57 class ParallelParamsBp final : public ParallelParams {
58 public:
67  explicit ParallelParamsBp(
68  run_environment::OptParallelParamsSetting opt_parallel_params_setting,
69  unsigned int num_levels,
70  const std::array<unsigned int, 2>& default_parallel_dims);
71 
77  void SetParallelDims(
78  const std::array<unsigned int, 2>& parallel_dims) override;
79 
88  const std::array<unsigned int, 2>& p_params_curr_run,
89  const RunData& curr_run_data);
90 
96  void SetOptimizedParams() override;
97 
106  std::array<unsigned int, 2> OptParamsForKernel(
107  const std::array<unsigned int, 2>& kernel_location) const override
108  {
109  return parallel_dims_each_kernel_[kernel_location[0]][kernel_location[1]];
110  }
111 
117  RunData AsRunData() const override;
118 
119 private:
123  const run_environment::OptParallelParamsSetting opt_parallel_params_setting_;
124 
126  const unsigned int num_levels_;
127 
129  std::array<std::vector<std::array<unsigned int, 2>>, beliefprop::kNumKernels>
130  parallel_dims_each_kernel_;
131 
134  std::array<std::vector<std::map<std::array<unsigned int, 2>, double>>,
136  p_params_to_run_time_each_kernel_;
137 };
138 
139 #endif //BP_PARALLEL_PARAMS_H
File with namespace for enums, constants, structures, and functions specific to belief propagation pr...
Declares abstract class for holding and processing parallelization parameters.
Declares class to store headers with data corresponding to current program run and evaluation.
Declares and defines structure that stores settings for current implementation run as well as functio...
Child class of ParallelParams to store and process parallelization parameters to use in each BP kerne...
void AddTestResultsForParallelParams(const std::array< unsigned int, 2 > &p_params_curr_run, const RunData &curr_run_data)
Add results from run with same specified parallel parameters used every parallel component.
void SetParallelDims(const std::array< unsigned int, 2 > &parallel_dims) override
Set parallel parameters for each kernel to the same input dimensions.
RunData AsRunData() const override
Retrieve current parallel parameters as RunData object.
std::array< unsigned int, 2 > OptParamsForKernel(const std::array< unsigned int, 2 > &kernel_location) const override
Get optimized parallel parameters for parallel processing kernel for kernel that is indexed as an arr...
void SetOptimizedParams() override
Retrieve optimized parameters from results across multiple runs with different parallel parameters an...
ParallelParamsBp(run_environment::OptParallelParamsSetting opt_parallel_params_setting, unsigned int num_levels, const std::array< unsigned int, 2 > &default_parallel_dims)
Constructor to set parallel parameters with default dimensions for each kernel.
Abstract class for holding and processing parallelization parameters. Child class(es) specific to im...
Class to store headers with data corresponding to current program run and evaluation.
Definition: RunData.h:42
Namespace for enums, constants, structures, and functions specific to belief propagation processing.
constexpr std::string_view kCompOutputDispPDimsHeader
constexpr std::string_view kInitMValsPDimsHeader
constexpr unsigned int kNumKernels
constexpr std::string_view kDataCostsPDimsHeader
constexpr std::string_view kLevelText
constexpr std::string_view kCopyToNextLevelPDimsHeader
constexpr std::string_view kBlurImagesPDimsHeader
constexpr std::string_view kBpItersPDimsHeader
OptParallelParamsSetting
Enum to specify if optimizing parallel parameters per kernel or using same parallel parameters across...