ALP User Documentation  0.8.preview
Algebraic Programming User Documentation
base/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_CONFIG_BASE
29 #define _H_GRB_CONFIG_BASE
30 
31 #include <cstddef> //size_t
32 #include <string>
33 
34 #include <assert.h>
35 #include <unistd.h> //sysconf
36 
37 #include <graphblas/backends.hpp>
38 
39 #ifndef _GRB_NO_STDIO
40  #include <iostream> //std::cout
41 #endif
42 
43 // if the user did not define _GRB_BACKEND, set it to the default sequential
44 // implementation
45 #ifndef _GRB_BACKEND
46  #define _GRB_BACKEND reference
47 #endif
48 
49 
50 namespace grb {
51 
56  namespace config {
57 
79  static constexpr grb::Backend default_backend = _GRB_BACKEND;
80 
87 
88  private:
89 
94  static constexpr size_t bytes = 64;
95 
96  public:
97 
104  static constexpr size_t value() {
105  return bytes;
106  }
107 
108  };
109 
115  class SIMD_SIZE {
116 
117  private:
118 
123  static constexpr size_t bytes = 64;
124 
125  public:
126 
133  static constexpr size_t value() {
134  return bytes;
135  }
136 
137  };
138 
145  template< typename T >
146  class SIMD_BLOCKSIZE {
147 
148  public:
149 
158  static constexpr size_t unsafe_value() {
159  return SIMD_SIZE::value() / sizeof( T );
160  }
161 
168  static constexpr size_t value() {
169  return unsafe_value() > 0 ? unsafe_value() : 1;
170  }
171 
172  };
173 
185  class HARDWARE_THREADS {
186 
187  public:
188 
200  static long value() {
201  return sysconf( _SC_NPROCESSORS_ONLN );
202  }
203 
204  };
205 
211  class BENCHMARKING {
212 
213  public:
214 
216  static constexpr size_t inner() {
217  return 1;
218  }
219 
221  static constexpr size_t outer() {
222  return 10;
223  }
224 
225  };
226 
232  class MEMORY {
233 
234  public:
235 
237  static constexpr size_t l1_cache_size() {
238  return 32768;
239  }
240 
244  static constexpr size_t big_memory() {
245  return 31;
246  } // 2GB
247 
269  static constexpr double random_access_memspeed() {
270  return 147.298;
271  }
272 
294  static constexpr double stream_memspeed() {
295  return 1931.264;
296  }
297 
305  static bool report(
306  const std::string prefix, const std::string action,
307  const size_t size, const bool printNewline = true
308  ) {
309 #ifdef _GRB_NO_STDIO
310  (void) prefix;
311  (void) action;
312  (void) size;
313  (void) printNewline;
314  return false;
315 #else
316  constexpr size_t big =
317  #ifdef _DEBUG
318  true;
319  #else
320  ( 1ul << big_memory() );
321  #endif
322  if( size >= big ) {
323  std::cout << "Info: ";
324  std::cout << prefix << " ";
325  std::cout << action << " ";
326  if( sizeof( size_t ) * 8 > 40 && ( size >> 40 ) > 2 ) {
327  std::cout << ( size >> 40 ) << " TB of memory";
328  } else if( sizeof( size_t ) * 8 > 30 && ( size >> 30 ) > 2 ) {
329  std::cout << ( size >> 30 ) << " GB of memory";
330  } else if( sizeof( size_t ) * 8 > 20 && ( size >> 20 ) > 2 ) {
331  std::cout << ( size >> 20 ) << " MB of memory";
332  } else if( sizeof( size_t ) * 8 > 10 && ( size >> 10 ) > 2 ) {
333  std::cout << ( size >> 10 ) << " kB of memory";
334  } else {
335  std::cout << size << " bytes of memory";
336  }
337  if( printNewline ) {
338  std::cout << ".\n";
339  }
340  return true;
341  }
342  return false;
343 #endif
344  }
345  };
346 
386  template< grb::Backend backend = default_backend >
388 #ifdef __DOXYGEN__
389  public:
390 
397  static constexpr ALLOC_MODE defaultAllocMode();
398 
405  static constexpr ALLOC_MODE sharedAllocMode();
406 
421  static constexpr bool fixedVectorCapacities();
422 #endif
423  };
424 
436  typedef unsigned int RowIndexType;
437 
449  typedef unsigned int ColIndexType;
450 
462  typedef size_t NonzeroIndexType;
463 
475  typedef unsigned int VectorIndexType;
476 
477  } // namespace config
478 
479 } // namespace grb
480 
481 #endif // end _H_GRB_CONFIG_BASE
482 
The SIMD size, in bytes.
Definition: base/config.hpp:115
unsigned int RowIndexType
What data type should be used to store row indices.
Definition: base/config.hpp:436
This file contains a register of all backends that are either implemented, under implementation,...
static constexpr size_t outer()
Definition: base/config.hpp:221
Benchmarking default configuration parameters.
Definition: base/config.hpp:211
ALLOC_MODE
The memory allocation modes implemented in the grb::reference and the grb::reference_omp backends.
Definition: reference/config.hpp:54
unsigned int ColIndexType
What data type should be used to store column indices.
Definition: base/config.hpp:449
Collects a series of implementation choices corresponding to some given backend.
Definition: base/config.hpp:387
static constexpr size_t inner()
Definition: base/config.hpp:216
unsigned int VectorIndexType
What data type should be used to store vector indices.
Definition: base/config.hpp:475
Backend
A collection of all backends.
Definition: backends.hpp:49
static constexpr size_t l1_cache_size()
Definition: base/config.hpp:237
Contains information about the target architecture cache line size.
Definition: base/config.hpp:86
static constexpr size_t big_memory()
Definition: base/config.hpp:244
The ALP/GraphBLAS namespace.
Definition: graphblas.hpp:477
Memory configuration parameters.
Definition: base/config.hpp:232
static constexpr ALLOC_MODE sharedAllocMode()
Defines how shared memory regions are allocated.
size_t size(const Vector< DataType, backend, Coords > &x) noexcept
Request the size of a given vector.
Definition: io.hpp:235
size_t NonzeroIndexType
What data type should be used to refer to an array containing nonzeroes.
Definition: base/config.hpp:462
static constexpr ALLOC_MODE defaultAllocMode()
Defines how private memory regions are allocated.