Changeset 4152


Ignore:
Timestamp:
Sep 11, 2014, 4:23:25 PM (5 years ago)
Author:
nmedfort
Message:

Added tests for cxx11 / cxx0x and sse/avx support. Kept Meng's changes for BLOCK_SIZE_256 as is.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r4151 r4152  
    6464target_link_libraries (icgrep PabloADT RegExpADT ${REQ_LLVM_LIBRARIES})
    6565
    66 set(CMAKE_CXX_FLAGS_RELEASE "-std=c++11 -O3 -msse2")
     66#Check compiler support for 0x / 11
     67include(CheckCXXCompilerFlag)
     68CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
     69if(COMPILER_SUPPORTS_CXX11)
     70  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
     71else()
     72  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
     73  if(COMPILER_SUPPORTS_CXX0X)
     74    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
     75  else()
     76    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
     77    if(COMPILER_SUPPORTS_GNU11)
     78      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
     79    else() 
     80      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
     81      if(COMPILER_SUPPORTS_GNU0X)
     82        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
     83      endif()
     84    endif()
     85  endif()
     86endif()
     87
     88#Check compiler and system support for SSE or AVX
     89include(CheckCXXSourceRuns)
     90
     91set(SSE1_CODE "
     92#include <xmmintrin.h>
     93int main()
     94{
     95__m128 a;
     96float vals[4] = {0,0,0,0};
     97a = _mm_loadu_ps(vals);
     98return 0;
     99}")
     100
     101set(SSE2_CODE "
     102#include <emmintrin.h>
     103int main()
     104{
     105__m128d a;
     106double vals[2] = {0,0};
     107a = _mm_loadu_pd(vals);
     108return 0;
     109}")
     110
     111set(SSE3_CODE "
     112#include <pmmintrin.h>
     113int main( )
     114{
     115const int vals[4] = {0,0,0,0};
     116__m128i a;
     117a = _mm_lddqu_si128( (const __m128i*)vals );
     118return 0;
     119}")
     120
     121set(SSE4_1_CODE "
     122#include <smmintrin.h>
     123int main ()
     124{
     125__m128i a, b;
     126__m128i res = _mm_max_epi8(a, b);
     127return 0;
     128}")
     129
     130set(SSE4_2_CODE "
     131#include <nmmintrin.h>
     132int main()
     133{
     134__m128i a, b, c;
     135c = _mm_cmpgt_epi64(a, b);
     136return 0;
     137}")
     138
     139set(AVX_1_CODE "
     140#include <immintrin.h>
     141int main()
     142{
     143__m256* a=(__m256*)_mm_malloc(4, 32);
     144__m256 b = _mm256_load_ps((float*)a);
     145b = _mm256_or_ps(b, b);
     146_mm_free(a);
     147return 0;
     148}")
     149
     150set(AVX_2_CODE "
     151#include <immintrin.h>
     152int main()
     153{
     154__m256i* a = (__m256i*)_mm_malloc(4, 32);
     155__m256i b = _mm256_load_si256(a);
     156b = _mm256_or_si256(b, b);
     157_mm_free(a);
     158return 0;
     159}")
     160
     161IF (MSVC) # using Visual Studio C++
     162  SET(ENABLE_SSE1 "/arch:SSE")
     163  SET(ENABLE_SSE2 "/arch:SSE2")
     164  SET(ENABLE_SSE3 "/arch:SSE3")
     165  SET(ENABLE_SSE4_1 "/arch:SSE4")
     166  SET(ENABLE_SSE4_2 "/arch:SSE4")
     167  SET(ENABLE_AVX_1 "/arch:AVX1")
     168  SET(ENABLE_AVX_2 "/arch:AVX2")
     169ELSE() # using Clang, GCC, Intel C++, etc
     170  SET(ENABLE_SSE1 "-msse")
     171  SET(ENABLE_SSE2 "-msse2")
     172  SET(ENABLE_SSE3 "-msse3")
     173  SET(ENABLE_SSE4_1 "-msse4.1")
     174  SET(ENABLE_SSE4_2 "-msse4.2")
     175  SET(ENABLE_AVX_1 "-mavx")
     176  SET(ENABLE_AVX_2 "-mavx2")   
     177ENDIF()
     178
     179set(CMAKE_REQUIRED_FLAGS)
     180set(SIMD_SUPPORT_FOUND)
     181
     182MACRO(CHECK_SIMD_SUPPORT type) 
     183  IF(NOT SIMD_SUPPORT_FOUND) 
     184    set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
     185    set(CMAKE_REQUIRED_FLAGS ${ENABLE_${type}})
     186    check_cxx_source_runs("${${type}_CODE}" ${type})   
     187    IF(${type})
     188      SET(SIMD_SUPPORT_FOUND ${CMAKE_REQUIRED_FLAGS})
     189    ENDIF()
     190    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
     191  ENDIF()
     192ENDMACRO()
     193
     194CHECK_SIMD_SUPPORT("AVX_2")
     195CHECK_SIMD_SUPPORT("AVX_1")
     196CHECK_SIMD_SUPPORT("SSE4_2")
     197CHECK_SIMD_SUPPORT("SSE4_1")
     198CHECK_SIMD_SUPPORT("SSE3")
     199CHECK_SIMD_SUPPORT("SSE2")
     200CHECK_SIMD_SUPPORT("SSE1")
     201
     202SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SIMD_SUPPORT_FOUND}")
    67203
    68204# detect LLVM version and add compiler flags.
    69205if (${LLVM_PACKAGE_VERSION} MATCHES "3.4")
    70   set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DUSE_LLVM_3_4")
     206  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_4")
    71207elseif (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
    72   set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DUSE_LLVM_3_5")
     208  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
    73209endif(${LLVM_PACKAGE_VERSION} MATCHES "3.4")
    74210
    75211if (BLOCK_SIZE_256)
    76   set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -mavx2 -m64 -fabi-version=6")
    77 endif()
     212  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -mavx2 -m64 -fabi-version=6")
     213endif()
     214
     215SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG")
    78216
    79217add_test(
Note: See TracChangeset for help on using the changeset viewer.