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

Last change on this file since 4533 was 4522, checked in by cameron, 5 years ago

Catch std::runtime_error and report; sanitize only on Linux

File size: 8.4 KB
RevLine 
[3850]1cmake_minimum_required (VERSION 2.8)
2
3project (icgrep)
4
[4096]5enable_testing()
[3850]6# The version number.
[4508]7set (icgrep_VERSION_MAJOR 1)
8set (icgrep_VERSION_MINOR 0)
[4096]9
[4151]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
[3850]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):
[4480]45llvm_map_components_to_libnames(REQ_LLVM_LIBRARIES mcjit native)
[3850]46
[4118]47message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
[4096]48
[4196]49# Check if boost has been installed on this system.
[4210]50set(Boost_USE_STATIC_LIBS ON)
51set(Boost_USE_MULTITHREADED OFF)
52set(Boost_USE_STATIC_RUNTIME OFF)
[4416]53find_package(Boost)
[4212]54
[4516]55add_library(PabloADT pablo/pabloAST.cpp pablo/ps_assign.cpp pablo/ps_if.cpp pablo/ps_while.cpp pablo/codegenstate.cpp pablo/symbol_generator.cpp pablo/printer_pablos.cpp pablo/pablo_compiler.cpp pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/pablo_codesinking.cpp)
[4393]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 re/re_analysis.cpp)
[4418]57add_library(CCADT cc/cc_namemap.cpp cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
[4427]58add_library(UCDlib UCD/unicode_set.cpp UCD/precompiled_gc.cpp UCD/precompiled_sc.cpp UCD/precompiled_scx.cpp UCD/precompiled_blk.cpp UCD/precompiled_derivedcoreproperties.cpp UCD/precompiled_proplist.cpp)
[4198]59
[4096]60include_directories("${PROJECT_SOURCE_DIR}")
[4197]61include_directories("${PROJECT_SOURCE_DIR}/re")
[4198]62include_directories("${PROJECT_SOURCE_DIR}/cc")
63include_directories("${PROJECT_SOURCE_DIR}/pablo")
[4316]64include_directories("${PROJECT_SOURCE_DIR}/UCD")
[3850]65include_directories("${PROJECT_SOURCE_DIR}/include")
66include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib")
67include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib/idisa_cpp")
[4096]68
[3850]69# add the executable
[4324]70add_executable(icgrep icgrep.cpp do_grep.cpp compiler.cpp)
[3850]71
[4249]72target_link_libraries (CCADT PabloADT RegExpADT)
73target_link_libraries (PabloADT ${REQ_LLVM_LIBRARIES})
[4380]74target_link_libraries (icgrep UCDlib PabloADT RegExpADT CCADT ${REQ_LLVM_LIBRARIES})
[4212]75# If Boost is on the system, include the headers and libraries
76IF(Boost_FOUND)
77    include_directories("${Boost_INCLUDE_DIRS}")
78    link_directories(${Boost_LIBRARY_DIR})
[4210]79    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST")
[4416]80    # target_link_libraries (CCADT ${Boost_LIBRARIES})
81    # target_link_libraries (PabloADT ${Boost_LIBRARIES})
82    # target_link_libraries (RegExpADT ${Boost_LIBRARIES})
[4210]83ENDIF()
[3916]84
[4152]85#Check compiler support for 0x / 11
86include(CheckCXXCompilerFlag)
87CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
88if(COMPILER_SUPPORTS_CXX11)
89  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
90else()
91  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
92  if(COMPILER_SUPPORTS_CXX0X)
93    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
94  else()
95    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
96    if(COMPILER_SUPPORTS_GNU11)
97      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
98    else() 
99      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
100      if(COMPILER_SUPPORTS_GNU0X)
101        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
102      endif()
103    endif()
104  endif()
105endif()
[4096]106
[4210]107
[4200]108#Disable RunTime Type Information
109IF (MSVC) # using Visual Studio C++
[4436]110  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
[4200]111ELSE() # using Clang, GCC, Intel C++, etc
[4436]112  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
[4200]113ENDIF()
114
[4227]115#Enable all warnings
[4356]116SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
[4200]117
118#Check compiler and system architecture support for SSE or AVX
[4152]119include(CheckCXXSourceRuns)
120
121set(SSE1_CODE "
122#include <xmmintrin.h>
123int main()
124{
125__m128 a;
126float vals[4] = {0,0,0,0};
127a = _mm_loadu_ps(vals);
128return 0;
129}")
130
131set(SSE2_CODE "
132#include <emmintrin.h>
133int main()
134{
135__m128d a;
136double vals[2] = {0,0};
137a = _mm_loadu_pd(vals);
138return 0;
139}")
140
141set(SSE3_CODE "
142#include <pmmintrin.h>
143int main( )
144{
145const int vals[4] = {0,0,0,0};
146__m128i a;
147a = _mm_lddqu_si128( (const __m128i*)vals );
148return 0;
149}")
150
151set(SSE4_1_CODE "
152#include <smmintrin.h>
153int main ()
154{
155__m128i a, b;
156__m128i res = _mm_max_epi8(a, b);
157return 0;
158}")
159
160set(SSE4_2_CODE "
161#include <nmmintrin.h>
162int main()
163{
164__m128i a, b, c;
165c = _mm_cmpgt_epi64(a, b);
166return 0;
167}")
168
[4480]169set(AVX1_CODE "
[4152]170#include <immintrin.h>
171int main()
172{
173__m256* a=(__m256*)_mm_malloc(4, 32);
174__m256 b = _mm256_load_ps((float*)a);
175b = _mm256_or_ps(b, b);
176_mm_free(a);
177return 0;
178}")
179
[4480]180set(AVX2_CODE "
[4152]181#include <immintrin.h>
182int main()
183{
184__m256i* a = (__m256i*)_mm_malloc(4, 32);
185__m256i b = _mm256_load_si256(a);
186b = _mm256_or_si256(b, b);
187_mm_free(a);
188return 0;
189}")
190
191IF (MSVC) # using Visual Studio C++
192  SET(ENABLE_SSE1 "/arch:SSE")
193  SET(ENABLE_SSE2 "/arch:SSE2")
194  SET(ENABLE_SSE3 "/arch:SSE3")
195  SET(ENABLE_SSE4_1 "/arch:SSE4")
196  SET(ENABLE_SSE4_2 "/arch:SSE4")
[4480]197  SET(ENABLE_AVX1 "/arch:AVX1")
198  SET(ENABLE_AVX2 "/arch:AVX2")
[4209]199ELSE() # using Clang, GCC, Intel C++, etc 
[4152]200  SET(ENABLE_SSE1 "-msse")
201  SET(ENABLE_SSE2 "-msse2")
202  SET(ENABLE_SSE3 "-msse3")
203  SET(ENABLE_SSE4_1 "-msse4.1")
204  SET(ENABLE_SSE4_2 "-msse4.2")
[4209]205  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
[4480]206    SET(ENABLE_AVX1 "-mavx -fabi-version=6")
207    SET(ENABLE_AVX2 "-mavx2 -fabi-version=6") 
[4209]208  ELSE()
[4480]209    SET(ENABLE_AVX1 "-mavx")
210    SET(ENABLE_AVX2 "-mavx2")
[4209]211  ENDIF()
[4152]212ENDIF()
213
[4480]214SET(CMAKE_REQUIRED_FLAGS)
[4152]215
[4480]216MACRO(CHECK_SIMD_SUPPORT SIMD_TYPE RESULT)
217  IF(NOT RESULT) 
218    SET(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
219    SET(CMAKE_REQUIRED_FLAGS ${ENABLE_${SIMD_TYPE}})
220    SET(SUCCESS "${SIMD_TYPE}")
221    check_cxx_source_runs("${${SIMD_TYPE}_CODE}" ${SUCCESS})   
222    IF(${SUCCESS})
223      SET(${RESULT} "${SIMD_TYPE}")
[4152]224    ENDIF()
225    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
226  ENDIF()
227ENDMACRO()
228
[4480]229IF(NOT SIMD_SUPPORT)
230SET(RESULT)
231CHECK_SIMD_SUPPORT("AVX2" RESULT)
232CHECK_SIMD_SUPPORT("AVX1" RESULT)
233CHECK_SIMD_SUPPORT("SSE4_2" RESULT)
234CHECK_SIMD_SUPPORT("SSE4_1" RESULT)
235CHECK_SIMD_SUPPORT("SSE3" RESULT)
236CHECK_SIMD_SUPPORT("SSE2" RESULT)
237CHECK_SIMD_SUPPORT("SSE1" RESULT)
238SET(SIMD_SUPPORT ${RESULT} CACHE STRING "SSE2")
239ENDIF()
[4152]240
[4480]241SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ENABLE_${SIMD_SUPPORT}}")
[4152]242
[4118]243# detect LLVM version and add compiler flags.
[4508]244IF (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
[4152]245  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
[4480]246ENDIF()
[4118]247
[4209]248IF (BLOCK_SIZE_256)
249    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -m64")
250ENDIF()
[4151]251
[4200]252SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
[4522]253IF (${CMAKE_SYSTEM} MATCHES "Linux")
254    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -fsanitize=address")
255ENDIF()
[4152]256
[4096]257add_test(
258  NAME greptest
259  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
260  COMMAND python greptest.py ${CMAKE_BINARY_DIR}/icgrep)
261
[4137]262add_test(
[4456]263  NAME proptest
264  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
265  COMMAND python greptest.py -d ${PROJECT_SOURCE_DIR}/../QA -t ${PROJECT_SOURCE_DIR}/../QA/proptest.xml ${CMAKE_BINARY_DIR}/icgrep)
266
267add_test(
[4137]268  NAME abc_test
269  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
270  COMMAND ./run_abc ../icgrep-build/icgrep)
271
272add_custom_target (abc_test
273  COMMAND python abc_testgen.py
274  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
275
[4096]276add_custom_target (check
[4130]277  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
[4137]278  DEPENDS icgrep abc_test)
[4128]279
280add_custom_target (perf_icgrep
281  COMMAND python perf.py icgrep
282  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
283  DEPENDS icgrep)
284
285add_custom_target (viewer
286  COMMAND python viewer.py
287  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
288
[4275]289add_custom_target (text_viewer
290  COMMAND python viewer.py -t
291  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
Note: See TracBrowser for help on using the repository browser.