Skip to content

Commit

Permalink
References for 'BlueBrain/nmodl#1387'.
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Actions Bot committed Aug 7, 2024
1 parent 9332732 commit 9ebaf08
Show file tree
Hide file tree
Showing 12 changed files with 531 additions and 0 deletions.
1 change: 1 addition & 0 deletions global/neuron/read_only.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ namespace neuron {
int node_id = node_data.nodeindices[id];
auto v = node_data.node_voltages[node_id];
inst.v_unused[id] = v;
inst.x[id] = inst.global->x0;
inst.x[id] = 42.0;
}
}
Expand Down
1 change: 1 addition & 0 deletions global/neuron/thread_newton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ namespace neuron {
int node_id = node_data.nodeindices[id];
auto v = node_data.node_voltages[node_id];
inst.v_unused[id] = v;
inst.X[id] = inst.global->X0;
double total;
inst.X[id] = 0.0;
_thread_vars.c(id) = 42.0;
Expand Down
3 changes: 3 additions & 0 deletions hodgkin_huxley/neuron/hodhux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ namespace neuron {
int node_id = node_data.nodeindices[id];
auto v = node_data.node_voltages[node_id];
inst.v_unused[id] = v;
inst.m[id] = inst.global->m0;
inst.h[id] = inst.global->h0;
inst.n[id] = inst.global->n0;
inst.ena[id] = (*inst.ion_ena[id]);
inst.ek[id] = (*inst.ion_ek[id]);
rates_hodhux(_lmc, inst, id, _ppvar, _thread, nt, v);
Expand Down
2 changes: 2 additions & 0 deletions kinetic/neuron/X2Y.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ namespace neuron {
int node_id = node_data.nodeindices[id];
auto v = node_data.node_voltages[node_id];
inst.v_unused[id] = v;
inst.X[id] = inst.global->X0;
inst.Y[id] = inst.global->Y0;
inst.X[id] = 0.0;
inst.Y[id] = 1.0;
inst.c1[id] = 0.0;
Expand Down
1 change: 1 addition & 0 deletions solve/neuron/cnexp_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ namespace neuron {
int node_id = node_data.nodeindices[id];
auto v = node_data.node_voltages[node_id];
inst.v_unused[id] = v;
inst.x[id] = inst.global->x0;
inst.x[id] = 42.0;
(inst.s+id*2)[static_cast<int>(0)] = 0.1;
(inst.s+id*2)[static_cast<int>(1)] = -1.0;
Expand Down
1 change: 1 addition & 0 deletions solve/neuron/cnexp_scalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ namespace neuron {
int node_id = node_data.nodeindices[id];
auto v = node_data.node_voltages[node_id];
inst.v_unused[id] = v;
inst.x[id] = inst.global->x0;
inst.x[id] = 42.0;
}
}
Expand Down
1 change: 1 addition & 0 deletions solve/neuron/derivimplicit_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ namespace neuron {
int node_id = node_data.nodeindices[id];
auto v = node_data.node_voltages[node_id];
inst.v_unused[id] = v;
inst.x[id] = inst.global->x0;
inst.x[id] = 42.0;
(inst.s+id*2)[static_cast<int>(0)] = 0.1;
(inst.s+id*2)[static_cast<int>(1)] = -1.0;
Expand Down
1 change: 1 addition & 0 deletions solve/neuron/derivimplicit_scalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ namespace neuron {
int node_id = node_data.nodeindices[id];
auto v = node_data.node_voltages[node_id];
inst.v_unused[id] = v;
inst.x[id] = inst.global->x0;
inst.x[id] = 42.0;
}
}
Expand Down
1 change: 1 addition & 0 deletions spike_travel/neuron/expsyn2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ namespace neuron {
int node_id = node_data.nodeindices[id];
auto v = node_data.node_voltages[node_id];
inst.v_unused[id] = v;
inst.g[id] = inst.global->g0;
inst.g[id] = 0.0;
}
}
Expand Down
3 changes: 3 additions & 0 deletions spike_travel/neuron/hodhux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ namespace neuron {
int node_id = node_data.nodeindices[id];
auto v = node_data.node_voltages[node_id];
inst.v_unused[id] = v;
inst.m[id] = inst.global->m0;
inst.h[id] = inst.global->h0;
inst.n[id] = inst.global->n0;
inst.ena[id] = (*inst.ion_ena[id]);
inst.ek[id] = (*inst.ion_ek[id]);
rates_hodhux(_lmc, inst, id, _ppvar, _thread, nt, v);
Expand Down
270 changes: 270 additions & 0 deletions state/coreneuron/default_values.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
/*********************************************************
Model Name : default_values
Filename : default_values.mod
NMODL Version : 7.7.0
Vectorized : true
Threadsafe : true
Created : DATE
Simulator : CoreNEURON
Backend : C++ (api-compatibility)
NMODL Compiler : VERSION
*********************************************************/

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <coreneuron/gpu/nrn_acc_manager.hpp>
#include <coreneuron/mechanism/mech/mod2c_core_thread.hpp>
#include <coreneuron/mechanism/register_mech.hpp>
#include <coreneuron/nrnconf.h>
#include <coreneuron/nrniv/nrniv_decl.h>
#include <coreneuron/sim/multicore.hpp>
#include <coreneuron/sim/scopmath/newton_thread.hpp>
#include <coreneuron/utils/ivocvect.hpp>
#include <coreneuron/utils/nrnoc_aux.hpp>
#include <coreneuron/utils/randoms/nrnran123.h>


namespace coreneuron {
#ifndef NRN_PRCELLSTATE
#define NRN_PRCELLSTATE 0
#endif


/** channel information */
static const char *mechanism_info[] = {
"7.7.0",
"default_values",
0,
0,
"X_default_values",
"Y_default_values",
"Z_default_values",
0,
0
};


/** all global variables */
struct default_values_Store {
double Y0{};
int reset{};
int mech_type{};
double X0{2};
double Z0{3};
};
static_assert(std::is_trivially_copy_constructible_v<default_values_Store>);
static_assert(std::is_trivially_move_constructible_v<default_values_Store>);
static_assert(std::is_trivially_copy_assignable_v<default_values_Store>);
static_assert(std::is_trivially_move_assignable_v<default_values_Store>);
static_assert(std::is_trivially_destructible_v<default_values_Store>);
default_values_Store default_values_global;


/** all mechanism instance variables and global variables */
struct default_values_Instance {
double* X{};
double* Y{};
double* Z{};
double* DX{};
double* DY{};
double* DZ{};
double* v_unused{};
default_values_Store* global{&default_values_global};
};


/** connect global (scalar) variables to hoc -- */
static DoubScal hoc_scalar_double[] = {
{"X0_default_values", &default_values_global.X0},
{"Z0_default_values", &default_values_global.Z0},
{nullptr, nullptr}
};


/** connect global (array) variables to hoc -- */
static DoubVec hoc_vector_double[] = {
{nullptr, nullptr, 0}
};


static inline int first_pointer_var_index() {
return -1;
}


static inline int first_random_var_index() {
return -1;
}


static inline int float_variables_size() {
return 7;
}


static inline int int_variables_size() {
return 0;
}


static inline int get_mech_type() {
return default_values_global.mech_type;
}


static inline Memb_list* get_memb_list(NrnThread* nt) {
if (!nt->_ml_list) {
return nullptr;
}
return nt->_ml_list[get_mech_type()];
}


static inline void* mem_alloc(size_t num, size_t size, size_t alignment = 16) {
void* ptr;
posix_memalign(&ptr, alignment, num*size);
memset(ptr, 0, size);
return ptr;
}


static inline void mem_free(void* ptr) {
free(ptr);
}


static inline void coreneuron_abort() {
abort();
}

// Allocate instance structure
static void nrn_private_constructor_default_values(NrnThread* nt, Memb_list* ml, int type) {
assert(!ml->instance);
assert(!ml->global_variables);
assert(ml->global_variables_size == 0);
auto* const inst = new default_values_Instance{};
assert(inst->global == &default_values_global);
ml->instance = inst;
ml->global_variables = inst->global;
ml->global_variables_size = sizeof(default_values_Store);
}

// Deallocate the instance structure
static void nrn_private_destructor_default_values(NrnThread* nt, Memb_list* ml, int type) {
auto* const inst = static_cast<default_values_Instance*>(ml->instance);
assert(inst);
assert(inst->global);
assert(inst->global == &default_values_global);
assert(inst->global == ml->global_variables);
assert(ml->global_variables_size == sizeof(default_values_Store));
delete inst;
ml->instance = nullptr;
ml->global_variables = nullptr;
ml->global_variables_size = 0;
}

/** initialize mechanism instance variables */
static inline void setup_instance(NrnThread* nt, Memb_list* ml) {
auto* const inst = static_cast<default_values_Instance*>(ml->instance);
assert(inst);
assert(inst->global);
assert(inst->global == &default_values_global);
assert(inst->global == ml->global_variables);
assert(ml->global_variables_size == sizeof(default_values_Store));
int pnodecount = ml->_nodecount_padded;
Datum* indexes = ml->pdata;
inst->X = ml->data+0*pnodecount;
inst->Y = ml->data+1*pnodecount;
inst->Z = ml->data+2*pnodecount;
inst->DX = ml->data+3*pnodecount;
inst->DY = ml->data+4*pnodecount;
inst->DZ = ml->data+5*pnodecount;
inst->v_unused = ml->data+6*pnodecount;
}



static void nrn_alloc_default_values(double* data, Datum* indexes, int type) {
// do nothing
}


void nrn_constructor_default_values(NrnThread* nt, Memb_list* ml, int type) {
#ifndef CORENEURON_BUILD
int nodecount = ml->nodecount;
int pnodecount = ml->_nodecount_padded;
const int* node_index = ml->nodeindices;
double* data = ml->data;
const double* voltage = nt->_actual_v;
Datum* indexes = ml->pdata;
ThreadDatum* thread = ml->_thread;
auto* const inst = static_cast<default_values_Instance*>(ml->instance);

#endif
}


void nrn_destructor_default_values(NrnThread* nt, Memb_list* ml, int type) {
#ifndef CORENEURON_BUILD
int nodecount = ml->nodecount;
int pnodecount = ml->_nodecount_padded;
const int* node_index = ml->nodeindices;
double* data = ml->data;
const double* voltage = nt->_actual_v;
Datum* indexes = ml->pdata;
ThreadDatum* thread = ml->_thread;
auto* const inst = static_cast<default_values_Instance*>(ml->instance);

#endif
}


/** initialize channel */
void nrn_init_default_values(NrnThread* nt, Memb_list* ml, int type) {
int nodecount = ml->nodecount;
int pnodecount = ml->_nodecount_padded;
const int* node_index = ml->nodeindices;
double* data = ml->data;
const double* voltage = nt->_actual_v;
Datum* indexes = ml->pdata;
ThreadDatum* thread = ml->_thread;

setup_instance(nt, ml);
auto* const inst = static_cast<default_values_Instance*>(ml->instance);

if (_nrn_skip_initmodel == 0) {
#pragma omp simd
#pragma ivdep
for (int id = 0; id < nodecount; id++) {
int node_id = node_index[id];
double v = voltage[node_id];
#if NRN_PRCELLSTATE
inst->v_unused[id] = v;
#endif
inst->X[id] = inst->global->X0;
inst->Y[id] = inst->global->Y0;
inst->Z[id] = inst->global->Z0;
}
}
}


/** register channel with the simulator */
void _default_values_reg() {

int mech_type = nrn_get_mechtype("default_values");
default_values_global.mech_type = mech_type;
if (mech_type == -1) {
return;
}

_nrn_layout_reg(mech_type, 0);
register_mech(mechanism_info, nrn_alloc_default_values, nullptr, nullptr, nullptr, nrn_init_default_values, nrn_private_constructor_default_values, nrn_private_destructor_default_values, first_pointer_var_index(), 1);

hoc_register_prop_size(mech_type, float_variables_size(), int_variables_size());
hoc_register_var(hoc_scalar_double, hoc_vector_double, NULL);
}
}
Loading

0 comments on commit 9ebaf08

Please sign in to comment.