Optimized Belief Propagation (CPU and GPU)
UtilityFuncts.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 
27 #ifndef UTILITY_FUNCTS_H_
28 #define UTILITY_FUNCTS_H_
29 
31 
32 #if defined(OPTIMIZED_CUDA_RUN)
33 //added in front of function header to indicate that function is device
34 //function to be processed on GPU
35 #define ARCHITECTURE_ADDITION __device__
36 #else
37 #define ARCHITECTURE_ADDITION
38 #endif //OPTIMIZED_CUDA_RUN
39 
43 namespace util_functs {
44 
53 template<RunData_t T, RunData_t U>
55  return data; //by default assume same data type and just return data
56 }
57 
58 template<RunData_t T>
60  return (T)0.0;
61 }
62 
63 template<typename T>
64 requires std::is_arithmetic_v<T>
65 ARCHITECTURE_ADDITION inline T GetMin(T val1, T val2) {
66  return ((val1 < val2) ? val1 : val2);
67 }
68 
69 template<typename T>
70 requires std::is_arithmetic_v<T>
71 ARCHITECTURE_ADDITION inline T GetMax(T val1, T val2) {
72  return ((val1 > val2) ? val1 : val2);
73 }
74 
75 };
76 
77 #endif //UTILITY_FUNCTS_H_
Define constraints for data type in processing.
#define ARCHITECTURE_ADDITION
Definition: UtilityFuncts.h:37
Namespace with utility functions for implementation.
Definition: UtilityFuncts.h:43
requires std::is_arithmetic_v< T > ARCHITECTURE_ADDITION T GetMin(T val1, T val2)
Definition: UtilityFuncts.h:65
ARCHITECTURE_ADDITION U ConvertValToDifferentDataTypeIfNeeded(T data)
T is input type, U is output type.
Definition: UtilityFuncts.h:54
requires std::is_arithmetic_v< T > ARCHITECTURE_ADDITION T GetMax(T val1, T val2)
Definition: UtilityFuncts.h:71
ARCHITECTURE_ADDITION T ZeroVal()
Definition: UtilityFuncts.h:59