NEURON
tnode.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 <vector>
12 
13 // experiment with ordering strategies for Tree Nodes
14 #if CORENRN_BUILD
15 namespace coreneuron {
16 #else
17 namespace neuron {
18 #endif
19 class TNode;
20 
21 using VecTNode = std::vector<TNode*>;
22 
23 /**
24  * \class TNode
25  * \brief TNode is the tree node that represents the tree of the compartments
26  */
27 class TNode {
28  public:
29  TNode(int ix);
30  virtual ~TNode();
33  size_t mkhash(); /// Hash algorith that generates a hash based on the hash of the children and
34  /// the number of compartments of the children
35  size_t hash; /// Hash value generated by mkhash
36  size_t treesize; /// Total number of compartments from the current node and below
37  size_t nodevec_index; /// index in nodevec that is set in check()
38  /// In cell permute 2 this is set as Breadth First traversal
39  size_t treenode_order; /// For cell permute 1 (Interleaved):
40  /// - This is the id given to the compartments based on a Breadth First
41  /// access on the tree that is created in the original circuit
42  /// - This is what makes the cell ordering interleaved
43  /// For cell permute 2 (Constant Depth):
44  /// VVVTN: Vector (groups of cells) of vector (levels of this group of
45  /// cells. Maxsize = maxlevel) of vector of TNodes This changes 3 times
46  /// during cell permute 2:
47  /// 1. According to the sorting of the nodes of each level
48  /// 2. According to the sorting of the parents' treenode_order of the
49  /// previous ordering
50  /// 3. According to children and parents data races. Parents and
51  /// children of the tree are moved by question2() so that threads that
52  /// exist on the same warp don't have data races when updating the
53  /// children and parent variables, so that threads have to wait in
54  /// atomic instructions. If there are any races then those are solved by
55  /// atomic instructions.
56  size_t level; /// level of of this compartment in the tree
57  size_t cellindex; /// Cell ID that this compartment belongs to
58  size_t groupindex; /// Initialized index / groupsize
59  int nodeindex;
60 };
61 
62 size_t level_from_leaf(VecTNode&);
63 size_t level_from_root(VecTNode&);
64 
65 /**
66  * \brief Implementation of the advanced interleaving strategy (interleave_permute_type == 2)
67  *
68  * The main steps are the following:
69  * 1. warp_balance function creates balanced groups of cells.
70  * 2. The compartments/tree nodes populate the groups vector (VVVTN) based on their groupindex and
71  * their level (see level_from_root).
72  * 3. The analyze() & question2() functions (operating per group) make sure that each cell is still
73  * a tree (treenode_order) and that the nodes with same parents belong to separate warps.
74  */
75 void group_order2(VecTNode&, size_t groupsize, size_t ncell);
76 size_t dist2child(TNode* nd);
77 
78 /**
79  * \brief Use of the LPT (Least Processing Time) algorithm to create balanced groups of cells.
80  *
81  * Competing objectives are to keep identical cells together and also balance warps.
82  *
83  * \param ncell number of cells
84  * \param nodevec vector of compartments from all cells
85  * \return number of warps
86  */
87 size_t warp_balance(size_t ncell, VecTNode& nodevec);
88 
89 #define warpsize 32
90 } // namespace coreneuron
TNode is the tree node that represents the tree of the compartments.
Definition: tnode.hpp:27
size_t groupindex
Cell ID that this compartment belongs to.
Definition: tnode.hpp:58
size_t nodevec_index
Total number of compartments from the current node and below.
Definition: tnode.hpp:37
VecTNode children
Definition: tnode.hpp:32
size_t level
For cell permute 1 (Interleaved):
Definition: tnode.hpp:56
size_t treesize
Hash value generated by mkhash.
Definition: tnode.hpp:36
size_t hash
Hash algorith that generates a hash based on the hash of the children and the number of compartments ...
Definition: tnode.hpp:35
size_t cellindex
level of of this compartment in the tree
Definition: tnode.hpp:57
size_t treenode_order
index in nodevec that is set in check() In cell permute 2 this is set as Breadth First traversal
Definition: tnode.hpp:39
TNode * parent
Definition: tnode.hpp:31
int nodeindex
Initialized index / groupsize.
Definition: tnode.hpp:59
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
In mechanism libraries, cannot use auto const token = nrn_ensure_model_data_are_sorted(); because the...
Definition: tnode.hpp:17
icycle< ncycle;++icycle) { int istride=stride[icycle];nrn_pragma_acc(loop vector) nrn_pragma_omp(loop bind(parallel)) for(int icore=0;icore< warpsize;++icore) { int i=ii+icore;if(icore< istride) { int ip=GPU_PARENT(i);GPU_RHS(i) -=GPU_B(i) *GPU_RHS(ip);GPU_RHS(i)/=GPU_D(i);} i+=istride;} ii+=istride;} }}void solve_interleaved2(int ith) { NrnThread *nt=nrn_threads+ith;InterleaveInfo &ii=interleave_info[ith];int nwarp=ii.nwarp;if(nwarp==0) return;int ncore=nwarp *warpsize;int *ncycles=ii.cellsize;int *stridedispl=ii.stridedispl;int *strides=ii.stride;int *rootbegin=ii.firstnode;int *nodebegin=ii.lastnode;if(0) { nrn_pragma_acc(parallel loop gang present(nt[0:1], strides[0:nstride], ncycles[0:nwarp], stridedispl[0:nwarp+1], rootbegin[0:nwarp+1], nodebegin[0:nwarp+1]) async(nt->stream_id)) nrn_pragma_omp(target teams loop map(present, alloc:nt[:1], strides[:nstride], ncycles[:nwarp], stridedispl[:nwarp+1], rootbegin[:nwarp+1], nodebegin[:nwarp+1])) for(int icore=0;icore< ncore;icore+=warpsize) { solve_interleaved2_loop_body(nt, icore, ncycles, strides, stridedispl, rootbegin, nodebegin);} nrn_pragma_acc(wait(nt->stream_id)) } else { for(int icore=0;icore< ncore;icore+=warpsize) { solve_interleaved2_loop_body(nt, icore, ncycles, strides, stridedispl, rootbegin, nodebegin);} }}void solve_interleaved1(int ith) { NrnThread *nt=nrn_threads+ith;int ncell=nt-> ncell
Definition: cellorder.cpp:784
void group_order2(VecTNode &, size_t groupsize, size_t ncell)
Implementation of the advanced interleaving strategy (interleave_permute_type == 2)
Definition: cellorder2.cpp:471
size_t level_from_root(VecTNode &)
Definition: cellorder1.cpp:221
size_t level_from_leaf(VecTNode &)
Definition: cellorder1.cpp:236
size_t warp_balance(size_t ncell, VecTNode &nodevec)
Use of the LPT (Least Processing Time) algorithm to create balanced groups of cells.
Definition: balance.cpp:52
static size_t groupsize
Definition: cellorder1.cpp:43
size_t dist2child(TNode *nd)
Definition: cellorder2.cpp:164
std::vector< TNode * > VecTNode
Definition: tnode.hpp:21