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

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

More refactoring of the RE system; moved the original re/RE_Compiler to compiler.cpp and the PBIX_Compiler to the re/RE_Compiler.

File size: 7.0 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
49# Check if boost has been installed on this system.
50set(Boost_USE_STATIC_LIBS ON)
51set(Boost_USE_MULTITHREADED OFF) 
52set(Boost_USE_STATIC_RUNTIME OFF)
53include(FindBoost)
54
55add_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)
56
57add_library(RegExpADT re/re_alt.cpp re/re_cc.cpp re/re_end.cpp re/re_name.cpp re/re_parser.cpp re/re_re.cpp re/re_rep.cpp re/re_seq.cpp re/re_start.cpp re/parsefailure.cpp re/re_reducer.cpp re/re_nullable.cpp re/re_simplifier.cpp re/re_compiler.cpp re/symbol_generator.cpp printer_re.cpp)
58
59include_directories("${PROJECT_SOURCE_DIR}")
60include_directories("${PROJECT_SOURCE_DIR}/re")
61include_directories("${PROJECT_SOURCE_DIR}/include")
62include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib")
63include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib/idisa_cpp")
64
65if (Boost_FOUND)
66    include_directories(${Boost_INCLUDE_DIRS})
67endif()
68
69# add the executable
70add_executable(icgrep icgrep.cpp llvm_gen.cpp llvm_gen_helper.cpp utf_encoding.cpp cc_compiler.cpp  cc_compiler_helper.cpp compiler.cpp utf8_encoder.cpp unicode_categories.h unicode_categories-flat.h unicode_categories-simple.h)
71
72target_link_libraries (icgrep PabloADT RegExpADT ${REQ_LLVM_LIBRARIES})
73if (Boost_FOUND)
74    target_link_libraries (icgrep ${Boost_LIBRARIES})
75endif()
76
77
78#Check compiler support for 0x / 11
79include(CheckCXXCompilerFlag)
80CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
81if(COMPILER_SUPPORTS_CXX11)
82  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
83else()
84  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
85  if(COMPILER_SUPPORTS_CXX0X)
86    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
87  else()
88    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
89    if(COMPILER_SUPPORTS_GNU11)
90      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
91    else() 
92      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
93      if(COMPILER_SUPPORTS_GNU0X)
94        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
95      endif()
96    endif()
97  endif()
98endif()
99
100#Check compiler and system support for SSE or AVX
101include(CheckCXXSourceRuns)
102
103set(SSE1_CODE "
104#include <xmmintrin.h>
105int main()
106{
107__m128 a;
108float vals[4] = {0,0,0,0};
109a = _mm_loadu_ps(vals);
110return 0;
111}")
112
113set(SSE2_CODE "
114#include <emmintrin.h>
115int main()
116{
117__m128d a;
118double vals[2] = {0,0};
119a = _mm_loadu_pd(vals);
120return 0;
121}")
122
123set(SSE3_CODE "
124#include <pmmintrin.h>
125int main( )
126{
127const int vals[4] = {0,0,0,0};
128__m128i a;
129a = _mm_lddqu_si128( (const __m128i*)vals );
130return 0;
131}")
132
133set(SSE4_1_CODE "
134#include <smmintrin.h>
135int main ()
136{
137__m128i a, b;
138__m128i res = _mm_max_epi8(a, b);
139return 0;
140}")
141
142set(SSE4_2_CODE "
143#include <nmmintrin.h>
144int main()
145{
146__m128i a, b, c;
147c = _mm_cmpgt_epi64(a, b);
148return 0;
149}")
150
151set(AVX_1_CODE "
152#include <immintrin.h>
153int main()
154{
155__m256* a=(__m256*)_mm_malloc(4, 32);
156__m256 b = _mm256_load_ps((float*)a);
157b = _mm256_or_ps(b, b);
158_mm_free(a);
159return 0;
160}")
161
162set(AVX_2_CODE "
163#include <immintrin.h>
164int main()
165{
166__m256i* a = (__m256i*)_mm_malloc(4, 32);
167__m256i b = _mm256_load_si256(a);
168b = _mm256_or_si256(b, b);
169_mm_free(a);
170return 0;
171}")
172
173IF (MSVC) # using Visual Studio C++
174  SET(ENABLE_SSE1 "/arch:SSE")
175  SET(ENABLE_SSE2 "/arch:SSE2")
176  SET(ENABLE_SSE3 "/arch:SSE3")
177  SET(ENABLE_SSE4_1 "/arch:SSE4")
178  SET(ENABLE_SSE4_2 "/arch:SSE4")
179  SET(ENABLE_AVX_1 "/arch:AVX1")
180  SET(ENABLE_AVX_2 "/arch:AVX2")
181ELSE() # using Clang, GCC, Intel C++, etc
182  SET(ENABLE_SSE1 "-msse")
183  SET(ENABLE_SSE2 "-msse2")
184  SET(ENABLE_SSE3 "-msse3")
185  SET(ENABLE_SSE4_1 "-msse4.1")
186  SET(ENABLE_SSE4_2 "-msse4.2")
187  SET(ENABLE_AVX_1 "-mavx")
188  SET(ENABLE_AVX_2 "-mavx2")   
189ENDIF()
190
191set(CMAKE_REQUIRED_FLAGS)
192set(SIMD_SUPPORT_FOUND)
193
194MACRO(CHECK_SIMD_SUPPORT type) 
195  IF(NOT SIMD_SUPPORT_FOUND) 
196    set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
197    set(CMAKE_REQUIRED_FLAGS ${ENABLE_${type}})
198    check_cxx_source_runs("${${type}_CODE}" ${type})   
199    IF(${type})
200      SET(SIMD_SUPPORT_FOUND ${CMAKE_REQUIRED_FLAGS})
201    ENDIF()
202    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
203  ENDIF()
204ENDMACRO()
205
206CHECK_SIMD_SUPPORT("AVX_2")
207CHECK_SIMD_SUPPORT("AVX_1")
208CHECK_SIMD_SUPPORT("SSE4_2")
209CHECK_SIMD_SUPPORT("SSE4_1")
210CHECK_SIMD_SUPPORT("SSE3")
211CHECK_SIMD_SUPPORT("SSE2")
212CHECK_SIMD_SUPPORT("SSE1")
213
214SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SIMD_SUPPORT_FOUND}")
215
216# detect LLVM version and add compiler flags.
217if (${LLVM_PACKAGE_VERSION} MATCHES "3.4")
218  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_4")
219elseif (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
220  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
221endif(${LLVM_PACKAGE_VERSION} MATCHES "3.4")
222
223if (BLOCK_SIZE_256)
224  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -mavx2 -m64 -fabi-version=6")
225endif()
226
227SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG")
228
229add_test(
230  NAME greptest
231  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
232  COMMAND python greptest.py ${CMAKE_BINARY_DIR}/icgrep)
233
234add_test(
235  NAME abc_test
236  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
237  COMMAND ./run_abc ../icgrep-build/icgrep)
238
239add_custom_target (abc_test
240  COMMAND python abc_testgen.py
241  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
242
243add_custom_target (check
244  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
245  DEPENDS icgrep abc_test)
246
247add_custom_target (perf_icgrep
248  COMMAND python perf.py icgrep
249  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
250  DEPENDS icgrep)
251
252add_custom_target (viewer
253  COMMAND python viewer.py
254  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
255
Note: See TracBrowser for help on using the repository browser.