Optimized Belief Propagation (CPU and GPU)
ProcessBpCUDA.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 RUN_BP_STEREO_HOST_HEADER_H
29 #define RUN_BP_STEREO_HOST_HEADER_H
30 
31 #include <cuda_runtime.h>
32 #include <cuda_fp16.h>
37 
46 template<RunData_t T, unsigned int DISP_VALS, run_environment::AccSetting ACCELERATION>
47 class ProcessBpCUDA final : public ProcessBp<T, DISP_VALS, ACCELERATION>
48 {
49 public:
50  explicit ProcessBpCUDA(const ParallelParams& cuda_params) :
51  ProcessBp<T, DISP_VALS, ACCELERATION>(cuda_params) {}
52 
53 private:
63  run_eval::Status InitializeDataCosts(
64  const beliefprop::BpSettings& alg_settings,
65  const BpLevel<T>& current_bp_level,
66  const std::array<float*, 2>& images_target_device,
67  const beliefprop::DataCostsCheckerboards<T*>& data_costs_device) const override;
68 
69  run_eval::Status InitializeDataCurrentLevel(
70  const BpLevel<T>& current_bp_level,
71  const BpLevel<T>& prev_bp_level,
72  const beliefprop::DataCostsCheckerboards<T*>& data_costs_device,
73  const beliefprop::DataCostsCheckerboards<T*>& data_costs_device_write,
74  unsigned int bp_settings_num_disp_vals) const override;
75 
84  run_eval::Status InitializeMessageValsToDefault(
85  const BpLevel<T>& current_bp_level,
86  const beliefprop::CheckerboardMessages<T*>& messages_device,
87  unsigned int bp_settings_num_disp_vals) const override;
88 
100  run_eval::Status RunBPAtCurrentLevel(
101  const beliefprop::BpSettings& alg_settings,
102  const BpLevel<T>& current_bp_level,
103  const beliefprop::DataCostsCheckerboards<T*>& data_costs_device,
104  const beliefprop::CheckerboardMessages<T*>& messages_device,
105  T* allocated_memory) const override;
106 
122  run_eval::Status CopyMessageValuesToNextLevelDown(
123  const BpLevel<T>& current_bp_level,
124  const BpLevel<T>& next_bp_level,
125  const beliefprop::CheckerboardMessages<T*>& messages_device_copy_from,
126  const beliefprop::CheckerboardMessages<T*>& messages_device_copy_to,
127  unsigned int bp_settings_num_disp_vals) const override;
128 
129  float* RetrieveOutputDisparity(
130  const BpLevel<T>& current_bp_level,
131  const beliefprop::DataCostsCheckerboards<T*>& data_costs_device,
132  const beliefprop::CheckerboardMessages<T*>& messages_device,
133  unsigned int bp_settings_num_disp_vals) const override;
134 
135  run_eval::Status ErrorCheck(
136  const char *file = "",
137  int line = 0,
138  bool abort = false) const override;
139 };
140 
141 #endif //RUN_BP_STEREO_HOST_HEADER_H
Declares child class of ParallelParams to store and process parallelization parameters to use in each...
Declares abstract class to run belief propagation on target device. Some of the class functions need ...
Contains namespace with enums and constants for implementation run evaluation.
Define constraints for data type in processing.
Class to store and retrieve properties of a bp processing level including a data type specified as a ...
Definition: BpLevel.h:60
Abstract class for holding and processing parallelization parameters. Child class(es) specific to im...
Child class of ProcessBp that define functions used in processing bp in the CUDA implementation.
Definition: ProcessBpCUDA.h:48
ProcessBpCUDA(const ParallelParams &cuda_params)
Definition: ProcessBpCUDA.h:50
Abstract class to run belief propagation on target device. Some of the class functions need to be ove...
Definition: ProcessBp.h:67
std::array< T, kNumCheckerboardParts > DataCostsCheckerboards
Define alias for two-element array with data costs for each bp processing checkerboard....
std::array< std::array< T, kNumMessageArrays >, kNumCheckerboardParts > CheckerboardMessages
Define alias for array with message costs for each bp processing checkerboard. Each checkerboard mes...
Status
Enum for status to indicate if error or no error.
Structure to store the belief propagation settings including the number of levels and iterations.
Definition: BpSettings.h:87