openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
LUT.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) NumeriCor GmbH
2 // SPDX-License-Identifier: LicenseRef-APL-1.1
3 
4 #ifndef LUT_H
5 #define LUT_H
6 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <math.h>
10 #include <stdbool.h>
11 #include "limpet_types.h"
12 #include "target.h"
13 
14 // define so that LUT exist only in device memory
15 #define LUT_DEV_ONLY
16 
17 namespace limpet {
18 
19 typedef double LUT_data_t;
20 
31 struct LUT {
32  char *name;
33  int rows;
34  int cols;
35  float mn;
36  float mx;
37  float res;
38  float step;
39  int mn_ind;
40  int mx_ind;
41  float dt;
43 };
44 
45 
46 void LUT_alloc( LUT *psv, int cols, float mn, float mx, float res,
47  const char*, Target target );
48 int LUT_dump( LUT *plut, const char * );
49 int check_LUT( LUT* );
50 LUT_data_t LUT_interp( LUT *t, int i, int j, GlobalData_t x );
51 LUT_data_t LUT_derror( LUT *t, int idx, GlobalData_t x );
52 #if defined MLIR_CODEGEN && (defined __CUDA__ || defined __HIP__)
53 #ifdef __cplusplus
54 extern "C"
55 {
56 #endif // ifdef __cplusplus
57 __host__ __device__
58 #endif
60 #if defined MLIR_CODEGEN && (defined __CUDA__ || defined __HIP__)
61 #ifdef __cplusplus
62 }
63 #endif // ifdef __cplusplus
64 #endif
65 void LUT_problem( LUT *, double, int, const char * );
66 void IIF_warn(const int wv, const char* error);
67 void destroy_lut( LUT *plut, Target target );
68 
74 
83 template<typename T>
84 T** build_matrix_ns(int m, int n, int size, Target target)
85 {
86  T **ptr = NULL;
87  T *buf;
88 
89  buf = allocate_on_target<T>(target, m * n);
90  if( buf==NULL ) {
91  log_msg(0, 5, 0, "Not enough memory for matrix\n" );
92  exit(1);
93  }
94 
95  ptr = allocate_on_target<T*>(target, m);
96  for ( int i=0; i<m; i++ )
97  ptr[i] = buf + i*n;
98 
99  return ptr;
100 }
101 
102 LUT_data_t* LUT_row( LUT *lut, GlobalData_t val, int locind );
103 
104 #ifdef __cplusplus
105 extern "C"
106 {
107 #endif // ifdef __cplusplus
108 // LUT functions for MLIR models
109 // Implements LUT_interpRow for multiple elements to be placed in a vector
110 void
111 LUT_interpRow_n_elements(char *tab, char *val_ptr, int offset, int distance,
112  int index, int n, char* row_ptr, int lut_numelements);
113 
114 void LUT_interpRow_mlir(char *table, int i, char* row_ptr,
115  int lut_num_elements, int vector_size);
116 
117 void LUT_problem_mlir( char *tab, GlobalData_t val, int locind);
118 
119 #ifdef __cplusplus
120 }
121 #endif // ifdef __cplusplus
122 
128 #define LUT_entry(A, I, J) (A)->tab[I][J]
129 
130 #ifdef IMP_FAST
137 #define LUT_index( T, V, W ) (int)((V)*T->step)
138 #define LUT_constrain( T, V, W )
139 
140 #else
141 
153 int LUT_index( LUT *tab, GlobalData_t val, int locind );
154 
167 #define LUT_constrain(T, V, W, N ) \
168  if( V>=T->mx){/*fprintf(stderr, "table overbound: %g\n", V );*/V=T->mx;}\
169  if( V<=T->mn){/*fprintf(stderr, "table underbound: %g\n", V );*/V=T->mn;}
170 #endif
171 
172 } // namespace limpet
173 
174 #endif
#define log_msg(F, L, O,...)
Definition: filament.h:8
double distance(const Point &a, const Point &b)
Definition: SF_container.h:146
void IIF_warn(const int wv, const char error[])
Definition: LUT.cc:140
Target
enum that represents different targets to run ionic models on.
Definition: target.h:30
void LUT_alloc(LUT *plut, int cols, float mn, float mx, float res, const char *name, Target target)
Definition: LUT.cc:30
LUT_data_t LUT_interp(LUT *t, int i, int j, GlobalData_t x)
Definition: LUT.cc:208
void LUT_problem_mlir(char *tab, GlobalData_t val, int locind)
SF_real GlobalData_t
Definition: limpet_types.h:12
LUT_data_t LUT_interpRow(LUT *const tab, GlobalData_t val, int i, LUT_data_t *row)
Definition: LUT.cc:243
double LUT_data_t
Definition: LUT.h:19
int LUT_dump(LUT *plut, const char *fname)
Definition: LUT.cc:59
LUT_data_t * LUT_row(LUT *lut, GlobalData_t val, int locind)
Definition: LUT.cc:265
int LUT_index(LUT *tab, GlobalData_t val, int locind)
Definition: LUT.cc:178
void destroy_lut(LUT *plut, Target target)
Definition: LUT.cc:86
void LUT_interpRow_mlir(char *table, int i, char *row_ptr, int lut_num_elements, int vector_size)
void LUT_interpRow_n_elements(char *table, char *val_ptr, int offset, int distance, int index, int n, char *row_ptr, int lut_numelements)
Definition: LUT.cc:289
void LUT_problem(LUT *lt, double val, int wv, const char *tabname)
Definition: LUT.cc:156
T ** build_matrix_ns(int m, int n, int size, Target target)
Definition: LUT.h:84
int check_LUT(LUT *lut)
Definition: LUT.cc:114
LUT_data_t LUT_derror(LUT *t, int idx, GlobalData_t x)
Definition: LUT.cc:227
bool is_big_endian()
Definition: basics.cc:278
FILE_SPEC f_open(const char *fname, const char *mode)
Open a FILE_SPEC.
Definition: basics.cc:123
char * dupstr(const char *old_str)
Definition: basics.cc:29
file_desc * FILE_SPEC
Definition: basics.h:125
lookup table structure
Definition: LUT.h:31
float res
Definition: LUT.h:37
float mx
Definition: LUT.h:36
int mn_ind
Definition: LUT.h:39
float dt
Definition: LUT.h:41
float mn
Definition: LUT.h:35
int rows
Definition: LUT.h:33
int cols
Definition: LUT.h:34
LUT_data_t ** tab
Definition: LUT.h:42
float step
Definition: LUT.h:38
int mx_ind
Definition: LUT.h:40
char * name
Definition: LUT.h:32
Defines valid targets for an ionic model to run on and an allocator for allocating memory on a specif...