Commit 41e5da8e authored by Berenger Bramas's avatar Berenger Bramas

Update cmake and doc - update the detection of Inastemp included by another...

Update cmake and doc - update the detection of Inastemp included by another project and put the cmake options in the readme
parent a66993ad
......@@ -27,12 +27,33 @@ INCLUDE(CMakeDependentOption)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RELEASE" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo" FORCE)
endif(NOT CMAKE_BUILD_TYPE)
endif()
if($ENV{VERBOSE})
MESSAGE(STATUS "Main -- CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}")
endif()
# Test if inastemp is included as a subproject
if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
set(INASTEMP_AS_SUBPROJECT FALSE)
else()
set(INASTEMP_AS_SUBPROJECT TRUE)
endif()
if($ENV{VERBOSE})
MESSAGE(STATUS "Main -- INASTEMP_AS_SUBPROJECT ${INASTEMP_AS_SUBPROJECT}")
endif()
# Build only the lib if subproject
if(NOT DEFINED INASTEMP_JUST_LIB)
set(INASTEMP_JUST_LIB ${INASTEMP_AS_SUBPROJECT} CACHE BOOL
"Set to on to build the lib for external use (without test and extra flags)" FORCE)
endif()
if($ENV{VERBOSE})
MESSAGE(STATUS "Main -- INASTEMP_JUST_LIB ${INASTEMP_JUST_LIB}")
endif()
#===========================================================================
# Version Number
#===========================================================================
......@@ -108,30 +129,26 @@ list(GET ALL_USED_TYPES -1 INASTEMP_BESTTYPE )
SET( INASTEMP_EXTRA_CXX_FLAGS "-funroll-loops" CACHE STRING "These flags are used for all configurations" )
set(INASTEMP_CXX_FLAGS "${INASTEMP_CXX_FLAGS} ${INASTEMP_EXTRA_CXX_FLAGS}")
SET( INASTEMP_EXTRA_CXX_FLAGS_RELEASE "-O3" CACHE STRING "These flags are added to the usual ones for RELEASE" )
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${INASTEMP_EXTRA_CXX_FLAGS_RELEASE}")
# Options
if(NOT INASTEMP_AS_SUBPROJECT)
SET( INASTEMP_EXTRA_CXX_FLAGS_RELEASE "-O3" CACHE STRING "These flags are added to the usual ones for RELEASE" )
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${INASTEMP_EXTRA_CXX_FLAGS_RELEASE}")
SET( INASTEMP_EXTRA_CXX_FLAGS_DEBUG "-O0" CACHE STRING "These flags are added to the usual ones for DEBUG" )
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_RELEASE} ${INASTEMP_EXTRA_CXX_FLAGS_DEBUG}")
SET( INASTEMP_EXTRA_CXX_FLAGS_DEBUG "-O0" CACHE STRING "These flags are added to the usual ones for DEBUG" )
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${INASTEMP_EXTRA_CXX_FLAGS_DEBUG}")
# Options
set(INASTEMP_CXX_FLAGS "${INASTEMP_CXX_FLAGS} -std=c++11 -fpic -Wextra -Wnon-virtual-dtor -Wshadow -Wpointer-arith -Wcast-qual -Wconversion -Wall -Wno-sign-conversion -pedantic -Woverloaded-virtual -Wpointer-arith -Wcast-qual -Wconversion -Wno-error")
set(INASTEMP_CXX_FLAGS "${INASTEMP_CXX_FLAGS} -fpic -Wextra -Wnon-virtual-dtor -Wshadow -Wpointer-arith -Wcast-qual -Wconversion -Wall -Wno-sign-conversion -pedantic -Wold-style-cast -Woverloaded-virtual -Wpointer-arith -Wcast-qual -Wconversion -Wno-error")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR ${CMAKE_CXX_COMPILER} MATCHES "icpc.*$")
set(INASTEMP_CXX_FLAGS "${INASTEMP_CXX_FLAGS} -diag-disable 2304 -diag-disable 10120 -diag-disable 10121")
else()
set(INASTEMP_CXX_FLAGS "${INASTEMP_CXX_FLAGS} -Wold-style-cast")
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(INASTEMP_CXX_FLAGS "${INASTEMP_CXX_FLAGS} -m64")
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(INASTEMP_CXX_FLAGS "${INASTEMP_CXX_FLAGS} -m64")
OPTION( INASTEMP_ATTACHE_SOURCE "Set to on to add -g flag" OFF )
if( INASTEMP_ATTACHE_SOURCE )
set(INASTEMP_CXX_FLAGS "${INASTEMP_CXX_FLAGS} -g")
endif(INASTEMP_ATTACHE_SOURCE)
endif()
OPTION( INASTEMP_ATTACHE_SOURCE "Set to on to add -g flag" OFF )
if( INASTEMP_ATTACHE_SOURCE )
set(INASTEMP_CXX_FLAGS "${INASTEMP_CXX_FLAGS} -g")
endif(INASTEMP_ATTACHE_SOURCE)
#===========================================================================
# Generate config
#===========================================================================
......@@ -160,10 +177,6 @@ if(NOT INASTEMP_JUST_LIB)
# Build examples
#===========================================================================
add_subdirectory(Examples)
else()
if($ENV{VERBOSE})
MESSAGE(STATUS "Main -- INASTEMP_JUST_LIB ${INASTEMP_JUST_LIB}")
endif()
endif()
#===========================================================================
......@@ -175,13 +188,13 @@ configure_file(${INASTEMP_SOURCE_DIR}/CMakeModules/InastempInfo.cmake.in
)
install(FILES ${INASTEMP_BINARY_DIR}/InastempInfo.cmake DESTINATION lib/ )
if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
# nothing - we are not used by another lib here
else()
if(INASTEMP_AS_SUBPROJECT)
set(INASTEMP_CXX_FLAGS "${INASTEMP_CXX_FLAGS}" PARENT_SCOPE)
set(INASTEMP_BINARY_DIR "${INASTEMP_BINARY_DIR}" PARENT_SCOPE)
set(INASTEMP_SOURCE_DIR "${INASTEMP_SOURCE_DIR}" PARENT_SCOPE)
set(INASTEMP_INCLUDE_DIR "${INASTEMP_INCLUDE_DIR}" PARENT_SCOPE)
else()
# nothing - we are not used by another lib here
endif()
......
......@@ -63,6 +63,8 @@ Template C++ source-code Compiled Template C++ code
## Compilation
### Basic compilation
```bash
# Create a Build directory
mkdir Build
......@@ -70,33 +72,77 @@ mkdir Build
cd Build
# Run cmake - considering Inastemp is the upper directory
cmake ..
# OR with more output
# OR with more output messages
VERBOSE=1 cmake ..
# Then make will build the unit test and examples
make
```
Inastemp was developed and tested using the following compilers on the x86_64 architecture.
- Gcc 6.1 (earlier versions if AVX512/KNL is not used)
- Clang 3.5
- Intel 16.0
Earlier versions may work as well.
### CMake variables - Hardware detection
There are two hardware detections:
- the instructions supported by the compiler
- the instructions supported by the current CPU
For each existing vector type in Inastemp, the cmake stage runs both tests.
The results are print out if `VERBOSE=1`.
If a vector type can be compiled, it creates the cmake variable `INASTEMP_USE_X` where `X` could be `SSE3`, `AVX2`, etc.
Then, all the vector types that are supported by the CPU are turned to `ON` by default.
So it is possible to turn on specific options even if the CPU does not support them (to execute over intel SDE for example).
But if an options does not exist (even if the hardware seems appropriate) it means that the compiler does not support it.
For example, here is a part of the output of the `ccmake ..` command on a AVX2 CPU and using GCC 6.1:
```
INASTEMP_USE_AVX ON
INASTEMP_USE_AVX2 ON
INASTEMP_USE_AVX512KNL OFF
INASTEMP_USE_SSE3 ON
INASTEMP_USE_SSE41 ON
INASTEMP_USE_SSE42 ON
INASTEMP_USE_SSSE3 ON
```
`AVX512KNL` is supported by the compiler but not by the hardware, so it is turned `OFF` but could be turn to `ON` if needed.
By turning the cmake variable `INASTEMP_ISDE_CPU` to `ON` the hardware detection is done over intel SDE.
In this case, one can ask Inastemp to check any hardware (passing the appropriate options to isde).
### Using Inastemp as a sub-project with CMake
Considering that the folder `inastemp exist in the root directory of the project, one could use:
```
# inastemp
## inastemp inclusion in CMakeLists.txt of the other project
# tell inastemp we do not want examples/tests
# (will be detected automatically otherwise because it is included as a subproject)
set(INASTEMP_JUST_LIB TRUE)
add_subdirectory(ext/inastemp)
# add the cmakelist directory
add_subdirectory(inastemp)
# use the filled variables from inastemp
INCLUDE_DIRECTORIES(
${INASTEMP_BINARY_DIR}/Src
${INASTEMP_SOURCE_DIR}/Src
${INASTEMP_INCLUDE_DIR}
)
# propagate the flags to be able to compile
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${INASTEMP_CXX_FLAGS}")
```
The statement `set(INASTEMP_JUST_LIB TRUE)` ask inastemp not to compile tests/examples.
The statement `set(INASTEMP_JUST_LIB TRUE)` asks inastemp not to compile tests/examples and to limit inclusion of extra warning flags in `INASTEMP_CXX_FLAGS`.
The inclusion of Inastemp as a subproject does not modify the variables of the upper project.
This is why we use the variables `${INASTEMP_CXX_FLAGS}` explicitly to transfer the hardware specific flags.
### Compilers support
Inastemp was developed and tested using the following compilers on the x86_64 architecture.
- Gcc 6.1 (earlier versions if AVX512/KNL is not used)
- Clang 3.5
- Intel 16.0
Earlier versions may work as well.
### Multiple hardwares compilation
Inastemp is not designed to compile a binary targeting multiple hardwares (like having an execution path for the different possibilities).
If such need appears, let us know and we might enable it in a next release.
## Best practices
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment