NEURON
mem_layout_util.hpp
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================
7 */
8 
9 #pragma once
10 
11 #include <array>
12 
15 
16 namespace coreneuron {
17 
18 #if !defined(NRN_SOA_PAD)
19 // for layout 0, every range variable array must have a size which
20 // is a multiple of NRN_SOA_PAD doubles
21 #define NRN_SOA_PAD 8
22 #endif
23 
24 /// return the new offset considering the byte aligment settings
25 size_t nrn_soa_byte_align(size_t i);
26 
27 /// This function return the index in a flat array of a matrix coordinate (icnt, isz).
28 /// The matrix size is (cnt, sz)
29 /// Depending of the layout some padding can be calculated
30 int nrn_i_layout(int icnt, int cnt, int isz, int sz, int layout);
31 
32 /// \brief Split a legacy index into the three SoAoS indices.
33 ///
34 /// The legacy index is the AoS of the data, i.e. all values are arranged in a
35 /// table. Different variables and elements of those variables for array
36 /// variables occupy different columns, while different instances occupy
37 /// different rows.
38 ///
39 /// The legacy index is then simply the elements flat (one-dimensional) index
40 /// in that (unpadded) row-major table.
41 ///
42 /// Given this `legacy_index` and `array_dims`, i.e. the number of array
43 /// elements for each variable (1 for regular variables and >= 1 for array
44 /// variables), compute the triplet `(i, j, k)` where `i` is the index of the
45 /// instance, `j` of the variable, and `k` the of array element.
46 std::array<int, 3> legacy2soaos_index(int legacy_index, const std::vector<int>& array_dims);
47 
48 /// \brief Compute the CoreNEURON index given an SoAoS index.
49 ///
50 /// The CoreNEURON index is the index in a flat array starting from a pointer
51 /// pointing to the beginning of the data of that mechanism. Note, that
52 /// CoreNEURON pads to the number of instances.
53 ///
54 /// If `permute` is not null, then the instance index `i` is permuted. Before
55 /// computing before computing the flat index.
56 ///
57 /// Consecutive array elements are always stored consecutively, next fastest
58 /// index is over instances, and the slowest index runs over variables. Note,
59 /// up to padding and permutation of the instances this is the same SoAoS order
60 /// as in NEURON.
61 int soaos2cnrn_index(const std::array<int, 3>& soaos_indices,
62  const std::vector<int>& array_dims,
63  int padded_node_count,
64  int* permute);
65 
66 } // namespace coreneuron
#define cnt
Definition: tqueue.hpp:44
#define i
Definition: md1redef.h:19
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
int soaos2cnrn_index(const std::array< int, 3 > &soaos_indices, const std::vector< int > &array_dims, int padded_node_count, int *permute)
Compute the CoreNEURON index given an SoAoS index.
int nrn_i_layout(int icnt, int cnt, int isz, int sz, int layout)
This function return the index in a flat array of a matrix coordinate (icnt, isz).
std::array< int, 3 > legacy2soaos_index(int legacy_index, const std::vector< int > &array_dims)
Split a legacy index into the three SoAoS indices.
size_t nrn_soa_byte_align(size_t size)
return the new offset considering the byte aligment settings
static int permute(int i, NrnThread &nt)
Definition: prcellstate.cpp:28