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

Last change on this file since 4356 was 4356, checked in by cameron, 4 years ago

Improved unicode_categories.h implementation; eliminates uninitialized variable issues

File size: 8.2 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)
53find_package(Boost COMPONENTS system REQUIRED)
54
55add_library(PabloADT pablo/pe_and.cpp pablo/pe_not.cpp pablo/pe_or.cpp  pablo/pabloAST.cpp  pablo/pe_sel.cpp  pablo/pe_xor.cpp pablo/codegenstate.cpp  pablo/symbol_generator.cpp pablo/analysis/useanalysis.cpp pablo/printer_pablos.cpp pablo/pablo_compiler.cpp)
56add_library(RegExpADT re/re_re.cpp re/re_cc.cpp re/re_parser.cpp re/re_rep.cpp re/parsefailure.cpp re/re_nullable.cpp re/re_simplifier.cpp re/re_compiler.cpp re/printer_re.cpp re/re_diff.cpp re/re_intersect.cpp)
57add_library(CCADT cc/cc_namemap.cpp cc/cc_compiler.cpp utf_encoding.cpp utf8_encoder.cpp unicode_categories.h UCD/CaseFolding_txt.cpp)
58
59include_directories("${PROJECT_SOURCE_DIR}")
60include_directories("${PROJECT_SOURCE_DIR}/re")
61include_directories("${PROJECT_SOURCE_DIR}/cc")
62include_directories("${PROJECT_SOURCE_DIR}/pablo")
63include_directories("${PROJECT_SOURCE_DIR}/UCD")
64include_directories("${PROJECT_SOURCE_DIR}/include")
65include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib")
66include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib/idisa_cpp")
67
68# add the executable
69add_executable(icgrep icgrep.cpp do_grep.cpp compiler.cpp)
70
71target_link_libraries (CCADT PabloADT RegExpADT)
72target_link_libraries (PabloADT ${REQ_LLVM_LIBRARIES})
73target_link_libraries (icgrep PabloADT RegExpADT CCADT ${REQ_LLVM_LIBRARIES})
74# If Boost is on the system, include the headers and libraries
75IF(Boost_FOUND)
76    include_directories("${Boost_INCLUDE_DIRS}")
77    link_directories(${Boost_LIBRARY_DIR})
78    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST")
79    target_link_libraries (CCADT ${Boost_LIBRARIES})
80    target_link_libraries (PabloADT ${Boost_LIBRARIES})
81    target_link_libraries (RegExpADT ${Boost_LIBRARIES})
82ENDIF()
83
84#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address")
85
86#Check compiler support for 0x / 11
87include(CheckCXXCompilerFlag)
88CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
89if(COMPILER_SUPPORTS_CXX11)
90  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
91else()
92  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
93  if(COMPILER_SUPPORTS_CXX0X)
94    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
95  else()
96    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
97    if(COMPILER_SUPPORTS_GNU11)
98      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
99    else() 
100      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
101      if(COMPILER_SUPPORTS_GNU0X)
102        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
103      endif()
104    endif()
105  endif()
106endif()
107
108
109#Disable RunTime Type Information
110IF (MSVC) # using Visual Studio C++
111  #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
112ELSE() # using Clang, GCC, Intel C++, etc
113  #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
114ENDIF()
115
116#Enable all warnings
117SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
118
119#Check compiler and system architecture support for SSE or AVX
120include(CheckCXXSourceRuns)
121
122set(SSE1_CODE "
123#include <xmmintrin.h>
124int main()
125{
126__m128 a;
127float vals[4] = {0,0,0,0};
128a = _mm_loadu_ps(vals);
129return 0;
130}")
131
132set(SSE2_CODE "
133#include <emmintrin.h>
134int main()
135{
136__m128d a;
137double vals[2] = {0,0};
138a = _mm_loadu_pd(vals);
139return 0;
140}")
141
142set(SSE3_CODE "
143#include <pmmintrin.h>
144int main( )
145{
146const int vals[4] = {0,0,0,0};
147__m128i a;
148a = _mm_lddqu_si128( (const __m128i*)vals );
149return 0;
150}")
151
152set(SSE4_1_CODE "
153#include <smmintrin.h>
154int main ()
155{
156__m128i a, b;
157__m128i res = _mm_max_epi8(a, b);
158return 0;
159}")
160
161set(SSE4_2_CODE "
162#include <nmmintrin.h>
163int main()
164{
165__m128i a, b, c;
166c = _mm_cmpgt_epi64(a, b);
167return 0;
168}")
169
170set(AVX_1_CODE "
171#include <immintrin.h>
172int main()
173{
174__m256* a=(__m256*)_mm_malloc(4, 32);
175__m256 b = _mm256_load_ps((float*)a);
176b = _mm256_or_ps(b, b);
177_mm_free(a);
178return 0;
179}")
180
181set(AVX_2_CODE "
182#include <immintrin.h>
183int main()
184{
185__m256i* a = (__m256i*)_mm_malloc(4, 32);
186__m256i b = _mm256_load_si256(a);
187b = _mm256_or_si256(b, b);
188_mm_free(a);
189return 0;
190}")
191
192IF (MSVC) # using Visual Studio C++
193  SET(ENABLE_SSE1 "/arch:SSE")
194  SET(ENABLE_SSE2 "/arch:SSE2")
195  SET(ENABLE_SSE3 "/arch:SSE3")
196  SET(ENABLE_SSE4_1 "/arch:SSE4")
197  SET(ENABLE_SSE4_2 "/arch:SSE4")
198  SET(ENABLE_AVX_1 "/arch:AVX1")
199  SET(ENABLE_AVX_2 "/arch:AVX2")
200ELSE() # using Clang, GCC, Intel C++, etc 
201  SET(ENABLE_SSE1 "-msse")
202  SET(ENABLE_SSE2 "-msse2")
203  SET(ENABLE_SSE3 "-msse3")
204  SET(ENABLE_SSE4_1 "-msse4.1")
205  SET(ENABLE_SSE4_2 "-msse4.2")
206  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
207    SET(ENABLE_AVX_1 "-mavx -fabi-version=6")
208    SET(ENABLE_AVX_2 "-mavx2 -fabi-version=6") 
209  ELSE()
210    SET(ENABLE_AVX_1 "-mavx")
211    SET(ENABLE_AVX_2 "-mavx2")
212  ENDIF()
213ENDIF()
214
215set(CMAKE_REQUIRED_FLAGS)
216set(SIMD_SUPPORT_FOUND)
217set(SIMD_MAX_BLOCK_SIZE)
218
219MACRO(CHECK_SIMD_SUPPORT type maxBlockSize)
220  IF(NOT SIMD_SUPPORT_FOUND) 
221    set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
222    set(CMAKE_REQUIRED_FLAGS ${ENABLE_${type}})
223    check_cxx_source_runs("${${type}_CODE}" ${type})   
224    IF(${type})
225      SET(SIMD_SUPPORT_FOUND ${CMAKE_REQUIRED_FLAGS})
226      SET(SIMD_MAX_BLOCK_SIZE ${maxBlockSize})
227    ENDIF()
228    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
229  ENDIF()
230ENDMACRO()
231
232CHECK_SIMD_SUPPORT("AVX_2" 256)
233CHECK_SIMD_SUPPORT("AVX_1" 128)
234CHECK_SIMD_SUPPORT("SSE4_2" 128)
235CHECK_SIMD_SUPPORT("SSE4_1" 128)
236CHECK_SIMD_SUPPORT("SSE3" 128)
237CHECK_SIMD_SUPPORT("SSE2" 128)
238CHECK_SIMD_SUPPORT("SSE1" 128)
239
240SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SIMD_SUPPORT_FOUND}")
241
242# detect LLVM version and add compiler flags.
243if (${LLVM_PACKAGE_VERSION} MATCHES "3.4")
244  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_4")
245elseif (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
246  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
247endif(${LLVM_PACKAGE_VERSION} MATCHES "3.4")
248
249IF (BLOCK_SIZE_256)
250  IF(${SIMD_MAX_BLOCK_SIZE} GREATER 128)
251    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -m64")
252  ELSE()
253    MESSAGE(FATAL_ERROR "AVX2 or better is required for BLOCK_SIZE=256")
254  ENDIF()
255ENDIF()
256
257SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
258
259add_test(
260  NAME greptest
261  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
262  COMMAND python greptest.py ${CMAKE_BINARY_DIR}/icgrep)
263
264add_test(
265  NAME abc_test
266  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
267  COMMAND ./run_abc ../icgrep-build/icgrep)
268
269add_custom_target (abc_test
270  COMMAND python abc_testgen.py
271  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
272
273add_custom_target (check
274  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
275  DEPENDS icgrep abc_test)
276
277add_custom_target (perf_icgrep
278  COMMAND python perf.py icgrep
279  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
280  DEPENDS icgrep)
281
282add_custom_target (viewer
283  COMMAND python viewer.py
284  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
285
286add_custom_target (text_viewer
287  COMMAND python viewer.py -t
288  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
Note: See TracBrowser for help on using the repository browser.