source: icGREP/icgrep-devel/icgrep/CMakeLists.txt @ 4152

Last change on this file since 4152 was 4152, checked in by nmedfort, 5 years ago

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

File size: 6.6 KB
Line 
1cmake_minimum_required (VERSION 2.8)
2
3project (icgrep)
4
5enable_testing()
6# The version number.
7set (icgrep_VERSION_MAJOR 0)
8set (icgrep_VERSION_MINOR 8)
9
10option(BLOCK_SIZE_256 "Compiling with BLOCK_SIZE=256")
11if (BLOCK_SIZE_256)
12  message("-- Build with BLOCK_SIZE=256")
13else ()
14  message("-- Build with BLOCK_SIZE=128")
15endif()
16
17# configure a header file to pass some of the CMake settings
18# to the source code
19#configure_file (
20#  "${PROJECT_SOURCE_DIR}/icgrepconfig.h.in"
21#  "${PROJECT_BINARY_DIR}/icgrepconfig.h"
22#  )
23
24# LLVM set up
25#
26# A convenience variable:
27set(LLVM_ROOT "../libllvm" CACHE PATH "Root of LLVM install.")
28
29# A bit of a sanity check:
30if( NOT EXISTS ${LLVM_ROOT}/include/llvm )
31message(FATAL_ERROR "LLVM_ROOT (${LLVM_ROOT}) is not a valid LLVM install")
32endif()
33
34# We incorporate the CMake features provided by LLVM:
35set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT}/share/llvm/cmake")
36include(LLVMConfig)
37
38# Now set the header and library paths:
39include_directories( ${LLVM_INCLUDE_DIRS} )
40link_directories( ${LLVM_LIBRARY_DIRS} )
41add_definitions( ${LLVM_DEFINITIONS} )
42
43# Let's suppose we want to build a JIT compiler with support for
44# binary code (no interpreter):
45llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES mcjit native)
46
47message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
48
49add_library(PabloADT pe_advance.cpp  pe_all.cpp  pe_and.cpp pe_call.cpp pe_charclass.cpp  pe_matchstar.cpp pe_scanthru.cpp pe_not.cpp  pe_or.cpp  pe_pabloe.cpp  pe_sel.cpp  pe_var.cpp  pe_xor.cpp ps_assign.cpp  ps_if.cpp  ps_pablos.cpp  ps_while.cpp printer_pablos.cpp)
50
51add_library(RegExpADT re_alt.cpp  re_cc.cpp  re_end.cpp  re_name.cpp re_parser.cpp  re_re.cpp  re_rep.cpp  re_seq.cpp  re_start.cpp parsefailure.cpp  parseresult.cpp  parsesuccess.cpp printer_re.cpp)
52
53
54
55#include_directories("${PROJECT_BINARY_DIR}")
56include_directories("${PROJECT_SOURCE_DIR}")
57include_directories("${PROJECT_SOURCE_DIR}/include")
58include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib")
59include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib/idisa_cpp")
60
61# add the executable
62add_executable(icgrep icgrep.cpp llvm_gen.cpp llvm_gen_helper.cpp utf_encoding.cpp cc_compiler.cpp  cc_compiler_helper.cpp re_simplifier.cpp re_reducer.cpp re_nullable.cpp re_compiler.cpp pbix_compiler.cpp  symbol_generator.cpp utf8_encoder.cpp unicode_categories.h unicode_categories-flat.h unicode_categories-simple.h)
63
64target_link_libraries (icgrep PabloADT RegExpADT ${REQ_LLVM_LIBRARIES})
65
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}")
203
204# detect LLVM version and add compiler flags.
205if (${LLVM_PACKAGE_VERSION} MATCHES "3.4")
206  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_4")
207elseif (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
208  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
209endif(${LLVM_PACKAGE_VERSION} MATCHES "3.4")
210
211if (BLOCK_SIZE_256)
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")
216
217add_test(
218  NAME greptest
219  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
220  COMMAND python greptest.py ${CMAKE_BINARY_DIR}/icgrep)
221
222add_test(
223  NAME abc_test
224  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
225  COMMAND ./run_abc ../icgrep-build/icgrep)
226
227add_custom_target (abc_test
228  COMMAND python abc_testgen.py
229  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
230
231add_custom_target (check
232  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
233  DEPENDS icgrep abc_test)
234
235add_custom_target (perf_icgrep
236  COMMAND python perf.py icgrep
237  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
238  DEPENDS icgrep)
239
240add_custom_target (viewer
241  COMMAND python viewer.py
242  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
243
Note: See TracBrowser for help on using the repository browser.