Commit 3c88e578 authored by Rashad Kanavath's avatar Rashad Kanavath

WIP: COMP: active SIMD extension on request (hardware dependent)

parent b373ac39
function(check_sse_features sse_flags )
include(CheckIncludeFile)
include(CheckLibraryExists)
include(CheckCXXSourceRuns)
include(CheckCXXCompilerFlag)
set(has_sse FALSE)
set(${sse_flags} "0" PARENT_SCOPE)
if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
set(CMAKE_REQUIRED_FLAGS "-msse2")
check_cxx_source_runs("
#include <emmintrin.h>
int main()
{
__m128d a, b;
double vals[2] = {0};
a = _mm_loadu_pd(vals);
b = _mm_add_pd(a,a);
_mm_storeu_pd(vals,b);
return 0;
}"
has_sse)
if(has_sse)
message(STATUS "Performing Test CXX_HAS_SSE2 - Success")
set(${sse_flags} "-msse2 -mfpmath=sse" PARENT_SCOPE)
else()
message(STATUS "Performing Test CXX_HAS_SSE2 - Failed")
endif()
set(CMAKE_REQUIRED_FLAGS "-msse")
check_cxx_source_runs("
#include <xmmintrin.h>
int main()
{
__m128 a, b;
float vals[4] = {0};
a = _mm_loadu_ps(vals);
b = a;
b = _mm_add_ps(a,b);
_mm_storeu_ps(vals,b);
return 0;
}"
has_sse)
if(has_sse)
message(STATUS "Performing Test CXX_HAS_SSE - Success")
set(${sse_flags} "-msse -mfpmath=sse" PARENT_SCOPE)
return()
else()
message(STATUS "Performing Test CXX_HAS_SSE - Failed")
return()
endif()
elseif(MSVC)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
return()
endif()
check_cxx_source_runs("
#include <emmintrin.h>
int main()
{
__m128d a, b;
double vals[2] = {0};
a = _mm_loadu_pd(vals);
b = _mm_add_pd(a,a);
_mm_storeu_pd(vals,b);
return 0;
}"
has_sse)
if(has_sse)
message(STATUS "Performing Test CXX_HAS_SSE - Success")
set(${sse_flags} "/arch:SSE2 /fp:fast -D__SSE__ -D__SSE2__" PARENT_SCOPE)
return()
else()
message(STATUS "Performing Test CXX_HAS_SSE - Failed")
return()
endif()
endif()
endfunction() #check_sse_features
......@@ -285,6 +285,19 @@ macro(check_compiler_platform_flags)
message(STATUS "Disabling OpenMP support")
endif()
set(OTB_SSE_FLAGS)
if(OTB_USE_SSE_FLAGS)
include(OTBCheckSSEFeatures)
check_sse_features(OTB_SSE_FLAGS)
endif()
if(OTB_SSE_FLAGS)
message(STATUS "Using SSE2 extensions")
set(OTB_REQUIRED_CXX_FLAGS "${OTB_REQUIRED_CXX_FLAGS} ${OTB_SSE_FLAGS}")
else()
message(STATUS "Not using SSE2 extensions")
endif()
#-----------------------------------------------------------------------------
# The frename-registers option does not work due to a bug in the gnu compiler.
# It must be removed or data errors will be produced and incorrect results
......
......@@ -214,7 +214,7 @@ option(OTB_USE_DEPRECATED "Turn on the use and test of deprecated classes" OFF)
mark_as_advanced(OTB_USE_DEPRECATED)
option(OTB_USE_OPENMP "Add openmp compiler and linker flags" ON)
option(OTB_USE_SSE_FLAGS "Enable SIMD optimisations (hardware dependant)." OFF)
#-----------------------------------------------------------------------------
# SHOW_ALL_MSG_DEBUG option
option(OTB_SHOW_ALL_MSG_DEBUG "Show all debug messages (very verbose)" OFF)
......
......@@ -55,8 +55,6 @@ if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
message(STATUS "Try to compile libsiftfast.cpp done.")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g")
add_definitions(" -Wall -fPIC ")
# check for x86-64 system
check_cxx_source_runs("
......@@ -72,120 +70,30 @@ if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
return 0;
}"
IS_X86_64)
if( IS_X86_64 )
add_definitions("-D__x86_64__")
endif()
else()
set(IS_X86_64 0)
endif()
if(OTB_DISABLE_FAST_FUNCTIONS_VALUE)
add_definitions(-DOTB_DISABLE_FAST_FUNCTIONS)
endif()
include(CheckIncludeFile)
include(CheckLibraryExists)
include(CheckCXXSourceRuns)
include(CheckCXXCompilerFlag)
# if( UNIX OR CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
# set(STDC_LIBRARY stdc++)
# else()
# set(STDC_LIBRARY)
# endif()
#set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g")
#add_xxdefinitions(" -Wall -fPIC ")
# check for SSE extensions
add_library(otbsiftfast libsiftfast.cpp)
if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
set(SSE_FLAGS)
set(CMAKE_REQUIRED_FLAGS "-msse2")
check_cxx_source_runs("
#include <emmintrin.h>
int main()
{
__m128d a, b;
double vals[2] = {0};
a = _mm_loadu_pd(vals);
b = _mm_add_pd(a,a);
_mm_storeu_pd(vals,b);
return 0;
}"
HAS_SSE2_EXTENSIONS)
set(CMAKE_REQUIRED_FLAGS "-msse")
check_cxx_source_runs("
#include <xmmintrin.h>
int main()
{
__m128 a, b;
float vals[4] = {0};
a = _mm_loadu_ps(vals);
b = a;
b = _mm_add_ps(a,b);
_mm_storeu_ps(vals,b);
return 0;
}"
HAS_SSE_EXTENSIONS)
set(CMAKE_REQUIRED_FLAGS)
if(HAS_SSE2_EXTENSIONS)
message(STATUS "Using SSE2 extensions")
set(SSE_FLAGS "-msse2 -mfpmath=sse")
elseif(HAS_SSE_EXTENSIONS)
message(STATUS "Using SSE extensions")
set(SSE_FLAGS "-msse -mfpmath=sse")
endif()
add_definitions(${SSE_FLAGS})
elseif(MSVC)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "Not using SSE2 extensions on x64")
else()
check_cxx_source_runs("
#include <emmintrin.h>
int main()
{
__m128d a, b;
double vals[2] = {0};
a = _mm_loadu_pd(vals);
b = _mm_add_pd(a,a);
_mm_storeu_pd(vals,b);
return 0;
}"
HAS_SSE2_EXTENSIONS)
if( HAS_SSE2_EXTENSIONS )
message(STATUS "Using SSE2 extensions")
add_definitions( "/arch:SSE2 /fp:fast -D__SSE__ -D__SSE2__" )
endif()
endif()
# target_link_libraries(otbsiftfast m stdc++)
target_link_libraries(otbsiftfast m)
endif()
#set(Boost_ADDITIONAL_VERSIONS "1.40" "1.39" "1.38" "1.37.0" "1.37" "1.35.0" "1.34.1" "1.34.0" "1.34" "1.33.1" "1.33.0" "1.33")
#if( NOT $ENV{BOOST_INCLUDEDIR} STREQUAL "" )
# set(Boost_INCLUDE_DIR $ENV{BOOST_INCLUDEDIR})
#endif()
#if( NOT $ENV{BOOST_LIBRARYDIR} STREQUAL "" )
# set(Boost_LIBRARY_DIRS $ENV{BOOST_LIBRARYDIR})
#endif()
#find_package(Boost COMPONENTS python)
#if( Boost_FOUND )
# message(STATUS "found boost version: ${Boost_VERSION}")
#else()
# message(STATUS "Could not find boost libraries!")
#endif()
add_library(otbsiftfast libsiftfast.cpp)
if(IS_X86_64)
set_target_properties(otbsiftfast
PROPERTIES COMPILE_FLAGS "-D__x86_64__")
endif()
if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
# target_link_libraries(otbsiftfast m stdc++)
target_link_libraries(otbsiftfast m)
#set_source_files_properties(<file> PROPERTIES COMPILE_FLAGS <flags>)
if(OTB_DISABLE_FAST_FUNCTIONS_VALUE)
set_target_properties(otbsiftfast
PROPERTIES COMPILE_FLAGS "-DOTB_DISABLE_FAST_FUNCTIONS")
endif()
#set_target_properties(otbsiftfast PROPERTIES OUTPUT_NAME siftfast CLEAN_DIRECT_OUTPUT 1)
......@@ -197,7 +105,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
#Install TARGET & FILES for otb-lib
if(OTB_LIBRARY_PROPERTIES)
set_target_properties(otbsiftfast PROPERTIES ${OTB_LIBRARY_PROPERTIES})
set_target_properties(otbsiftfast PROPERTIES ${OTB_LIBRARY_PROPERTIES})
endif()
install(TARGETS otbsiftfast
......
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