83 fwrite(&endian_flg,
sizeof(
int), 1, fdump->fd);
84 fwrite(&plut->
rows,
sizeof(plut->
rows), 1, fdump->fd);
85 fwrite(&plut->
cols,
sizeof(plut->
cols), 1, fdump->fd);
87 for (
int i=plut->
mn_ind; i<=plut->mx_ind; i++)
88 for (
int j=0; j<plut->
cols; j++)
103 if ( plut != NULL && plut->
tab != NULL ) {
104 if (plut->
tab != NULL) {
106 deallocate_on_target<LUT_data_t>(target, plut->
tab[0]);
112 memset( plut, 0,
sizeof(
LUT) );
127 #define MAX_LUT_NUMINF 10 134 for (
int i=lut->
mn_ind; i<=lut->mx_ind; i++ )
135 for (
int j=0; j<lut->
cols; j++ )
136 if ( ! std::isfinite(lut->
tab[i][j])) {
137 log_msg(0, 2, 0,
"LUT WARNING: %s=%g produces %g in entry number %d!\n",lut->
name,i*lut->
res,lut->
tab[i][j],j);
140 log_msg(0, 3, 0,
"suppressing further errors!!!\n" );
176 if ( std::isfinite(val) ) {
178 snprintf(error,
sizeof error,
"bounds exceeded for %s-table = %g (limits: %g - %g)",
179 tabname, val, lt->
mn, lt->
mx);
183 }
else if (std::isinf(val)) {
184 snprintf(error,
sizeof error,
"inf passed to LUT_index() for %s-table", tabname);
186 }
else if ( std::isnan(val) ) {
187 snprintf(error,
sizeof error,
"NaN passed to LUT_index() for %s-table", tabname);
195 int indx = (int)(tab->
step*val);
197 if (indx < tab->mn_ind) {
199 }
else if (indx > tab->
mx_ind) {
211 return (val < tab->mn || val > tab->
mx) ;
225 return (1.-x)*t->
tab[i][j] + x*t->
tab[i+1][j];
244 return (x-idx*t->
res)/t->
res;
263 for (
int j=0;j<tab->
cols;j++)
264 row[j] = tab->
tab[idx][j];
266 for (
int j=0;j<tab->
cols;j++)
288 #endif // ifdef __cplusplus 305 int distance,
int index,
int n,
char* row_ptr,
306 int lut_numelements) {
313 for (
unsigned i = 0; i < n; ++i)
315 row + (i * (lut_numelements)));
317 for (
unsigned i = 0; i < n; ++i)
318 LUT_interpRow(tab, *(val + i*distance + index*n), i + index*n,
319 row + (i * (lut_numelements)));
323 #ifdef HAS_MLIR_CPU_MODEL 324 void compute_LUT_interpRow_mlir_8xf64(
double ,
double,
double,
double,
int,
double,
double*,
double *,
bool,
int,
double,
char*);
325 void compute_LUT_interpRow_mlir_4xf64(
double ,
double,
double,
double,
int,
double,
double*,
double *,
bool,
int,
double,
char*);
326 void compute_LUT_interpRow_mlir_2xf64(
double ,
double,
double,
double,
int,
double,
double*,
double *,
bool,
int,
double,
char*);
339 int lut_num_elements,
int vector_size)
341 LUT *
const tab = (
LUT *
const)table;
344 if (lut_num_elements > 0)
347 if (vector_size == 8)
349 compute_LUT_interpRow_mlir_8xf64((
double) tab->
step, (
double) tab->
mn, (
double) tab->
mx, (
double) tab->
res, (
int) tab->
cols, (
double) tab->
mn_ind, (
double*)tab->
tab[tab->
mn_ind], (
double *) row,
true, i, (
double) tab->
mx_ind, table);
351 else if (vector_size == 4)
353 compute_LUT_interpRow_mlir_4xf64((
double) tab->
step, (
double) tab->
mn, (
double) tab->
mx, (
double) tab->
res, (
int) tab->
cols, (
double) tab->
mn_ind, (
double*)tab->
tab[tab->
mn_ind], (
double *) row,
true, i, (
double) tab->
mx_ind, table);
355 else if (vector_size == 2)
357 compute_LUT_interpRow_mlir_2xf64((
double) tab->
step, (
double) tab->
mn, (
double) tab->
mx, (
double) tab->
res, (
int) tab->
cols, (
double) tab->
mn_ind, (
double*)tab->
tab[tab->
mn_ind], (
double *) row,
true, i, (
double) tab->
mx_ind, table);
361 if (vector_size == 8)
363 compute_LUT_interpRow_mlir_8xf64((
double) tab->
step, (
double) tab->
mn, (
double) tab->
mx, (
double) tab->
res, (
int) tab->
cols, (
double) tab->
mn_ind, (
double*)tab->
tab[tab->
mn_ind], (
double *) row,
false, i, (
double) tab->
mx_ind, table);
365 else if (vector_size == 4)
367 compute_LUT_interpRow_mlir_4xf64((
double) tab->
step, (
double) tab->
mn, (
double) tab->
mx, (
double) tab->
res, (
int) tab->
cols, (
double) tab->
mn_ind, (
double*)tab->
tab[tab->
mn_ind], (
double *) row,
false, i, (
double) tab->
mx_ind, table);
369 else if (vector_size == 2)
371 compute_LUT_interpRow_mlir_2xf64((
double) tab->
step, (
double) tab->
mn, (
double) tab->
mx, (
double) tab->
res, (
int) tab->
cols, (
double) tab->
mn_ind, (
double*)tab->
tab[tab->
mn_ind], (
double *) row,
false, i, (
double) tab->
mx_ind, table);
381 LUT *
const tab = (
LUT *
const)table;
388 #endif // ifdef __cplusplus
int LUT_out_of_bounds(LUT *tab, GlobalData_t val)
char * dupstr(const char *old_str)
void LUT_interpRow_n_elements(char *table, char *val_ptr, int offset, int distance, int index, int n, char *row_ptr, int lut_numelements)
LUT_data_t * LUT_row(LUT *lut, GlobalData_t val, int locind)
void destroy_lut(LUT *plut, Target target)
void LUT_problem_mlir(char *tab, GlobalData_t val, int locind)
void IIF_warn(const int wv, const char error[])
void LUT_alloc(LUT *plut, int cols, float mn, float mx, float res, const char *name, Target target)
LUT_data_t LUT_interpRow(LUT *const tab, GlobalData_t val, int i, LUT_data_t *row)
LUT_data_t LUT_derror(LUT *t, int idx, GlobalData_t x)
int LUT_index(LUT *tab, GlobalData_t val, int locind)
#define MAX_LUT_NUMINF
maximum # non-finite warnings to print
Define multiple ionic models to be used in different regions.
double distance(const Point &a, const Point &b)
int LUT_dump(LUT *plut, const char *fname)
void LUT_problem(LUT *lt, double val, int wv, const char *tabname)
LUT_data_t LUT_interp(LUT *t, int i, int j, GlobalData_t x)
void LUT_interpRow_mlir(char *table, int i, char *row_ptr, int lut_num_elements, int vector_size)
void log_msg(FILE_SPEC out, int level, unsigned char flag, const char *fmt,...)
Target
enum that represents different targets to run ionic models on.
void f_close(FILE_SPEC &f)
Close a FILE_SPEC.
Basic utility structs and functions, mostly IO related.
void deallocate_on_target(Target target, T *ptr)
Utility function for deallocating memory on a target. See TargetAllocator.
FILE_SPEC f_open(const char *fname, const char *mode)
Open a FILE_SPEC.