68 fwrite(&endian_flg,
sizeof(
int), 1, fdump->fd);
69 fwrite(&plut->
rows,
sizeof(plut->
rows), 1, fdump->fd);
70 fwrite(&plut->
cols,
sizeof(plut->
cols), 1, fdump->fd);
72 for (
int i=plut->
mn_ind; i<=plut->mx_ind; i++)
73 for (
int j=0; j<plut->
cols; j++)
88 if ( plut != NULL && plut->
tab != NULL ) {
89 if (plut->
tab != NULL) {
91 deallocate_on_target<LUT_data_t>(target, plut->
tab[0]);
97 memset( plut, 0,
sizeof(
LUT) );
112 #define MAX_LUT_NUMINF 10
119 for (
int i=lut->
mn_ind; i<=lut->mx_ind; i++ )
120 for (
int j=0; j<lut->
cols; j++ )
121 if ( ! std::isfinite(lut->
tab[i][j])) {
122 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);
125 log_msg(0, 3, 0,
"suppressing further errors!!!\n" );
161 if ( std::isfinite(val) ) {
163 snprintf(error,
sizeof error,
"bounds exceeded for %s-table = %g (limits: %g - %g)",
164 tabname, val, lt->
mn, lt->
mx);
168 }
else if (std::isinf(val)) {
169 snprintf(error,
sizeof error,
"inf passed to LUT_index() for %s-table", tabname);
171 }
else if ( std::isnan(val) ) {
172 snprintf(error,
sizeof error,
"NaN passed to LUT_index() for %s-table", tabname);
180 int indx = (int)(tab->
step*val);
182 if (indx < tab->mn_ind) {
184 }
else if (indx > tab->
mx_ind) {
196 return (val < tab->mn || val > tab->
mx) ;
210 return (1.-x)*t->
tab[i][j] + x*t->
tab[i+1][j];
229 return (x-idx*t->
res)/t->
res;
248 for (
int j=0;j<tab->
cols;j++)
249 row[j] = tab->
tab[idx][j];
251 for (
int j=0;j<tab->
cols;j++)
290 int distance,
int index,
int n,
char* row_ptr,
291 int lut_numelements) {
298 for (
unsigned i = 0; i < n; ++i)
300 row + (i * (lut_numelements)));
302 for (
unsigned i = 0; i < n; ++i)
304 row + (i * (lut_numelements)));
308 #ifdef HAS_MLIR_CPU_MODEL
309 void compute_LUT_interpRow_mlir_8xf64(
double ,
double,
double,
double,
int,
double,
double*,
double *,
bool,
int,
double,
char*);
310 void compute_LUT_interpRow_mlir_4xf64(
double ,
double,
double,
double,
int,
double,
double*,
double *,
bool,
int,
double,
char*);
311 void compute_LUT_interpRow_mlir_2xf64(
double ,
double,
double,
double,
int,
double,
double*,
double *,
bool,
int,
double,
char*);
324 int lut_num_elements,
int vector_size)
326 LUT *
const tab = (LUT *
const)table;
329 if (lut_num_elements > 0)
332 if (vector_size == 8)
334 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);
336 else if (vector_size == 4)
338 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);
340 else if (vector_size == 2)
342 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);
346 if (vector_size == 8)
348 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);
350 else if (vector_size == 4)
352 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);
354 else if (vector_size == 2)
356 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);
366 LUT *
const tab = (LUT *
const)table;
#define MAX_LUT_NUMINF
maximum # non-finite warnings to print
Define multiple ionic models to be used in different regions.
Basic utility structs and functions, mostly IO related.
#define log_msg(F, L, O,...)
double distance(const Point &a, const Point &b)
int LUT_out_of_bounds(LUT *tab, GlobalData_t val)
void IIF_warn(const int wv, const char error[])
Target
enum that represents different targets to run ionic models on.
void LUT_alloc(LUT *plut, int cols, float mn, float mx, float res, const char *name, Target target)
LUT_data_t LUT_interp(LUT *t, int i, int j, GlobalData_t x)
void LUT_problem_mlir(char *tab, GlobalData_t val, int locind)
LUT_data_t LUT_interpRow(LUT *const tab, GlobalData_t val, int i, LUT_data_t *row)
int LUT_dump(LUT *plut, const char *fname)
LUT_data_t * LUT_row(LUT *lut, GlobalData_t val, int locind)
int LUT_index(LUT *tab, GlobalData_t val, int locind)
void destroy_lut(LUT *plut, Target target)
void deallocate_on_target(Target target, T *ptr)
Utility function for deallocating memory on a target. See TargetAllocator.
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)
void LUT_problem(LUT *lt, double val, int wv, const char *tabname)
LUT_data_t LUT_derror(LUT *t, int idx, GlobalData_t x)
FILE_SPEC f_open(const char *fname, const char *mode)
Open a FILE_SPEC.
char * dupstr(const char *old_str)
void f_close(FILE_SPEC &f)
Close a FILE_SPEC.