NEURON
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 = 0;
153 };
154 } // namespace coreneuron
for gpu builds with unified memory support
Definition: memory.h:181
char buf[512]
Definition: init.cpp:13
#define assert(ex)
Definition: hocassrt.h:24
void free_memory(void *pointer)
Definition: memory.h:213
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
void * ecalloc_align(size_t n, size_t size, size_t alignment)
int Datum
Definition: nrnconf.h:23
ThreadDatum * _thread
Definition: mechanism.hpp:141
NetSendBuffer_t * _net_send_buffer
Definition: mechanism.hpp:143
std::size_t global_variables_size
Definition: mechanism.hpp:152
NetReceiveBuffer_t * _net_receive_buffer
Definition: mechanism.hpp:142
void grow_buf(T **buf, int size, int new_size)
Definition: mechanism.hpp:122