Skip to content

Commit

Permalink
MSVC support (acados#108)
Browse files Browse the repository at this point in the history
* Trying compiling with MSVC. Outstanding errors: variable-sized

* Can compiler qpoases_chen and nonlinear_chain examples with MSVC

* Correct some errors introduced by working towards msvc

* Get rid of timing dependencies

* MSVC still compiling examples

* Add Appveyor

* Try other branch

* run cmake

* submodules

* Add openblas, fortran

* small fix

* Fix build error

* try other openblas

* Small adaptations to dependencies in order to compile with msvc

* Always answer yes

* New version of dependencies

* Find conda libs

* Find shared library of gfortran

* change testing in Appveyor

* Fix lint errors

* Fix CMake error in qpDUNES
  • Loading branch information
roversch authored Aug 10, 2017
1 parent a92f2b6 commit 1b62ed6
Show file tree
Hide file tree
Showing 47 changed files with 423 additions and 373 deletions.
17 changes: 17 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

branches:
only:
- msvc

install:
- call C:\Miniconda36-x64\Scripts\activate.bat
- conda install --yes -c msys2 m2w64-gcc-libgfortran m2w64-openblas

build_script:
- git submodule update --init --recursive
- cmake -E make_directory build
- cmake -E chdir build cmake ..
- cmake --build build --config Debug
- cmake -E chdir build ctest --output-on-failure
- cmake --build build --config Release
- cmake -E chdir build ctest --output-on-failure
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@ octave-workspace
notes.txt
*.dSYM/
cmakelint
.vs
17 changes: 10 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)

if(CMAKE_SYSTEM MATCHES "Windows")
set(CMAKE_FIND_LIBRARY_PREFIXES "lib" CACHE INTERNAL "Library prefix")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll" CACHE INTERNAL "Library suffix")
endif()

# Set up build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release
Expand All @@ -34,13 +39,9 @@ message(STATUS "Build type is ${CMAKE_BUILD_TYPE}")

enable_testing(true)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Werror -fdiagnostics-show-option")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -fdiagnostics-show-option")
elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -WX")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Werror -fdiagnostics-show-option")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror -fdiagnostics-show-option")
endif()

# Set install directories
Expand Down Expand Up @@ -94,4 +95,6 @@ add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")

# Cpplint
include(lint)
if(NOT ${CMAKE_SYSTEM} MATCHES "Windows")
include(lint)
endif()
12 changes: 10 additions & 2 deletions acados/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,28 @@ endif()
file(GLOB_RECURSE ACADOS_SRC "${PROJECT_SOURCE_DIR}/acados/*.c")
# Exclude helper files
list(REMOVE_ITEM ACADOS_SRC "${PROJECT_SOURCE_DIR}/acados/ocp_qp/condensing_helper_functions.c")
# Exclude files not compatible with MSVC
if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
list(REMOVE_ITEM ACADOS_SRC "${PROJECT_SOURCE_DIR}/acados/ocp_qp/ocp_qp_hpmpc.c")
endif()

if(NOT EXISTS ${PROJECT_SOURCE_DIR}/external/OOQP)
list(REMOVE_ITEM ACADOS_SRC "${PROJECT_SOURCE_DIR}/acados/ocp_qp/ocp_qp_ooqp.c")
endif()

# Define acados library
add_library(acados STATIC ${ACADOS_SRC})
add_library(acados ${ACADOS_SRC})
target_include_directories(acados
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..> # for include "acados/..."
$<BUILD_INTERFACE:${EXTERNAL_SRC_DIR}>
$<INSTALL_INTERFACE:include>)

target_link_libraries(acados PUBLIC qpOASES_e hpmpc blasfeo qpdunes)
# HPMPC must come before BLASFEO!
if(NOT CMAKE_C_COMPILER_ID MATCHES "MSVC")
target_link_libraries(acados PUBLIC hpmpc)
endif()
target_link_libraries(acados PUBLIC qpOASES_e blasfeo qpdunes)

# TODO: The following definition should go ASAP!
target_compile_definitions(acados PRIVATE EXT_DEP)
Expand Down
6 changes: 3 additions & 3 deletions acados/ocp_nlp/ocp_nlp_gn_sqp.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int_t ocp_nlp_gn_sqp(const ocp_nlp_in *nlp_in, ocp_nlp_out *nlp_out, void *nlp_a
w[w_idx+j] = gn_sqp_mem->common->x[N][j];
}

acado_timer timer;
acados_timer timer;
real_t timings = 0;
real_t timings_sim = 0;
real_t timings_la = 0;
Expand All @@ -143,7 +143,7 @@ int_t ocp_nlp_gn_sqp(const ocp_nlp_in *nlp_in, ocp_nlp_out *nlp_out, void *nlp_a
real_t feas, stepX, stepU;
int_t status;

acado_tic(&timer);
acados_tic(&timer);

for (int_t sqp_iter = 0; sqp_iter < gn_sqp_args->common->maxIter; sqp_iter++) {
feas = stepX = stepU = -1e10;
Expand Down Expand Up @@ -276,7 +276,7 @@ int_t ocp_nlp_gn_sqp(const ocp_nlp_in *nlp_in, ocp_nlp_out *nlp_out, void *nlp_a
"step U: %+.3e \n", sqp_iter, feas, stepX, stepU);
}

timings += acado_toc(&timer);
timings += acados_toc(&timer);
#ifdef MEASURE_TIMINGS
printf("\nAverage of %.3f ms in the integrator,\n",
1e3*timings_sim/(gn_sqp_args->common->maxIter));
Expand Down
13 changes: 8 additions & 5 deletions acados/ocp_qp/ocp_qp_condensing_qpoases.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
#include "qpOASES_e/QProblemB.h"
#include "qpOASES_e/QProblem.h"
#endif
#else
#include "qpOASES_e/QProblemB.h"
#include "qpOASES_e/QProblem.h"
#endif

#include "acados/ocp_qp/condensing.h"
Expand Down Expand Up @@ -312,7 +315,7 @@ int_t ocp_qp_condensing_qpoases(ocp_qp_in *qp_in, ocp_qp_out *qp_out,
workspace++;
workspace = 0;
mem_ = 0;
mem_++;
(void) mem_;

d_zeros(&A_row_major, work.nconstraints, work.nconvars);
convert_to_row_major(out.A, A_row_major, work.nconstraints, work.nconvars);
Expand Down Expand Up @@ -393,12 +396,12 @@ void ocp_qp_condensing_qpoases_initialize(ocp_qp_in *qp_in, void *args_, void *m
// TODO(dimitris): replace dummy commands once interface completed
args->dummy = 42.0;
if (qp_in->nx[0] > 0)
mem_++;
work++;
(void) mem_;
(void) work;
}

void ocp_qp_condensing_qpoases_destroy(void *mem_, void *work) {
// TODO(dimitris): replace dummy commands once interface completed
mem_++;
work++;
(void) mem_;
(void) work;
}
2 changes: 1 addition & 1 deletion acados/ocp_qp/ocp_qp_hpmpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void ocp_qp_hpmpc_initialize(ocp_qp_in *qp_in, void *args_, void *mem_, void **w
// TODO(andrea): replace dummy commands once interface completed
args->max_iter = args->max_iter;
if (qp_in->nx[0] > 0)
mem_++;
(void) mem_;
work++;
}

Expand Down
14 changes: 7 additions & 7 deletions acados/ocp_qp/ocp_qp_ooqp.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,32 +653,32 @@ int_t ocp_qp_ooqp(ocp_qp_in *in, ocp_qp_out *out, void *args_, void *memory_, vo
// printf("$$ FIRST RUN FLAG %d\n", mem->firstRun);

#ifdef MEASURE_TIMINGS
acado_timer timer;
acados_timer timer;
real_t cputime;
acado_tic(&timer);
acados_tic(&timer);
#endif

// NOTE: has to be called after setting up the memory which contains the problem dimensions
ocp_qp_ooqp_cast_workspace(work, mem);

#ifdef MEASURE_TIMINGS
cputime = acado_toc(&timer);
cputime = acados_toc(&timer);
printf(">>> OOQP workspace casted in %.3f ms.\n", 1e3*cputime);
#endif

#ifdef MEASURE_TIMINGS
acado_tic(&timer);
acados_tic(&timer);
#endif
ocp_qp_ooqp_update_memory(in, args, mem, work);
#ifdef MEASURE_TIMINGS
cputime = acado_toc(&timer);
cputime = acados_toc(&timer);
printf(">>> OOQP memory initialized in %.3f ms.\n", 1e3*cputime);
#endif

if (0) print_inputs(mem);

#ifdef MEASURE_TIMINGS
acado_tic(&timer);
acados_tic(&timer);
#endif
// TODO(dimitris): implement dense OOQP
// call sparse OOQP
Expand All @@ -692,7 +692,7 @@ int_t ocp_qp_ooqp(ocp_qp_in *in, ocp_qp_out *out, void *args_, void *memory_, vo
work->x, work->gamma, work->phi, work->y, work->z, work->lambda, work->pi,
&work->objectiveValue, args->printLevel, &return_value);
#ifdef MEASURE_TIMINGS
cputime = acado_toc(&timer);
cputime = acados_toc(&timer);
printf(">>> OOQP problem solved in %.3f ms.\n\n", 1e3*cputime);
#endif

Expand Down
9 changes: 6 additions & 3 deletions acados/sim/sim_collocation.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ void get_Gauss_nodes(const int_t num_stages, real_t *nodes) {
}

void read_Gauss_simplified(const int_t num_stages, Newton_scheme *scheme) {
real_t D[2*num_stages];
real_t T[num_stages*num_stages];
real_t *D;
D = (real_t *) calloc(2 * num_stages, sizeof(real_t));
real_t *T;
T = (real_t *) calloc(num_stages*num_stages, sizeof(real_t));
char simplified[80];
int_t *perm;
real_t *T_inv;
Expand Down Expand Up @@ -258,7 +260,8 @@ real_t LU_system_solve(real_t* const A, real_t* const b, int* const perm,
int intSwap;
int DIM = dim;
int DIM_RHS = dim2;
real_t bPerm[DIM*DIM_RHS];
real_t *bPerm;
bPerm = (real_t *) calloc(DIM*DIM_RHS, sizeof(real_t));
real_t tmp_var;

for (i = 0; i < DIM; ++i) {
Expand Down
18 changes: 9 additions & 9 deletions acados/sim/sim_erk_integrator.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static void sim_erk_cast_workspace(sim_erk_workspace *work,
if (!in->sens_forw) {
NF = 0;
}
int_t nhess = (int_t)(NF+1)*(real_t)NF/2.0;
int_t nhess = (int_t) (NF+1)*(real_t)NF/2.0;

char *ptr = (char *)work;
ptr += sizeof(sim_erk_workspace);
Expand Down Expand Up @@ -90,7 +90,7 @@ int_t sim_erk(const sim_in *in, sim_out *out, void *args, void *mem, void *work_
}
int_t nhess = (int_t)(NF+1)*(real_t)NF/2.0;

mem = 0; mem += 0;
mem = 0; (void) mem;

real_t *A_mat = opts->A_mat;
real_t *b_vec = opts->b_vec;
Expand All @@ -107,9 +107,9 @@ int_t sim_erk(const sim_in *in, sim_out *out, void *args, void *mem, void *work_
real_t *rhs_adj_in = work->rhs_adj_in;

#ifdef MEASURE_TIMINGS
acado_timer timer, timer_ad;
acados_timer timer, timer_ad;
real_t timing_ad = 0.0;
acado_tic(&timer);
acados_tic(&timer);
#endif
for (i = 0; i < nx; i++) forw_traj[i] = in->x[i];
if (in->sens_forw) {
Expand Down Expand Up @@ -140,11 +140,11 @@ int_t sim_erk(const sim_in *in, sim_out *out, void *args, void *mem, void *work_
}
}
#ifdef MEASURE_TIMINGS
acado_tic(&timer_ad);
acados_tic(&timer_ad);
#endif
in->VDE_forw(rhs_forw_in, &(K_traj[s*nx*(1+NF)]), in->vde); // k evaluation
#ifdef MEASURE_TIMINGS
timing_ad += acado_toc(&timer_ad);
timing_ad += acados_toc(&timer_ad);
#endif
}
for (s = 0; s < num_stages; s++) {
Expand Down Expand Up @@ -199,11 +199,11 @@ int_t sim_erk(const sim_in *in, sim_out *out, void *args, void *mem, void *work_
}
}
#ifdef MEASURE_TIMINGS
acado_tic(&timer_ad);
acados_tic(&timer_ad);
#endif
in->VDE_adj(rhs_adj_in, &(adj_traj[s*nAdj])); // adjoint VDE evaluation
#ifdef MEASURE_TIMINGS
timing_ad += acado_toc(&timer_ad);
timing_ad += acados_toc(&timer_ad);
#endif
}
for (s = 0; s < num_stages; s++) {
Expand All @@ -218,7 +218,7 @@ int_t sim_erk(const sim_in *in, sim_out *out, void *args, void *mem, void *work_
}
}
#ifdef MEASURE_TIMINGS
out->info->CPUtime = acado_toc(&timer);
out->info->CPUtime = acados_toc(&timer);
out->info->LAtime = 0.0;
out->info->ADtime = timing_ad;
#endif
Expand Down
2 changes: 1 addition & 1 deletion acados/sim/sim_erk_integrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int_t sim_erk(const sim_in *in, sim_out *out, void *args, void *mem, void *work)

int_t sim_erk_calculate_workspace_size(const sim_in *in, void *args);

void sim_erk_create_arguments(void *args, int_t num_stages);
void sim_erk_create_arguments(void *args, const int_t num_stages);

void sim_erk_initialize(const sim_in *in, void *args_, void **work);
void sim_erk_destroy(void *work);
Expand Down
Loading

0 comments on commit 1b62ed6

Please sign in to comment.