Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 8 additions & 195 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,199 +1,12 @@
################################################################################
#
# Project settings
#
################################################################################
cmake_minimum_required (VERSION 2.8)
project (HPMPC)

#
# Minimum required version of cmake
#
CMAKE_MINIMUM_REQUIRED( VERSION 2.8 )
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH})

#
# Project name and programming languages used
#
PROJECT( HPMPC C )
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

#
# Folder path for generated executables
#
SET( EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin )
include(CompilerOptions.cmake)

#
# Folder path for generated libraries
#
SET( LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib )

################################################################################
#
# User configuration
#
################################################################################

IF( NOT CMAKE_VERBOSE_MAKEFILE )
SET( CMAKE_VERBOSE_MAKEFILE OFF )
ENDIF( NOT CMAKE_VERBOSE_MAKEFILE )

#
# Build type
#
IF( NOT CMAKE_BUILD_TYPE )
SET(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE
)
ENDIF( NOT CMAKE_BUILD_TYPE )

#
# Target type
#
IF ( NOT HPMPC_TARGET )
SET( HPMPC_TARGET X64_AVX CACHE STRING
"Choose build target: X64_AVX2, X64_AVX, X64_SSE3, CORTEX_A57, CORTEX_A15, CORTEX_A9, CORTEX_A7, C99_4x4"
)
ENDIF( )

################################################################################
#
# Compiler settings
#
################################################################################

SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC" )

IF ( ${HPMPC_TARGET} STREQUAL "X64_AVX2" )
ADD_DEFINITIONS( -DTARGET_X64_AVX2 )
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -m64 -mavx2 -mfma")

ELSEIF ( ${HPMPC_TARGET} STREQUAL "X64_AVX" )
ADD_DEFINITIONS( -DTARGET_X64_AVX )
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -m64 -mavx")

ELSEIF ( ${HPMPC_TARGET} STREQUAL "X64_SSE3" )
ADD_DEFINITIONS( -DTARGET_X64_SSE3 )
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -m64 -msse3")

ELSEIF ( ${HPMPC_TARGET} STREQUAL "CORTEX_A57" )
ADD_DEFINITIONS( -DTARGET_CORTEX_A57 )
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=armv8-a+fp+simd -mcpu=cortex-a57")

ELSEIF ( ${HPMPC_TARGET} STREQUAL "CORTEX_A15" )
ADD_DEFINITIONS( -DTARGET_CORTEX_A15 )
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -marm -mfloat-abi=hard -mfpu=neon-vfpv4 -mcpu=cortex-a15")

ELSEIF ( ${HPMPC_TARGET} STREQUAL "CORTEX_A9" )
ADD_DEFINITIONS( -DTARGET_CORTEX_A9 )
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -marm -mfloat-abi=hard -mfpu=neon -mcpu=cortex-a9")

ELSEIF ( ${HPMPC_TARGET} STREQUAL "CORTEX_A7" )
ADD_DEFINITIONS( -DTARGET_CORTEX_A7 )
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -marm -mfloat-abi=hard -mfpu=neon-vfpv4 -mcpu=cortex-a7")

ELSEIF ( ${HPMPC_TARGET} STREQUAL "C99_4X4" )
ADD_DEFINITIONS( -DTARGET_C99_4X4 )
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=native")

ELSEIF ( ${HPMPC_TARGET} STREQUAL "C99_4X4_PREFETCH" )
ADD_DEFINITIONS( -DTARGET_C99_4X4_PREFETCH )
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=native")

ELSE( )
MESSAGE( ERROR "You chose unsupported target ${HPMPC_TARGET}")
ENDIF( )

# Link math library against all targets
LINK_LIBRARIES( m )

# This will add the "make test" target
ENABLE_TESTING()

################################################################################
#
# Configure the target header file
#
################################################################################

STRING(TOUPPER ${HPMPC_TARGET} TARGET_DEF)
SET( TARGET_DEF TARGET_${TARGET_DEF})

CONFIGURE_FILE(
"${PROJECT_SOURCE_DIR}/include/target.h.in"
"${PROJECT_SOURCE_DIR}/include/target.h"
@ONLY
)

################################################################################
#
# Include directories
#
################################################################################

INCLUDE_DIRECTORIES( include )

################################################################################
#
# Build the library
#
################################################################################

MESSAGE( STATUS "Compiling the library for ${HPMPC_TARGET} target")

#
# Macro for adding source files
#
MACRO( HPMPC_ADD_SOURCE_FILES )
# MESSAGE( STATUS "${ARGV}" )
UNSET( _SRC )
FOREACH( SRC ${ARGV} )
GET_FILENAME_COMPONENT(ABS_SRC ${SRC} REALPATH)
SET( _SRC ${_SRC} ${ABS_SRC} )
ENDFOREACH()
SET ( SOURCES ${SOURCES} ${_SRC} PARENT_SCOPE )
ENDMACRO( HPMPC_ADD_SOURCE_FILES )

#
# Add source folders
#
UNSET( SOURCES )
ADD_SUBDIRECTORY( kernel )
ADD_SUBDIRECTORY( blas )
ADD_SUBDIRECTORY( auxiliary )
ADD_SUBDIRECTORY( lqcp_solvers )
ADD_SUBDIRECTORY( mpc_solvers )
ADD_SUBDIRECTORY( interfaces )
ADD_SUBDIRECTORY( reference_code )
#ADD_SUBDIRECTORY( codegen )

#
# Add library
#
ADD_LIBRARY( hpmpc STATIC ${SOURCES} )

################################################################################
#
# Installation rules
#
################################################################################

INSTALL(
DIRECTORY
include/
DESTINATION
include/hpmpc
PATTERN "*.h.in*" EXCLUDE
)

INSTALL(
TARGETS
hpmpc
DESTINATION
lib
)

################################################################################
#
# Build examples
#
################################################################################

ADD_SUBDIRECTORY( test_problems )
add_subdirectory(test)
56 changes: 56 additions & 0 deletions CompilerOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
################################################################################
#
# Compiler settings - General
#
################################################################################

INCLUDE( CheckCXXCompilerFlag )

################################################################################
#
# Compiler settings - GCC/G++; Linux, Apple
#
################################################################################
MESSAGE(CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID})
IF ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" )

SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fPIC" )

################################################################################
#
# Compiler settings - MS Visual Studio; Windows
#
################################################################################
ELSEIF( MSVC )
# On MSVC, use statically linked C runtime for release builds (to avoid problems with missing runtime).
SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /D NDEBUG")
SET(CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1")

SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nologo -EHsc " )

#
# Some common definitions
#
ADD_DEFINITIONS( -DWIN32 )
#ADD_DEFINITIONS( -D__NO_COPYRIGHT__ )
#ADD_DEFINITIONS( -Dsnprintf=_snprintf )
#ADD_DEFINITIONS( -Dusleep=Sleep )
#ADD_DEFINITIONS( -Dsleep=Sleep )
#ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS )
#ADD_DEFINITIONS( -D_SCL_SECURE_NO_WARNINGS )
#ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
#ADD_DEFINITIONS(-D_SCL_SECURE_NO_DEPRECATE)
#ADD_DEFINITIONS(-D_SECURE_SCL=0)
#ADD_DEFINITIONS(-D_ITERATOR_DEBUG_LEVEL=0)
#ADD_DEFINITIONS( -D__NO_PIPES__ )
#ADD_DEFINITIONS( "/wd4068")

#
# Enable project grouping when making Visual Studio solution
# NOTE: This feature is NOT supported in Express editions
#
SET_PROPERTY( GLOBAL PROPERTY USE_FOLDERS ON )

ENDIF( )


23 changes: 20 additions & 3 deletions include/c_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#include "target.h"
#include "block_size.h"


#ifdef __cplusplus
extern "C" {
#endif

// work space: dynamic definition as function return value

Expand All @@ -46,8 +48,23 @@ int fortran_order_d_ip_mpc_hard_tv( int *kk, int k_max, double mu0, double mu_to


// new interfaces
int c_order_d_ip_ocp_hard_tv(int *kk, int k_max, double mu0, double mu_tol, int N, int *nx, int *nu, int *nb, int *ng, int warm_start, double **A, double **B, double **b, double **Q, double **S, double **R, double **q, double **r, double **lb, double **ub, double **C, double **D, double **lg, double **ug, double **x, double **u, double **pi, double **lam, double **t, double *inf_norm_res, void *work0, double *stat);
int c_order_d_ip_ocp_hard_tv(
int *kk, int k_max, double mu0, double mu_tol,
int N, int const *nx, int const *nu, int const *nb, int const *ng,
int warm_start,
double const * const *A, double const * const *B, double const * const *b,
double const * const *Q, double const * const *S, double const * const *R, double const * const *q, double const * const *r,
double const * const *lb, double const * const *ub,
double const * const *C, double const * const *D, double const * const *lg, double const * const *ug,
double * const *x, double * const *u, double * const *pi, double * const *lam, double * const *t,
double *inf_norm_res,
void *work0,
double *stat);

int fortran_order_d_ip_ocp_hard_tv(int *kk, int k_max, double mu0, double mu_tol, int N, int *nx, int *nu, int *nb, int *ng, int warm_start, double **A, double **B, double **b, double **Q, double **S, double **R, double **q, double **r, double **lb, double **ub, double **C, double **D, double **lg, double **ug, double **x, double **u, double **pi, double **lam, double **t, double *inf_norm_res, void *work0, double *stat);
int hpmpc_d_ip_ocp_hard_tv_work_space_size_bytes(int N, int *nx, int *nu, int *nb, int *ng);
int hpmpc_d_ip_ocp_hard_tv_work_space_size_bytes(int N, int const *nx, int const *nu, int const *nb, int const *ng);


#ifdef __cplusplus
} // extern "C"
#endif
2 changes: 1 addition & 1 deletion interfaces/c/c_interface_work_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int hpmpc_d_ip_mpc_hard_tv_work_space_size_bytes(int N, int nx, int nu, int nb,



int hpmpc_d_ip_ocp_hard_tv_work_space_size_bytes(int N, int *nx, int *nu, int *nb, int *ng)
int hpmpc_d_ip_ocp_hard_tv_work_space_size_bytes(int N, int const *nx, int const *nu, int const *nb, int const *ng)
{

const int bs = D_MR; //d_get_mr();
Expand Down
14 changes: 8 additions & 6 deletions interfaces/c/c_order_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
// TODO add indx to the interface ????
int c_order_d_ip_ocp_hard_tv(
int *kk, int k_max, double mu0, double mu_tol,
int N, int *nx, int *nu_N, int *nb, int *ng,
int N, int const *nx, int const *nu_N, int const *nb, int const *ng,
int warm_start,
double **A, double **B, double **b,
double **Q, double **S, double **R, double **q, double **r,
double **lb, double **ub,
double **C, double **D, double **lg, double **ug,
double **x, double **u, double **pi, double **lam, double **t,
double const * const *A, double const * const *B, double const * const *b,
double const * const *Q, double const * const *S, double const * const *R, double const * const *q, double const * const *r,
double const * const *lb, double const * const *ub,
double const * const *C, double const * const *D, double const * const *lg, double const * const *ug,
double * const *x, double * const *u, double * const *pi, double * const *lam, double * const *t,
double *inf_norm_res,
void *work0,
double *stat)
Expand Down Expand Up @@ -477,6 +477,8 @@ int c_order_d_ip_ocp_hard_tv(

inf_norm_res[3] = mu;

d_print_mat(1, 4, inf_norm_res, 1);



// copy back multipliers
Expand Down
24 changes: 24 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# HPMPC/test
#

#enable_testing()
find_package(GTest REQUIRED)
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})

set(SRC
hpmpc_test.cpp
test_qp.cpp
)

add_executable(hpmpc_test ${SRC})

target_link_libraries(hpmpc_test ${PROJECT_SOURCE_DIR}/libhpmpc.a ${GTEST_BOTH_LIBRARIES})

if (UNIX)
# On UNIX, link to pthread -- gtest requires it.
target_link_libraries(hpmpc_test pthread)
endif (UNIX)

#add_test(AllTests mpc_test)
Loading