ALP User Documentation  0.8.preview
Algebraic Programming User Documentation
reference/config.hpp
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2021 Huawei Technologies Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
28 #ifndef _H_GRB_REFERENCE_CONFIG
29 #define _H_GRB_REFERENCE_CONFIG
30 
32 
33 
34 namespace grb {
35 
36  namespace config {
37 
54  enum ALLOC_MODE {
55 
58 
61 
62  };
63 
70  std::string toString( const ALLOC_MODE mode );
71 
96  template< Backend backend >
97  class PREFETCHING {
98 
99  // guard against unintended use
100  static_assert( backend == reference || backend == reference_omp,
101  "Instantiating for non-reference backend" );
102 
103  public:
104 
108  static constexpr bool enabled() {
109  return false;
110  }
111 
117  static constexpr size_t distance() {
118  return 128;
119  }
120 
121  };
122 
139  template<>
141 
142  public:
143 
145  static constexpr ALLOC_MODE defaultAllocMode() {
146  return ALLOC_MODE::ALIGNED;
147  }
148 
150  static constexpr ALLOC_MODE sharedAllocMode() {
151  return ALLOC_MODE::ALIGNED;
152  }
153 
160  static constexpr bool fixedVectorCapacities() {
161  return true;
162  }
163 
172  static constexpr size_t vectorBufferSize( const size_t, const size_t ) {
173  return 0;
174  }
175 
181  static constexpr Backend coordinatesBackend() {
182  return reference;
183  }
184 
185  };
186 
203  template<>
205 
206  private:
207 
214  static constexpr size_t minVectorBufferChunksize() {
215  return CACHE_LINE_SIZE::value();
216  }
217 
232  static constexpr size_t absVectorBufferSize() {
233  return 0;
234  }
235 
252  static constexpr double relVectorBufferSize() {
253  return 1;
254  }
255 
256 
257  public:
258 
263  static constexpr ALLOC_MODE defaultAllocMode() {
264  return ALLOC_MODE::ALIGNED;
265  }
266 
271  static constexpr ALLOC_MODE sharedAllocMode() {
272  // return ALLOC_MODE::ALIGNED; //DBG
274  }
275 
281  static constexpr Backend coordinatesBackend() {
282  return reference_omp;
283  }
284 
291  static constexpr bool fixedVectorCapacities() {
292  return true;
293  }
294 
311  static inline size_t vectorBufferSize( const size_t n, const size_t T ) {
312  size_t ret;
313  if( absVectorBufferSize() > 0 ) {
314  (void)n;
315  ret = absVectorBufferSize();
316  } else {
317  constexpr const double factor = relVectorBufferSize();
318  static_assert( factor > 0, "Configuration error" );
319  ret = factor * n;
320  }
321  ret = std::max( ret, T * minVectorBufferChunksize() );
322  ret += T;
323  if( ret % T > 0 ) {
324  ret += T - ( ret % T );
325  }
326  ret = std::max( 2 * T, ret );
327  assert( ret % T == 0 );
328  return ret;
329  }
330 
331  };
332 
335  } // namespace config
336 
337 } // namespace grb
338 
339 #endif // end ``_H_GRB_REFERENCE_CONFIG''
340 
Allocation via numa_alloc_interleaved.
Definition: reference/config.hpp:60
static constexpr size_t distance()
The prefetch distance used during level-2 and level-3 operations.
Definition: reference/config.hpp:117
static constexpr ALLOC_MODE defaultAllocMode()
A private memory segment shall never be accessed by threads other than the thread who allocates it.
Definition: reference/config.hpp:263
static constexpr ALLOC_MODE sharedAllocMode()
For the reference_omp backend, a shared memory-segment should use interleaved alloc so that any threa...
Definition: reference/config.hpp:271
ALLOC_MODE
The memory allocation modes implemented in the grb::reference and the grb::reference_omp backends.
Definition: reference/config.hpp:54
Collects a series of implementation choices corresponding to some given backend.
Definition: base/config.hpp:387
static constexpr bool enabled()
Whether prefetching is enabled.
Definition: reference/config.hpp:108
The threaded reference implementation.
Definition: backends.hpp:62
The sequential reference implementation.
Definition: backends.hpp:55
Backend
A collection of all backends.
Definition: backends.hpp:49
The ALP/GraphBLAS namespace.
Definition: graphblas.hpp:477
std::string toString(const ALLOC_MODE mode)
Converts instances of grb::config::ALLOC_MODE to a descriptive lower-case string.
static constexpr ALLOC_MODE sharedAllocMode()
How to allocate shared memory segments.
Definition: reference/config.hpp:150
Defines both configuration parameters effective for all backends, as well as defines structured ways ...
Allocation via posix_memalign.
Definition: reference/config.hpp:57
static constexpr ALLOC_MODE defaultAllocMode()
How to allocate private memory segments.
Definition: reference/config.hpp:145
Default prefetching settings for reference and reference_omp backends.
Definition: reference/config.hpp:97