Loading [MathJax]/jax/input/TeX/config.js
CoreNEURON
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mechanism.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 <string.h>
12 
13 #include "coreneuron/nrnconf.h"
15 
16 namespace coreneuron {
17 // OpenACC with PGI compiler has issue when union is used and hence use struct
18 // \todo check if newer PGI versions has resolved this issue
19 #if defined(_OPENACC)
20 struct ThreadDatum {
21  int i;
22  double* pval;
23  void* _pvoid;
24 };
25 #else
26 union ThreadDatum {
27  double val;
28  int i;
29  double* pval;
30  void* _pvoid;
31 };
32 #endif
33 
34 /* will go away at some point */
35 struct Point_process {
37  short _type;
38  short _tid; /* NrnThread id */
39 };
40 
42  int* _displ; /* _displ_cnt + 1 of these */
43  int* _nrb_index; /* _cnt of these (order of increasing _pnt_index) */
44 
45  int* _pnt_index;
47  double* _nrb_t;
48  double* _nrb_flag;
49  int _cnt;
50  int _displ_cnt; /* number of unique _pnt_index */
51  int _size; /* capacity */
53  size_t size_of_object() {
54  size_t nbytes = 0;
55  nbytes += _size * sizeof(int) * 3;
56  nbytes += (_size + 1) * sizeof(int);
57  nbytes += _size * sizeof(double) * 2;
58  return nbytes;
59  }
60 };
61 
63  int* _sendtype; // net_send, net_event, net_move
65  int* _pnt_index;
67  double* _nsb_t;
68  double* _nsb_flag;
69  int _cnt;
70  int _size; /* capacity */
71  int reallocated; /* if buffer resized/reallocated, needs to be copy to cpu */
72 
73  NetSendBuffer_t(int size)
74  : _size(size) {
75  _cnt = 0;
76 
77  _sendtype = (int*) ecalloc_align(_size, sizeof(int));
78  _vdata_index = (int*) ecalloc_align(_size, sizeof(int));
79  _pnt_index = (int*) ecalloc_align(_size, sizeof(int));
80  _weight_index = (int*) ecalloc_align(_size, sizeof(int));
81  // when == 1, NetReceiveBuffer_t is newly allocated (i.e. we need to free previous copy
82  // and recopy new data
83  reallocated = 1;
84  _nsb_t = (double*) ecalloc_align(_size, sizeof(double));
85  _nsb_flag = (double*) ecalloc_align(_size, sizeof(double));
86  }
87 
88  size_t size_of_object() {
89  size_t nbytes = 0;
90  nbytes += _size * sizeof(int) * 4;
91  nbytes += _size * sizeof(double) * 2;
92  return nbytes;
93  }
94 
102  }
103 
104  void grow() {
105 #ifdef CORENEURON_ENABLE_GPU
106  int cannot_reallocate_on_device = 0;
107  assert(cannot_reallocate_on_device);
108 #else
109  int new_size = _size * 2;
110  grow_buf(&_sendtype, _size, new_size);
111  grow_buf(&_vdata_index, _size, new_size);
112  grow_buf(&_pnt_index, _size, new_size);
113  grow_buf(&_weight_index, _size, new_size);
114  grow_buf(&_nsb_t, _size, new_size);
115  grow_buf(&_nsb_flag, _size, new_size);
116  _size = new_size;
117 #endif
118  }
119 
120  private:
121  template <typename T>
122  void grow_buf(T** buf, int size, int new_size) {
123  T* new_buf = nullptr;
124  new_buf = (T*) ecalloc_align(new_size, sizeof(T));
125  memcpy(new_buf, *buf, size * sizeof(T));
126  free(*buf);
127  *buf = new_buf;
128  }
129 };
130 
131 struct Memb_list {
132  /* nodeindices contains all nodes this extension is responsible for,
133  * ordered according to the matrix. This allows to access the matrix
134  * directly via the nrn_actual_* arrays instead of accessing it in the
135  * order of insertion and via the node-structure, making it more
136  * cache-efficient */
137  int* nodeindices = nullptr;
138  int* _permute = nullptr;
139  double* data = nullptr;
140  Datum* pdata = nullptr;
141  ThreadDatum* _thread = nullptr; /* thread specific data (when static is no good) */
144  int nodecount; /* actual node count */
146  void* instance{nullptr}; /* mechanism instance struct */
147  // nrn_acc_manager.cpp handles data movement to/from the accelerator as the
148  // "private constructor" in the translated MOD file code is called before
149  // the main nrn_acc_manager methods that copy thread/mechanism data to the
150  // device
151  void* global_variables{nullptr};
152  std::size_t global_variables_size{};
153 };
154 } // namespace coreneuron
coreneuron::NetSendBuffer_t::~NetSendBuffer_t
~NetSendBuffer_t()
Definition: mechanism.hpp:95
free_memory
void free_memory(void *pointer)
Definition: memory.h:196
coreneuron::Point_process
Definition: mechanism.hpp:35
coreneuron::Datum
int Datum
Definition: nrnconf.h:23
data
Definition: alignment.cpp:18
MemoryManaged
for gpu builds with unified memory support
Definition: memory.h:172
coreneuron::NetSendBuffer_t::grow_buf
void grow_buf(T **buf, int size, int new_size)
Definition: mechanism.hpp:122
coreneuron::ThreadDatum::i
int i
Definition: mechanism.hpp:28
coreneuron::NetReceiveBuffer_t::_displ_cnt
int _displ_cnt
Definition: mechanism.hpp:50
coreneuron::NetSendBuffer_t
Definition: mechanism.hpp:62
coreneuron::NetSendBuffer_t::_size
int _size
Definition: mechanism.hpp:70
coreneuron::Memb_list
Definition: mechanism.hpp:131
coreneuron::NetReceiveBuffer_t::_pnt_index
int * _pnt_index
Definition: mechanism.hpp:45
coreneuron
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
Definition: corenrn_parameters.cpp:12
coreneuron::ThreadDatum::_pvoid
void * _pvoid
Definition: mechanism.hpp:30
coreneuron::NetReceiveBuffer_t::_nrb_index
int * _nrb_index
Definition: mechanism.hpp:43
coreneuron::NetSendBuffer_t::size_of_object
size_t size_of_object()
Definition: mechanism.hpp:88
coreneuron::NetSendBuffer_t::NetSendBuffer_t
NetSendBuffer_t(int size)
Definition: mechanism.hpp:73
coreneuron::NetReceiveBuffer_t
Definition: mechanism.hpp:41
coreneuron::NetSendBuffer_t::_weight_index
int * _weight_index
Definition: mechanism.hpp:66
coreneuron::NetReceiveBuffer_t::_cnt
int _cnt
Definition: mechanism.hpp:49
coreneuron::NetSendBuffer_t::_vdata_index
int * _vdata_index
Definition: mechanism.hpp:64
coreneuron::ThreadDatum::val
double val
Definition: mechanism.hpp:27
coreneuron::NetReceiveBuffer_t::_weight_index
int * _weight_index
Definition: mechanism.hpp:46
coreneuron::NetSendBuffer_t::_pnt_index
int * _pnt_index
Definition: mechanism.hpp:65
coreneuron::Memb_list::instance
void * instance
Definition: mechanism.hpp:146
coreneuron::NetSendBuffer_t::grow
void grow()
Definition: mechanism.hpp:104
coreneuron::NetSendBuffer_t::_nsb_flag
double * _nsb_flag
Definition: mechanism.hpp:68
coreneuron::Memb_list::_net_send_buffer
NetSendBuffer_t * _net_send_buffer
Definition: mechanism.hpp:143
coreneuron::ThreadDatum
Definition: mechanism.hpp:26
coreneuron::Memb_list::nodecount
int nodecount
Definition: mechanism.hpp:144
coreneuron::NetSendBuffer_t::_sendtype
int * _sendtype
Definition: mechanism.hpp:63
coreneuron::Memb_list::_net_receive_buffer
NetReceiveBuffer_t * _net_receive_buffer
Definition: mechanism.hpp:142
coreneuron::ThreadDatum::pval
double * pval
Definition: mechanism.hpp:29
coreneuron::Memb_list::pdata
Datum * pdata
Definition: mechanism.hpp:140
nrnconf.h
coreneuron::Point_process::_type
short _type
Definition: mechanism.hpp:37
coreneuron::NetSendBuffer_t::_nsb_t
double * _nsb_t
Definition: mechanism.hpp:67
coreneuron::NetReceiveBuffer_t::_nrb_flag
double * _nrb_flag
Definition: mechanism.hpp:48
coreneuron::NetSendBuffer_t::_cnt
int _cnt
Definition: mechanism.hpp:69
coreneuron::NetReceiveBuffer_t::size_of_object
size_t size_of_object()
Definition: mechanism.hpp:53
coreneuron::Point_process::_tid
short _tid
Definition: mechanism.hpp:38
coreneuron::Memb_list::_thread
ThreadDatum * _thread
Definition: mechanism.hpp:141
coreneuron::Memb_list::_nodecount_padded
int _nodecount_padded
Definition: mechanism.hpp:145
coreneuron::Memb_list::global_variables_size
std::size_t global_variables_size
Definition: mechanism.hpp:152
coreneuron::NetSendBuffer_t::reallocated
int reallocated
Definition: mechanism.hpp:71
coreneuron::NetReceiveBuffer_t::_pnt_offset
int _pnt_offset
Definition: mechanism.hpp:52
coreneuron::NetReceiveBuffer_t::_displ
int * _displ
Definition: mechanism.hpp:42
coreneuron::ecalloc_align
void * ecalloc_align(size_t n, size_t size, size_t alignment)
coreneuron::NetReceiveBuffer_t::_size
int _size
Definition: mechanism.hpp:51
memory.h
coreneuron::Memb_list::global_variables
void * global_variables
Definition: mechanism.hpp:151
coreneuron::NetReceiveBuffer_t::_nrb_t
double * _nrb_t
Definition: mechanism.hpp:47
coreneuron::Memb_list::nodeindices
int * nodeindices
Definition: mechanism.hpp:137
coreneuron::Memb_list::_permute
int * _permute
Definition: mechanism.hpp:138
coreneuron::Point_process::_i_instance
int _i_instance
Definition: mechanism.hpp:36