Skip to content

Commit

Permalink
introduce configurable type for memory size in structs and size calcu…
Browse files Browse the repository at this point in the history
…lation

For larger problems with high memory demand (>2GB) using type int is a
limiting factor. A configurable typedef "hpipm_size_t" defined in
include/hpipm_common.h can be set depending on the problem size to expect
and depending on the platform/OS.
  • Loading branch information
schwieni committed Feb 7, 2021
1 parent b2a70f7 commit 8c3a0c9
Show file tree
Hide file tree
Showing 195 changed files with 804 additions and 784 deletions.
4 changes: 2 additions & 2 deletions archive/include/hpipm_d_irk_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct d_irk_workspace
int nx; // number of states
int nf; // number of forward sensitivities
int np; // number of parameters
int memsize; // TODO
hpipm_size_t memsize; // TODO
};


Expand All @@ -67,7 +67,7 @@ struct d_irk_args


//
int d_memsize_irk_int(struct d_rk_data *rk_data, int nx, int nf, int np);
hpipm_size_t d_memsize_irk_int(struct d_rk_data *rk_data, int nx, int nf, int np);
//
void d_create_irk_int(struct d_rk_data *rk_data, int nx, int nf, int np, struct d_irk_workspace *workspace, void *memory);
//
Expand Down
4 changes: 2 additions & 2 deletions archive/include/hpipm_d_ocp_nlp.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ struct d_ocp_nlp
int *ns; // number of soft constraints
int **idxs; // index of soft constraints
int N; // hotizon lenght
int memsize; // memory size in bytes
hpipm_size_t memsize; // memory size in bytes
};



//
int d_memsize_ocp_nlp(int N, int *nx, int *nu, int *nb, int *ng, int *ns);
hpipm_size_t d_memsize_ocp_nlp(int N, int *nx, int *nu, int *nb, int *ng, int *ns);
//
void d_create_ocp_nlp(int N, int *nx, int *nu, int *nb, int *ng, int *ns, struct d_ocp_nlp *nlp, void *memory);
//
Expand Down
8 changes: 4 additions & 4 deletions archive/include/hpipm_d_ocp_nlp_hyb.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct d_ocp_nlp_hyb_arg
int stat_max; // iterations saved in stat
int N2; // horizon of partially condensed QP
int pred_corr; // use Mehrotra's predictor-corrector IPM algirthm
int memsize;
hpipm_size_t memsize;
};


Expand All @@ -76,20 +76,20 @@ struct d_ocp_nlp_hyb_workspace
double nlp_res_m; // exit inf norm of residuals
int iter_qp; // qp ipm iteration number
int iter_nlp; // nlp ipm iteration number
int memsize;
hpipm_size_t memsize;
};



//
int d_memsize_ocp_nlp_hyb_arg(struct d_ocp_nlp *nlp);
hpipm_size_t d_memsize_ocp_nlp_hyb_arg(struct d_ocp_nlp *nlp);
//
void d_create_ocp_nlp_hyb_arg(struct d_ocp_nlp *nlp, struct d_ocp_nlp_hyb_arg *arg, void *mem);
//
void d_set_default_ocp_nlp_hyb_arg(struct d_ocp_nlp_hyb_arg *arg);

//
int d_memsize_ocp_nlp_hyb(struct d_ocp_nlp *nlp, struct d_ocp_nlp_hyb_arg *arg);
hpipm_size_t d_memsize_ocp_nlp_hyb(struct d_ocp_nlp *nlp, struct d_ocp_nlp_hyb_arg *arg);
//
void d_create_ocp_nlp_hyb(struct d_ocp_nlp *nlp, struct d_ocp_nlp_hyb_arg *arg, struct d_ocp_nlp_hyb_workspace *ws, void *mem);
//
Expand Down
8 changes: 4 additions & 4 deletions archive/include/hpipm_d_ocp_nlp_ipm.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct d_ocp_nlp_ipm_arg
int nlp_iter_max; // exit cond in iter number
int stat_max; // iterations saved in stat
int pred_corr; // use Mehrotra's predictor-corrector IPM algirthm
int memsize;
hpipm_size_t memsize;
};


Expand All @@ -65,20 +65,20 @@ struct d_ocp_nlp_ipm_workspace
double nlp_res_d; // exit inf norm of residuals
double nlp_res_m; // exit inf norm of residuals
int iter; // iteration number
int memsize;
hpipm_size_t memsize;
};



//
int d_memsize_ocp_nlp_ipm_arg(struct d_ocp_nlp *nlp);
hpipm_size_t d_memsize_ocp_nlp_ipm_arg(struct d_ocp_nlp *nlp);
//
void d_create_ocp_nlp_ipm_arg(struct d_ocp_nlp *nlp, struct d_ocp_nlp_ipm_arg *arg, void *mem);
//
void d_set_default_ocp_nlp_ipm_arg(struct d_ocp_nlp_ipm_arg *arg);

//
int d_memsize_ocp_nlp_ipm(struct d_ocp_nlp *nlp, struct d_ocp_nlp_ipm_arg *arg);
hpipm_size_t d_memsize_ocp_nlp_ipm(struct d_ocp_nlp *nlp, struct d_ocp_nlp_ipm_arg *arg);
//
void d_create_ocp_nlp_ipm(struct d_ocp_nlp *nlp, struct d_ocp_nlp_ipm_arg *arg, struct d_ocp_nlp_ipm_workspace *ws, void *mem);
//
Expand Down
4 changes: 2 additions & 2 deletions archive/include/hpipm_d_ocp_nlp_sol.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ struct d_ocp_nlp_sol
struct blasfeo_dvec *pi;
struct blasfeo_dvec *lam;
struct blasfeo_dvec *t;
int memsize; // memory size in bytes
hpipm_size_t memsize; // memory size in bytes
};



//
int d_memsize_ocp_nlp_sol(int N, int *nx, int *nu, int *nb, int *ng, int *ns);
hpipm_size_t d_memsize_ocp_nlp_sol(int N, int *nx, int *nu, int *nb, int *ng, int *ns);
//
void d_create_ocp_nlp_sol(int N, int *nx, int *nu, int *nb, int *ng, int *ns, struct d_ocp_nlp_sol *qp_sol, void *memory);
//
Expand Down
6 changes: 3 additions & 3 deletions archive/include/hpipm_d_ocp_nlp_sqp.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@ struct d_ocp_nlp_sqp_workspace
double nlp_res_d; // exit inf norm of residuals
double nlp_res_m; // exit inf norm of residuals
int iter; // iteration number
int memsize;
hpipm_size_t memsize;
};



//
int d_memsize_ocp_nlp_sqp_arg(struct d_ocp_nlp *nlp);
hpipm_size_t d_memsize_ocp_nlp_sqp_arg(struct d_ocp_nlp *nlp);
//
void d_create_ocp_nlp_sqp_arg(struct d_ocp_nlp *nlp, struct d_ocp_nlp_sqp_arg *arg, void *mem);
//
void d_set_default_ocp_nlp_sqp_arg(struct d_ocp_nlp_sqp_arg *arg);

//
int d_memsize_ocp_nlp_sqp(struct d_ocp_nlp *nlp, struct d_ocp_nlp_sqp_arg *arg);
hpipm_size_t d_memsize_ocp_nlp_sqp(struct d_ocp_nlp *nlp, struct d_ocp_nlp_sqp_arg *arg);
//
void d_create_ocp_nlp_sqp(struct d_ocp_nlp *nlp, struct d_ocp_nlp_sqp_arg *arg, struct d_ocp_nlp_sqp_workspace *ws, void *mem);
//
Expand Down
4 changes: 2 additions & 2 deletions archive/include/hpipm_s_ocp_nlp_sol.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ struct s_ocp_nlp_sol
struct blasfeo_svec *lam;
struct blasfeo_svec *t;
struct blasfeo_svec *eta0;
int memsize; // memory size in bytes
hpipm_size_t memsize; // memory size in bytes
};



//
int s_memsize_ocp_nlp_sol(int N, int *nx, int *nu, int *nb, int *ng, int *ns, int ne0);
hpipm_size_t s_memsize_ocp_nlp_sol(int N, int *nx, int *nu, int *nb, int *ng, int *ns, int ne0);
//
void s_create_ocp_nlp_sol(int N, int *nx, int *nu, int *nb, int *ng, int *ns, int ne0, struct s_ocp_nlp_sol *qp_sol, void *memory);
//
Expand Down
4 changes: 2 additions & 2 deletions archive/ocp_nlp/d_ocp_nlp.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@



int MEMSIZE_OCP_NLP(int N, int *nx, int *nu, int *nb, int *ng, int *ns)
hpipm_size_t MEMSIZE_OCP_NLP(int N, int *nx, int *nu, int *nb, int *ng, int *ns)
{

int ii;
Expand All @@ -72,7 +72,7 @@ int MEMSIZE_OCP_NLP(int N, int *nx, int *nu, int *nb, int *ng, int *ns)
nuxM = nu[ii]+nx[ii]>nuxM ? nu[ii]+nx[ii] : nuxM;
}

int size = 0;
hpipm_size_t size = 0;

size += 5*(N+1)*sizeof(int); // nx nu nb ng ns
size += 2*(N+1)*sizeof(int *); // idxb idxs
Expand Down
8 changes: 4 additions & 4 deletions archive/ocp_nlp/d_ocp_nlp_hyb.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@



int d_memsize_ocp_nlp_hyb_arg(struct OCP_NLP *nlp)
hpipm_size_t d_memsize_ocp_nlp_hyb_arg(struct OCP_NLP *nlp)
{

int N = nlp->N;

int size;
hpipm_size_t size;

size = 0;

Expand Down Expand Up @@ -207,7 +207,7 @@ void d_set_default_ocp_nlp_hyb_arg(struct OCP_NLP_HYB_ARG *arg)


// TODO eliminate x0 in QP !!!
int MEMSIZE_OCP_NLP_HYB(struct OCP_NLP *nlp, struct OCP_NLP_HYB_ARG *arg)
hpipm_size_t MEMSIZE_OCP_NLP_HYB(struct OCP_NLP *nlp, struct OCP_NLP_HYB_ARG *arg)
{

int ii;
Expand Down Expand Up @@ -241,7 +241,7 @@ int MEMSIZE_OCP_NLP_HYB(struct OCP_NLP *nlp, struct OCP_NLP_HYB_ARG *arg)

int *i_ptr;

int size = 0;
hpipm_size_t size = 0;

size += 1*sizeof(struct OCP_QP);
size += 1*sizeof(struct OCP_QP_SOL);
Expand Down
8 changes: 4 additions & 4 deletions archive/ocp_nlp/d_ocp_nlp_ipm.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@



int d_memsize_ocp_nlp_ipm_arg(struct OCP_NLP *nlp)
hpipm_size_t d_memsize_ocp_nlp_ipm_arg(struct OCP_NLP *nlp)
{

int N = nlp->N;

int size;
hpipm_size_t size;

size = 0;

Expand Down Expand Up @@ -140,7 +140,7 @@ void d_set_default_ocp_nlp_ipm_arg(struct OCP_NLP_IPM_ARG *arg)


// TODO eliminate x0 in QP !!!
int MEMSIZE_OCP_NLP_IPM(struct OCP_NLP *nlp, struct OCP_NLP_IPM_ARG *arg)
hpipm_size_t MEMSIZE_OCP_NLP_IPM(struct OCP_NLP *nlp, struct OCP_NLP_IPM_ARG *arg)
{

int ii;
Expand All @@ -162,7 +162,7 @@ int MEMSIZE_OCP_NLP_IPM(struct OCP_NLP *nlp, struct OCP_NLP_IPM_ARG *arg)

int *i_ptr;

int size = 0;
hpipm_size_t size = 0;

size += 1*sizeof(struct OCP_QP);
size += 1*sizeof(struct OCP_QP_SOL);
Expand Down
8 changes: 4 additions & 4 deletions archive/ocp_nlp/d_ocp_nlp_sqp.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@



int d_memsize_ocp_nlp_sqp_arg(struct OCP_NLP *nlp)
hpipm_size_t d_memsize_ocp_nlp_sqp_arg(struct OCP_NLP *nlp)
{

int N = nlp->N;

int size;
hpipm_size_t size;

size = 0;

Expand Down Expand Up @@ -192,7 +192,7 @@ void d_set_default_ocp_nlp_sqp_arg(struct OCP_NLP_SQP_ARG *arg)


// TODO eliminate x0 in QP !!!
int MEMSIZE_OCP_NLP_SQP(struct OCP_NLP *nlp, struct OCP_NLP_SQP_ARG *arg)
hpipm_size_t MEMSIZE_OCP_NLP_SQP(struct OCP_NLP *nlp, struct OCP_NLP_SQP_ARG *arg)
{

int ii;
Expand Down Expand Up @@ -226,7 +226,7 @@ int MEMSIZE_OCP_NLP_SQP(struct OCP_NLP *nlp, struct OCP_NLP_SQP_ARG *arg)

int *i_ptr;

int size = 0;
hpipm_size_t size = 0;

size += 1*sizeof(struct OCP_QP);
size += 1*sizeof(struct OCP_QP_SOL);
Expand Down
4 changes: 2 additions & 2 deletions archive/ocp_nlp/x_ocp_nlp_sol.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@



int MEMSIZE_OCP_NLP_SOL(int N, int *nx, int *nu, int *nb, int *ng, int *ns)
hpipm_size_t MEMSIZE_OCP_NLP_SOL(int N, int *nx, int *nu, int *nb, int *ng, int *ns)
{

int ii;
Expand All @@ -46,7 +46,7 @@ int MEMSIZE_OCP_NLP_SOL(int N, int *nx, int *nu, int *nb, int *ng, int *ns)
nvt += nu[ii]+nx[ii]+2*ns[ii];
nct += nb[ii]+ng[ii]+ns[ii];

int size = 0;
hpipm_size_t size = 0;

size += 3*(N+1)*sizeof(struct STRVEC); // ux lam t
size += 1*N*sizeof(struct STRVEC); // pi
Expand Down
4 changes: 2 additions & 2 deletions archive/sim_core/d_irk_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@



int d_memsize_irk_int(struct d_rk_data *rk_data, int nx, int nf, int np)
hpipm_size_t d_memsize_irk_int(struct d_rk_data *rk_data, int nx, int nf, int np)
{

int ns = rk_data->ns;

int nX = nx*(1+nf);

int size = 0;
hpipm_size_t size = 0;

size += 3*sizeof(struct blasfeo_dmat); // JG rG K

Expand Down
16 changes: 8 additions & 8 deletions archive/test_d_nlp_ipm.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ struct d_linear_system
double *Bc;
int nx;
int nu;
int memsize;
hpipm_size_t memsize;
};



int d_memsize_linear_system(int nx, int nu)
hpipm_size_t d_memsize_linear_system(int nx, int nu)
{
int size = 0;
hpipm_size_t size = 0;
size += (nx*nx+nx*nu)*sizeof(double);
return size;
}
Expand Down Expand Up @@ -250,7 +250,7 @@ int main()
d_print_mat(nx_, nx_, Ac, nx_);
d_print_mat(nx_, nu_, Bc, nx_);

int lin_sys_memsize = d_memsize_linear_system(nx_, nu_);
hpipm_size_t lin_sys_memsize = d_memsize_linear_system(nx_, nu_);
printf("\nlin_sys memsize = %d\n", lin_sys_memsize);
void *lin_sys_memory = malloc(lin_sys_memsize);

Expand Down Expand Up @@ -349,7 +349,7 @@ int main()
#endif

// erk data structure
int memsize_rk_data = d_memsize_rk_data(nsta);
hpipm_size_t memsize_rk_data = d_memsize_rk_data(nsta);
printf("\nmemsize rk data %d\n", memsize_rk_data);
void *memory_rk_data = malloc(memsize_rk_data);

Expand Down Expand Up @@ -664,7 +664,7 @@ int main()
* ocp nlp
************************************************/

int nlp_size = d_memsize_ocp_nlp(N, nx, nu, nb, ng, ns);
hpipm_size_t nlp_size = d_memsize_ocp_nlp(N, nx, nu, nb, ng, ns);
printf("\nnlpsize = %d\n", nlp_size);
void *nlp_mem = malloc(nlp_size);

Expand All @@ -677,7 +677,7 @@ int main()
* ocp nlp sol
************************************************/

int nlp_sol_size = d_memsize_ocp_nlp_sol(N, nx, nu, nb, ng, ns);
hpipm_size_t nlp_sol_size = d_memsize_ocp_nlp_sol(N, nx, nu, nb, ng, ns);
printf("\nnlp sol size = %d\n", nlp_sol_size);
void *nlp_sol_mem = malloc(nlp_sol_size);

Expand Down Expand Up @@ -709,7 +709,7 @@ int main()
* ocp nlp ipm ws
************************************************/

int nlp_ws_size = d_memsize_ocp_nlp_ipm(&nlp, &ipm_arg);
hpipm_size_t nlp_ws_size = d_memsize_ocp_nlp_ipm(&nlp, &ipm_arg);
printf("\nnlp ws size = %d\n", nlp_ws_size);
void *nlp_ws_mem = malloc(nlp_ws_size);

Expand Down
Loading

0 comments on commit 8c3a0c9

Please sign in to comment.