ALP User Documentation 0.7.alpha
Algebraic Programming User Documentation
Loading...
Searching...
No Matches
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
34namespace grb {
35
36 namespace config {
37
55
58
61
62 };
63
70 std::string toString( const ALLOC_MODE mode );
71
96 template< Backend backend >
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
131 template<>
132 class IMPLEMENTATION< reference > {
133
134 public:
135
137 static constexpr ALLOC_MODE defaultAllocMode() {
138 return ALLOC_MODE::ALIGNED;
139 }
140
142 static constexpr ALLOC_MODE sharedAllocMode() {
143 return ALLOC_MODE::ALIGNED;
144 }
145
152 static constexpr bool fixedVectorCapacities() {
153 return true;
154 }
155
164 static constexpr size_t vectorBufferSize( const size_t, const size_t ) {
165 return 0;
166 }
167
173 static constexpr Backend coordinatesBackend() {
174 return reference;
175 }
176
177 };
178
187 template<>
188 class IMPLEMENTATION< reference_omp > {
189
190 private:
191
198 static constexpr size_t minVectorBufferChunksize() {
199 return CACHE_LINE_SIZE::value();
200 }
201
216 static constexpr size_t absVectorBufferSize() {
217 return 0;
218 }
219
236 static constexpr double relVectorBufferSize() {
237 return 1;
238 }
239
240
241 public:
242
247 static constexpr ALLOC_MODE defaultAllocMode() {
248 return ALLOC_MODE::ALIGNED;
249 }
250
255 static constexpr ALLOC_MODE sharedAllocMode() {
256 // return ALLOC_MODE::ALIGNED; //DBG
258 }
259
265 static constexpr Backend coordinatesBackend() {
266 return reference_omp;
267 }
268
275 static constexpr bool fixedVectorCapacities() {
276 return true;
277 }
278
295 static inline size_t vectorBufferSize( const size_t n, const size_t T ) {
296 size_t ret;
297 if( absVectorBufferSize() > 0 ) {
298 (void)n;
299 ret = absVectorBufferSize();
300 } else {
301 constexpr const double factor = relVectorBufferSize();
302 static_assert( factor > 0, "Configuration error" );
303 ret = factor * n;
304 }
305 ret = std::max( ret, T * minVectorBufferChunksize() );
306 ret += T;
307 if( ret % T > 0 ) {
308 ret += T - ( ret % T );
309 }
310 ret = std::max( 2 * T, ret );
311 assert( ret % T == 0 );
312 return ret;
313 }
314
315 };
316
319 } // namespace config
320
321} // namespace grb
322
323#endif // end ``_H_GRB_REFERENCE_CONFIG''
324
Defines both configuration parameters effective for all backends, as well as defines structured ways ...
static constexpr ALLOC_MODE defaultAllocMode()
How to allocate private memory segments.
Definition: reference/config.hpp:137
static constexpr ALLOC_MODE sharedAllocMode()
How to allocate shared memory segments.
Definition: reference/config.hpp:142
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:247
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:255
Default prefetching settings for reference and reference_omp backends.
Definition: reference/config.hpp:97
static constexpr size_t distance()
The prefetch distance used during level-2 and level-3 operations.
Definition: reference/config.hpp:117
static constexpr bool enabled()
Whether prefetching is enabled.
Definition: reference/config.hpp:108
Backend
A collection of all backends.
Definition: backends.hpp:46
@ reference
The sequential reference implementation.
Definition: backends.hpp:52
@ reference_omp
The threaded reference implementation.
Definition: backends.hpp:59
std::string toString(const ALLOC_MODE mode)
Converts instances of grb::config::ALLOC_MODE to a descriptive lower-case string.
ALLOC_MODE
The memory allocation modes implemented in the grb::reference and the grb::reference_omp backends.
Definition: reference/config.hpp:54
@ ALIGNED
Allocation via posix_memalign.
Definition: reference/config.hpp:57
@ INTERLEAVED
Allocation via numa_alloc_interleaved.
Definition: reference/config.hpp:60
The ALP/GraphBLAS namespace.
Definition: graphblas.hpp:450