glucat  0.12.0
tuning.h
Go to the documentation of this file.
1 #ifndef GLUCAT_TUNING_H
2 #define GLUCAT_TUNING_H
3 /***************************************************************************
4  GluCat : Generic library of universal Clifford algebra templates
5  tuning.h : Policy classes to control tuning
6  -------------------
7  begin : Sun 2001-12-09
8  copyright : (C) 2001-2021 by Paul C. Leopardi
9  ***************************************************************************
10 
11  This library is free software: you can redistribute it and/or modify
12  it under the terms of the GNU Lesser General Public License as published
13  by the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public License
22  along with this library. If not, see <http://www.gnu.org/licenses/>.
23 
24  ***************************************************************************
25  This library is based on a prototype written by Arvind Raja and was
26  licensed under the LGPL with permission of the author. See Arvind Raja,
27  "Object-oriented implementations of Clifford algebras in C++: a prototype",
28  in Ablamowicz, Lounesto and Parra (eds.)
29  "Clifford algebras with numeric and symbolic computations", Birkhauser, 1996.
30  ***************************************************************************
31  See also Arvind Raja's original header comments in glucat.h
32  ***************************************************************************/
33 
34 // If radix of int is not 2, we can't easily set thresholds
35 _GLUCAT_CTAssert(std::numeric_limits<unsigned int>::radix == 2, CannotSetThresholds)
36 
37 namespace glucat
38 {
40  struct policy{};
41 
43  enum precision_t
44  {
45  precision_demoted,
46  precision_same,
47  precision_promoted
48  };
49 
50  // Tuning policy default constants
51  const unsigned int Tuning_Default_Mult_Matrix_Threshold = 8;
52  const unsigned int Tuning_Default_Div_Max_Steps = 4;
53  const unsigned int Tuning_Default_CR_Sqrt_Max_Steps = 256;
54  const unsigned int Tuning_Default_DB_Sqrt_Max_Steps = 256;
55  const unsigned int Tuning_Default_Log_Max_Outer_Steps = 256;
56  const unsigned int Tuning_Default_Log_Max_Inner_Steps = 32;
57  const unsigned int Tuning_Default_Basis_Max_Count = 12;
58  const unsigned int Tuning_Default_Fast_Size_Threshold = 1 << 6;
59  const unsigned int Tuning_Default_Inv_Fast_Dim_Threshold = 1 << 3;
60  const unsigned int Tuning_Default_Products_Size_Threshold = 1 << 22;
61  const unsigned int Tuning_Default_Denom_Different_Bits = 8;
62  const unsigned int Tuning_Default_Extra_Different_Bits = 8;
63  const precision_t Tuning_Default_Function_Precision = precision_same;
64 
66  template
67  <
68  unsigned int Mult_Matrix_Threshold = Tuning_Default_Mult_Matrix_Threshold,
69  unsigned int Div_Max_Steps = Tuning_Default_Div_Max_Steps,
70  unsigned int CR_Sqrt_Max_Steps = Tuning_Default_CR_Sqrt_Max_Steps,
71  unsigned int DB_Sqrt_Max_Steps = Tuning_Default_DB_Sqrt_Max_Steps,
72  unsigned int Log_Max_Outer_Steps = Tuning_Default_Log_Max_Outer_Steps,
73  unsigned int Log_Max_Inner_Steps = Tuning_Default_Log_Max_Inner_Steps,
74  unsigned int Basis_Max_Count = Tuning_Default_Basis_Max_Count,
75  unsigned int Fast_Size_Threshold = Tuning_Default_Fast_Size_Threshold,
76  unsigned int Inv_Fast_Dim_Threshold = Tuning_Default_Inv_Fast_Dim_Threshold,
77  unsigned int Products_Size_Threshold = Tuning_Default_Products_Size_Threshold,
78  unsigned int Denom_Different_Bits = Tuning_Default_Denom_Different_Bits,
79  unsigned int Extra_Different_Bits = Tuning_Default_Extra_Different_Bits,
80  precision_t Function_Precision = Tuning_Default_Function_Precision
81  >
82  struct tuning : policy
83  {
84  using tune_p = tuning
85  <
86  Mult_Matrix_Threshold,
87  Div_Max_Steps,
88  CR_Sqrt_Max_Steps,
89  DB_Sqrt_Max_Steps,
90  Log_Max_Outer_Steps,
91  Log_Max_Inner_Steps,
92  Basis_Max_Count,
93  Fast_Size_Threshold,
94  Inv_Fast_Dim_Threshold,
95  Products_Size_Threshold,
96  Denom_Different_Bits,
97  Extra_Different_Bits,
98  Function_Precision
99  >;
100  // Tuning for multiplication
102  enum { mult_matrix_threshold = Mult_Matrix_Threshold };
103  // Tuning for division
105  enum { div_max_steps = Div_Max_Steps };
106  // Tuning for sqrt
108  enum { cr_sqrt_max_steps = CR_Sqrt_Max_Steps };
110  enum { db_sqrt_max_steps = DB_Sqrt_Max_Steps };
111  // Tuning for log
113  enum { log_max_outer_steps = Log_Max_Outer_Steps };
115  enum { log_max_inner_steps = Log_Max_Inner_Steps };
116  // Tuning for basis cache
118  enum { basis_max_count = Basis_Max_Count };
119  // Tuning for FFT
121  enum { fast_size_threshold = Fast_Size_Threshold };
123  enum { inv_fast_dim_threshold = Inv_Fast_Dim_Threshold };
124  // Tuning for products (other than geometric product)
126  enum { products_size_threshold = Products_Size_Threshold };
127  // Tuning for precision of exp, log and sqrt functions
129  enum { denom_different_bits = Denom_Different_Bits };
131  enum { extra_different_bits = Extra_Different_Bits };
133  static const precision_t function_precision = Function_Precision;
134  };
135 
136  using tuning_demoted = tuning
137  <
138  Tuning_Default_Mult_Matrix_Threshold,
139  Tuning_Default_Div_Max_Steps,
140  Tuning_Default_CR_Sqrt_Max_Steps,
141  Tuning_Default_DB_Sqrt_Max_Steps,
142  Tuning_Default_Log_Max_Outer_Steps,
143  Tuning_Default_Log_Max_Inner_Steps,
144  Tuning_Default_Basis_Max_Count,
145  Tuning_Default_Fast_Size_Threshold,
146  Tuning_Default_Inv_Fast_Dim_Threshold,
147  Tuning_Default_Products_Size_Threshold,
148  Tuning_Default_Denom_Different_Bits,
149  Tuning_Default_Extra_Different_Bits,
150  precision_demoted
151  >;
152 
153  using tuning_promoted = tuning
154  <
155  Tuning_Default_Mult_Matrix_Threshold,
156  Tuning_Default_Div_Max_Steps,
157  Tuning_Default_CR_Sqrt_Max_Steps,
158  Tuning_Default_DB_Sqrt_Max_Steps,
159  Tuning_Default_Log_Max_Outer_Steps,
160  Tuning_Default_Log_Max_Inner_Steps,
161  Tuning_Default_Basis_Max_Count,
162  Tuning_Default_Fast_Size_Threshold,
163  Tuning_Default_Inv_Fast_Dim_Threshold,
164  Tuning_Default_Products_Size_Threshold,
165  Tuning_Default_Denom_Different_Bits,
166  Tuning_Default_Extra_Different_Bits,
167  precision_promoted
168  >;
169 }
170 
171 #endif // GLUCAT_TUNING_H
_GLUCAT_CTAssert(std::numeric_limits< unsigned int >::radix==2, CannotSetThresholds) namespace glucat
Definition: tuning.h:35