35 #include <cuda_runtime.h>
38 #include <hip/hip_runtime.h>
51 #define M_PI 3.14159265358979323846264338327
55 #define heav(x) ( (x)<0 ? 0 : 1)
56 #define sign(x) ( (x)<0 ? -1 : 1 )
57 #define square(x) ((x)*(x))
58 #define cube(x) ((x)*(x)*(x))
61 #define MPI_RESTORE_IMP_POLL_BUFSIZE_TAG 10
62 #define MPI_RESTORE_IMP_SNDRCV_BUFFER_TAG 11
63 #define MPI_DUMP_IMP_POLL_BUFSIZE_TAG 20
64 #define MPI_DUMP_IMP_SNDRCV_BUFFER_TAG 21
65 #define MPI_DUMP_SVS_POLL_BUFSIZE_TAG 30
66 #define MPI_DUMP_SVS_SNDRCV_BUFFER_TAG 31
144 std::vector<IonIfBase*> _plugins;
157 std::vector<LUT> _tables;
158 LUT * _tables_d =
nullptr;
159 size_t _n_tables_d = 0;
216 std::vector<IonIfBase*>&
plugins();
244 #if defined HAS_CUDA_MODEL || defined HAS_ROCM_MODEL
311 std::vector<LUT>&
tables();
320 #if defined HAS_CUDA_MODEL || defined HAS_ROCM_MODEL
324 return this->_tables_d;
335 #if defined HAS_GPU_MODEL
401 size_t *offset,
IMPinfo *impinfo,
const int* loc2canon);
443 void tune(
const char *im_par,
const char *plugs,
const char *plug_par);
505 struct has_rosenbrock_type {};
506 struct has_rosenbrock_vector_type {};
507 struct no_rosenbrock_type {};
522 static constexpr
bool is_void = std::is_void<S>::value;
527 bool _allocated =
false;
554 if (!is_void && _allocated) {
555 deallocate_on_target<S>(this->_target, this->_data);
567 this->_target = target;
569 bool do_zero =
false;
570 this->_data = allocate_on_target<S>(this->_target, this->_size, do_zero);
571 this->_allocated =
true;
581 template<
typename Type = S>
582 typename std::enable_if<!std::is_void<Type>::value, std::size_t>::type
get_element_size()
const {
586 template<
typename Type = S>
587 typename std::enable_if<std::is_void<Type>::value, std::size_t>::type
get_element_size()
const {
600 static_assert(!is_void,
"The LimpetArray class can't be used with type 'void'");
613 static_assert(!is_void,
"The LimpetArray class can't be used with type 'void'");
624 return this->_allocated;
634 if (
this == &other) {
637 this->_target = other._target;
638 this->_data = other._data;
639 this->_size = other._size;
640 if (other._allocated) {
641 this->_allocated =
true;
642 other._allocated =
false;
648 using SvTab = LimpetArray<typename T::state_type>;
649 using PrivateTab = LimpetArray<typename T::private_type>;
650 using PrivateVectorTab = LimpetArray<typename T::private_type_vector>;
658 using rosenbrock_usage =
typename std::conditional<std::is_void<typename T::private_type>::value, no_rosenbrock_type,
typename std::conditional<std::is_void<typename T::private_type_vector>::value, has_rosenbrock_type, has_rosenbrock_vector_type>::type>::type;
664 PrivateVectorTab _ion_private_vector;
688 if (this->_params[i] !=
nullptr) {
702 typename T::params_type *
params()
const {
728 return this->_ion_private[this->
get_target()];
733 throw std::logic_error(
"the vectorized ion private structure can only be used with the MLIR_CPU (vectorized CPU) target");
735 return this->_ion_private_vector;
744 return (
void *) this->_sv_tabs[this->
get_target()].data();
753 return sizeof(
typename T::state_type);
768 memcpy(this->
sv_tab().data(), this->_sv_tabs[old_target].data(), this->
sv_tab().size());
772 memcpy(this->
params(), this->_params[old_target],
sizeof(
typename T::params_type));
780 if (!this->_sv_tabs[this->
get_target()].is_allocated())
783 if (!this->_ion_private[this->
get_target()].is_allocated())
786 if (!this->_ion_private_vector.is_allocated() && this->get_target() ==
Target::MLIR_CPU)
788 if (this->_params[this->
get_target()] ==
nullptr)
789 this->_params[this->
get_target()] = allocate_on_target<typename T::params_type>(this->
get_target(), 1,
true);
825 throw std::logic_error(
"cannot copy SVs if both IMPs don't handle the same amount of cells");
922 bool flag_set(
const char *flags,
const char *target );
927 bool verify_flags(
const char *flags,
const char* given );
934 #include "ION_IF_sv.h"
936 #define CHANGE_PARAM( T, P, V, F ) do { \
937 ((T##_Params *)P)->V = modify_param( ((T##_Params *)P)->V, F ); \
938 log_msg( _nc_logf,0, 0, " %-20s modifier: %-15s value: %g",\
939 #V,F,(float)((T##_Params *)P)->V);} while (0)
#define NDEF
definition of cell geometry
Basic utility structs and functions, mostly IO related.
Represents the ionic model and plug-in (IMP) data structure.
virtual void initialize(double dt, GlobalData_t **impdat)
Initializes lookup table and state variable tables.
void tune(const char *im_par, const char *plugs, const char *plug_par)
Tunes specific IMP parameters from files.
Target _target
execution target for this IMP
void set_parent(IonIfBase *parent)
IonIfBase(const IonType &type, Target target, int num_node, const std::vector< std::reference_wrapper< IonType >> &plugins)
Constructor for IonIfBase.
virtual void set_target(Target target)
const IonType & get_type() const
Gets this IMP's model type.
int restore(opencarp::FILE_SPEC in, int n, const int *pos, IIF_Mask_t *mask, size_t *offset, IMPinfo *impinfo, const int *loc2canon)
Reads in the state variables for an IMP.
virtual void copy_SVs_from(IonIfBase &other, bool alloc)=0
Copies the state variables of an IMP.
char * fill_buf(char *buf, int *n, opencarp::Salt_list *l) const
Appends the state variables to a buffer.
float get_dt() const
Gets the basic integration time step.
int read_svs(FILE *file)
Reads state variable values for one cell from a file.
std::vector< LUT > & tables()
Gets the array of state variables.
ts _tstp
control time stepping
std::vector< IonIfBase * > & plugins()
Returns a vector containing the plugins of this IMP.
int dump_luts(bool zipped)
Dumps array of LUTs to file.
int write_svs(FILE *file, int node)
virtual ~IonIfBase()
Virtual destructor declaration.
void set_moddat(uint32_t data)
Set the data flag for this IMP's modified data.
void set_dt(float dt)
Sets the basic integration time step.
ts & get_tstp()
Gets the time stepper.
void for_each(const std::function< void(IonIfBase &)> &consumer)
Executes the consumer functions on this IMP and each of its plugins.
size_t get_n_tables_d() const
Gets the size of the array returned by IonIf::tables_d.
IonIfBase * parent() const
Gets the parent IMP.
void destroy_luts()
Destroys array of LUTs.
Target get_target() const
int get_num_node() const
Gets the number of nodes handled by this IMP.
uint32_t get_moddat() const
Gets the data flags for this IMP's modified data.
int miifIdx
imp index within miif
virtual std::size_t get_sv_size() const =0
Gets the size of the structure this IMP uses for state variables.
void copy_plugins_from(IonIfBase &other)
Copies the plugins of an IMP.
virtual void * get_sv_address()=0
Gets the raw address of the state variables for this IMP.
void compute(int start, int end, GlobalData_t **data)
Perform ionic model computation for 1 time step.
void initialize_params()
Initializes user modifiable parameters with default values defined in the respective ionic models.
uint32_t get_reqdat() const
Gets the data flags for this IMP's required data.
std::size_t get_num_threads() const
Gets the number of threads used for running this IMP.
LUT * tables_d() const
Gets an array of LUTs.
cell_geom & cgeom()
Gets the cell geometry data.
Utility class for handling arrays of data used by IMPs.
~LimpetArray()
Destroy a limpet array.
LimpetArray & operator=(LimpetArray &&other)
Move assignement operator.
LimpetArray()
Default constructor with no allocated data.
LimpetArray(Target target, std::size_t size)
Constructs a LimpetArray.
std::enable_if< std::is_void< Type >::value, std::size_t >::type get_element_size() const
bool is_allocated() const
Returns whether data has been allocated for this LimpetArray.
std::size_t size() const
Gets the sizee of the array.
std::enable_if<!std::is_void< Type >::value, std::size_t >::type get_element_size() const
Get the size of a single element (size of type S)
S * data() const
Gets a pointer to the underlying data.
void allocate(Target target, std::size_t size)
Allocate the array on the given target.
Child class of IonIfBase specialized for each ionic model type.
PrivateTab & ion_private()
Gets the ion private LimpetArray for the current target.
SvTab & sv_tab()
Gets the SV LimpetArray for the current target.
void copy_ion_private(IonIf< T > &other, has_rosenbrock_vector_type)
Copy the ion private array from other.
T::params_type * params() const
Gets a pointer to the parameter structure for the current target.
void copy_ion_private(IonIf< T > &other, no_rosenbrock_type)
This function does nothing (overload of copy_ion_private(IonIf<T>&, has_rosenbrock_type)).
PrivateVectorTab & ion_private_vector()
void initialize(double dt, GlobalData_t **impdat) override
Override of the initialization function to add the initialization of the private structures.
void init_ion_private(has_rosenbrock_vector_type)
Initialize private data.
void * get_sv_address() override
Gets the raw address of the SV array for the current target.
void allocate_model_data()
Allocate memory for the IMP data for the current target.
void copy_ion_private(IonIf< T > &other, has_rosenbrock_type)
Copy the ion private array from other.
void init_ion_private(has_rosenbrock_type)
Initialize private data.
void init_ion_private(no_rosenbrock_type)
Doesn't do anything.
void copy_SVs_from(IonIfBase &other_base, bool alloc) override
Copy state and private variables from another IMP.
std::size_t get_sv_size() const override
Gets the size of a SV structure.
void set_target(Target target) override
Set a new execution target for this IMP.
IonIf(const IonType &type, Target target, int num_node, const std::vector< std::reference_wrapper< IonType >> &plugins)
Constructs an IonIf object.
Abstract class representing an ionic model type.
virtual size_t dlo_vector_size() const =0
Gets the vector size when using data layout optimization (DLO).
char * get_typename(int type)
int process_param_mod(char *pstr, char *par, char *mod)
void SV_alloc(SV_TAB *psv, int numSeg, int struct_size)
GlobalData_t(* SVgetfcn)(IonIfBase &, int, int)
SVputfcn getPutSV(SVgetfcn)
int load_ionic_module(const char *)
Target
enum that represents different targets to run ionic models on.
@ UNKNOWN
special value to handle unknown targets
@ N_TARGETS
a token to indicate the maximum number of targets
@ MLIR_CPU
vectorized CPU code generated with MLIR
bool flag_set(const char *flags, const char *target)
bool verify_flags(const char *flags, const char *given)
void(* SVputfcn)(IonIfBase &, int, int, GlobalData_t)
void deallocate_on_target(Target target, T *ptr)
Utility function for deallocating memory on a target. See TargetAllocator.
void SV_free(SV_TAB *psv)
void update_ts(ts *ptstp)
char * get_next_list(char *lst, char delimiter)
void free_sv_table(void *)
float modify_param(float a, char *expr)
void initialize_ts(Target target, ts *tstp, int ng, int *skp, double dt)
V mod(const V &a, const V &b)
int offset
offset into node data
int map
which plugin does this IMO match
bool compatible
does IM match stored IM
int nplug
number of plugins
array of stat variable structures
int svSize
size of structure holding SV's for a node
int numSeg
number of unknowns
float fr_myo
volume of myoplasm
float sl_i2c
convert sl-currents in uA/cm^2 to mM/L without valence
float SVratio
single cell surface-to-volume ratio (per um)
float a_cap
capacitive cell surface
saltatory list – memory is allocated in chunks
Defines valid targets for an ionic model to run on and an allocator for allocating memory on a specif...