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

Last change on this file since 4876 was 4876, checked in by nmedfort, 4 years ago

More work towards n-ary And/Or/Xor? functions.

File size: 11.1 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()
[4583]16option(ENABLE_MULTIPLEXING "Compiling the Multiplexing Module")
[4778]17option(USE_BOOST_MMAP "Using mmap from Boost.Iostreams")
[4686]18option(DISABLE_PREGENERATED_UCD_FUNCTIONS "Disable compiling the pregenerated UCD functions")
[4151]19
[4583]20
[3850]21# configure a header file to pass some of the CMake settings
22# to the source code
23#configure_file (
24#  "${PROJECT_SOURCE_DIR}/icgrepconfig.h.in"
25#  "${PROJECT_BINARY_DIR}/icgrepconfig.h"
26#  )
27
28# LLVM set up
29#
30# A convenience variable:
31set(LLVM_ROOT "../libllvm" CACHE PATH "Root of LLVM install.")
32
33# A bit of a sanity check:
34if( NOT EXISTS ${LLVM_ROOT}/include/llvm )
35message(FATAL_ERROR "LLVM_ROOT (${LLVM_ROOT}) is not a valid LLVM install")
36endif()
37
38# We incorporate the CMake features provided by LLVM:
39set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT}/share/llvm/cmake")
40include(LLVMConfig)
41
42# Now set the header and library paths:
43include_directories( ${LLVM_INCLUDE_DIRS} )
44link_directories( ${LLVM_LIBRARY_DIRS} )
45add_definitions( ${LLVM_DEFINITIONS} )
46
47# Let's suppose we want to build a JIT compiler with support for
48# binary code (no interpreter):
[4734]49llvm_map_components_to_libnames(REQ_LLVM_LIBRARIES mcjit native IRReader)
[3850]50
[4118]51message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
[4096]52
[4196]53# Check if boost has been installed on this system.
[4210]54set(Boost_USE_STATIC_LIBS ON)
55set(Boost_USE_MULTITHREADED OFF)
[4583]56set(Boost_USE_STATIC_RUNTIME ON)
57
58if(ENABLE_MULTIPLEXING)
[4778]59  SET(REQ_BOOST_COMPONENTS ${REQ_BOOST_COMPONENTS} system)
[4583]60endif()
[4778]61if(USE_BOOST_MMAP)
[4801]62  SET(REQ_BOOST_COMPONENTS ${REQ_BOOST_COMPONENTS} system iostreams filesystem)
[4778]63endif()
[4212]64
[4778]65if(REQ_BOOST_COMPONENTS)
66  find_package(Boost COMPONENTS ${REQ_BOOST_COMPONENTS} REQUIRED)
67endif()
68
[4741]69SET(PABLO_SRC pablo/pabloAST.cpp pablo/ps_if.cpp pablo/ps_while.cpp pablo/function.cpp pablo/codegenstate.cpp pablo/builder.cpp pablo/symbol_generator.cpp pablo/printer_pablos.cpp)
70SET(PABLO_SRC ${PABLO_SRC} pablo/pablo_compiler.cpp pablo/carry_manager.cpp pablo/carry_data.cpp IDISA/idisa_builder.cpp)
[4766]71SET(PABLO_SRC ${PABLO_SRC} pablo/analysis/pabloverifier.cpp)
[4876]72SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/codemotionpass.cpp pablo/passes/flattenassociativedfg.cpp)
73SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/booleanreassociationpass.cpp)
[4583]74IF (ENABLE_MULTIPLEXING)
[4741]75SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_automultiplexing.cpp pablo/optimizers/pablo_bddminimization.cpp)
[4583]76ENDIF()
77
78add_library(PabloADT ${PABLO_SRC})
[4684]79add_library(RegExpADT re/re_re.cpp re/re_cc.cpp re/re_rep.cpp re/re_diff.cpp re/re_intersect.cpp re/printer_re.cpp)
80add_library(RegExpCompiler re/re_parser.cpp re/parsefailure.cpp re/re_nullable.cpp re/re_simplifier.cpp re/re_compiler.cpp re/re_analysis.cpp)
[4820]81add_library(CCADT cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
[4684]82add_library(UCDlib UCD/unicode_set.cpp UCD/ucd_compiler.cpp UCD/PropertyObjects.cpp UCD/resolve_properties.cpp)
[4198]83
[4583]84
[4684]85# add the executable
86target_link_libraries (PabloADT ${REQ_LLVM_LIBRARIES})
87target_link_libraries (CCADT PabloADT)
88target_link_libraries (UCDlib RegExpADT PabloADT CCADT)
89target_link_libraries (RegExpADT PabloADT CCADT UCDlib)
90target_link_libraries (RegExpCompiler RegExpADT)
91
[4686]92set(PRECOMPILED_FILES "")
93
94IF(DISABLE_PREGENERATED_UCD_FUNCTIONS)
95set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDISABLE_PREGENERATED_UCD_FUNCTIONS")
96MESSAGE("Disabling predefined UCD functions...")
97ELSE()
[4692]98
[4684]99# add the executable
100add_executable(generate_predefined_ucd_functions generate_predefined_ucd_functions.cpp)
[4784]101llvm_map_components_to_libnames(REQ_LLVM_TARGETS ${LLVM_TARGETS_TO_BUILD})
102target_link_libraries (generate_predefined_ucd_functions RegExpADT UCDlib PabloADT CCADT ${REQ_LLVM_TARGETS})
[4684]103
104set(PRECOMPILED_PROPERTIES_OBJ ${PROJECT_BINARY_DIR}/precompiled_properties.o)
105set(PRECOMPILED_FILES ${PRECOMPILED_PROPERTIES_OBJ} ${PROJECT_SOURCE_DIR}/UCD/precompiled_properties.cpp)
106
[4777]107if(ENABLE_MULTIPLEXING)
[4799]108set(MULTIPLEXING_FLAG -multiplexing -reassoc -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv) # -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv #-ldc=ldc.csv
[4777]109endif()
[4684]110
111add_custom_command(OUTPUT ${PRECOMPILED_FILES}
112  COMMAND generate_predefined_ucd_functions
[4788]113  ARGS -o ${PRECOMPILED_PROPERTIES_OBJ} -dir ${PROJECT_SOURCE_DIR}/UCD/ ${MULTIPLEXING_FLAG} -DefaultIfHierarchy
[4684]114  DEPENDS generate_predefined_ucd_functions
115  COMMENT "Building predefined UCD functions..."
116  VERBATIM)
117
[4692]118add_custom_target(run_generate_predefined_ucd_functions DEPENDS ${PRECOMPILED_FILES})
[4684]119
[4686]120add_dependencies(RegExpCompiler run_generate_predefined_ucd_functions)
121ENDIF()
122
[4801]123add_executable(icgrep icgrep.cpp toolchain.cpp do_grep.cpp ${PRECOMPILED_FILES})
[4686]124IF(NOT DISABLE_PREGENERATED_UCD_FUNCTIONS)
125add_dependencies(icgrep run_generate_predefined_ucd_functions)
126ENDIF()
[4583]127IF(Boost_FOUND)
128    include_directories("${Boost_INCLUDE_DIRS}")
129    link_directories(${Boost_LIBRARY_DIR})
130    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST")
[4778]131    target_link_libraries(icgrep ${Boost_LIBRARIES})
[4583]132ENDIF()
133
[4734]134target_link_libraries (icgrep UCDlib PabloADT RegExpCompiler CCADT ${REQ_LLVM_LIBRARIES})
135
[4778]136IF(USE_BOOST_MMAP)
137  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST_MMAP")
138ENDIF()
[4734]139
140
[4583]141IF (ENABLE_MULTIPLEXING)
142message(STATUS "Enabling Multiplexing")
[4868]143SET(BUDDY_ROOT "${CMAKE_SOURCE_DIR}/../buddy-2.4")
144file(GLOB BUDDY_SOURCES "${BUDDY_ROOT}/src/*.cpp")
145add_library(BUDDY ${BUDDY_SOURCES})
146include_directories(${BUDDY_ROOT}/src)
147target_link_libraries (PabloADT BUDDY)
[4583]148SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_MULTIPLEXING")
149ENDIF()
150
[4096]151include_directories("${PROJECT_SOURCE_DIR}")
152
[4152]153#Check compiler support for 0x / 11
154include(CheckCXXCompilerFlag)
155CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
156if(COMPILER_SUPPORTS_CXX11)
157  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
158else()
159  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
160  if(COMPILER_SUPPORTS_CXX0X)
161    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
162  else()
163    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
164    if(COMPILER_SUPPORTS_GNU11)
165      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
166    else() 
167      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
168      if(COMPILER_SUPPORTS_GNU0X)
169        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
170      endif()
171    endif()
172  endif()
173endif()
[4096]174
[4200]175#Disable RunTime Type Information
176IF (MSVC) # using Visual Studio C++
[4436]177  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
[4200]178ELSE() # using Clang, GCC, Intel C++, etc
[4436]179  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
[4200]180ENDIF()
181
[4227]182#Enable all warnings
[4356]183SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
[4200]184
185#Check compiler and system architecture support for SSE or AVX
[4152]186include(CheckCXXSourceRuns)
187
188set(SSE1_CODE "
189#include <xmmintrin.h>
190int main()
191{
192__m128 a;
193float vals[4] = {0,0,0,0};
194a = _mm_loadu_ps(vals);
195return 0;
196}")
197
198set(SSE2_CODE "
199#include <emmintrin.h>
200int main()
201{
202__m128d a;
203double vals[2] = {0,0};
204a = _mm_loadu_pd(vals);
205return 0;
206}")
207
208set(SSE3_CODE "
209#include <pmmintrin.h>
210int main( )
211{
212const int vals[4] = {0,0,0,0};
213__m128i a;
214a = _mm_lddqu_si128( (const __m128i*)vals );
215return 0;
216}")
217
218set(SSE4_1_CODE "
219#include <smmintrin.h>
220int main ()
221{
222__m128i a, b;
223__m128i res = _mm_max_epi8(a, b);
224return 0;
225}")
226
227set(SSE4_2_CODE "
228#include <nmmintrin.h>
229int main()
230{
231__m128i a, b, c;
232c = _mm_cmpgt_epi64(a, b);
233return 0;
234}")
235
[4480]236set(AVX1_CODE "
[4152]237#include <immintrin.h>
238int main()
239{
240__m256* a=(__m256*)_mm_malloc(4, 32);
241__m256 b = _mm256_load_ps((float*)a);
242b = _mm256_or_ps(b, b);
243_mm_free(a);
244return 0;
245}")
246
[4480]247set(AVX2_CODE "
[4152]248#include <immintrin.h>
249int main()
250{
251__m256i* a = (__m256i*)_mm_malloc(4, 32);
252__m256i b = _mm256_load_si256(a);
253b = _mm256_or_si256(b, b);
254_mm_free(a);
255return 0;
256}")
257
258IF (MSVC) # using Visual Studio C++
259  SET(ENABLE_SSE1 "/arch:SSE")
260  SET(ENABLE_SSE2 "/arch:SSE2")
261  SET(ENABLE_SSE3 "/arch:SSE3")
262  SET(ENABLE_SSE4_1 "/arch:SSE4")
263  SET(ENABLE_SSE4_2 "/arch:SSE4")
[4480]264  SET(ENABLE_AVX1 "/arch:AVX1")
265  SET(ENABLE_AVX2 "/arch:AVX2")
[4209]266ELSE() # using Clang, GCC, Intel C++, etc 
[4152]267  SET(ENABLE_SSE1 "-msse")
268  SET(ENABLE_SSE2 "-msse2")
269  SET(ENABLE_SSE3 "-msse3")
270  SET(ENABLE_SSE4_1 "-msse4.1")
271  SET(ENABLE_SSE4_2 "-msse4.2")
[4209]272  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
[4480]273    SET(ENABLE_AVX1 "-mavx -fabi-version=6")
274    SET(ENABLE_AVX2 "-mavx2 -fabi-version=6") 
[4209]275  ELSE()
[4480]276    SET(ENABLE_AVX1 "-mavx")
277    SET(ENABLE_AVX2 "-mavx2")
[4209]278  ENDIF()
[4152]279ENDIF()
280
[4480]281SET(CMAKE_REQUIRED_FLAGS)
[4152]282
[4480]283MACRO(CHECK_SIMD_SUPPORT SIMD_TYPE RESULT)
284  IF(NOT RESULT) 
285    SET(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
286    SET(CMAKE_REQUIRED_FLAGS ${ENABLE_${SIMD_TYPE}})
287    SET(SUCCESS "${SIMD_TYPE}")
288    check_cxx_source_runs("${${SIMD_TYPE}_CODE}" ${SUCCESS})   
289    IF(${SUCCESS})
290      SET(${RESULT} "${SIMD_TYPE}")
[4152]291    ENDIF()
292    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
293  ENDIF()
294ENDMACRO()
295
[4480]296IF(NOT SIMD_SUPPORT)
297SET(RESULT)
298CHECK_SIMD_SUPPORT("AVX2" RESULT)
299CHECK_SIMD_SUPPORT("AVX1" RESULT)
300CHECK_SIMD_SUPPORT("SSE4_2" RESULT)
301CHECK_SIMD_SUPPORT("SSE4_1" RESULT)
302CHECK_SIMD_SUPPORT("SSE3" RESULT)
303CHECK_SIMD_SUPPORT("SSE2" RESULT)
304CHECK_SIMD_SUPPORT("SSE1" RESULT)
305SET(SIMD_SUPPORT ${RESULT} CACHE STRING "SSE2")
306ENDIF()
[4750]307#message("SIMD_SUPPORT=" ${SIMD_SUPPORT})
[4480]308SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ENABLE_${SIMD_SUPPORT}}")
[4152]309
[4118]310# detect LLVM version and add compiler flags.
[4508]311IF (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
[4152]312  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
[4480]313ENDIF()
[4118]314
[4209]315IF (BLOCK_SIZE_256)
[4750]316    IF ("${SIMD_SUPPORT}" STREQUAL "AVX1")
317        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX -DUSE_AVX -DBLOCK_SIZE=256 -mavx -m64")
318    ELSEIF ("${SIMD_SUPPORT}" STREQUAL "AVX2")
319        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -m64")
320    ENDIF()
[4209]321ENDIF()
[4151]322
[4200]323SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
[4522]324IF (${CMAKE_SYSTEM} MATCHES "Linux")
[4856]325    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -fsanitize=address") # -fsanitize=address
[4522]326ENDIF()
[4152]327
[4096]328add_test(
329  NAME greptest
330  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
[4785]331  COMMAND python2 greptest.py ${CMAKE_BINARY_DIR}/icgrep)
[4096]332
[4137]333add_test(
[4456]334  NAME proptest
335  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
[4785]336  COMMAND python2 greptest.py -d ${PROJECT_SOURCE_DIR}/../QA -t ${PROJECT_SOURCE_DIR}/../QA/proptest.xml ${CMAKE_BINARY_DIR}/icgrep)
[4456]337
338add_test(
[4137]339  NAME abc_test
340  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
341  COMMAND ./run_abc ../icgrep-build/icgrep)
342
343add_custom_target (abc_test
[4785]344  COMMAND python2 abc_testgen.py
[4137]345  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
346
[4096]347add_custom_target (check
[4130]348  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
[4137]349  DEPENDS icgrep abc_test)
[4128]350
351add_custom_target (perf_icgrep
[4785]352  COMMAND python2 perf.py icgrep
[4128]353  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
354  DEPENDS icgrep)
355
356add_custom_target (viewer
[4785]357  COMMAND python2 viewer.py
[4128]358  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
359
[4275]360add_custom_target (text_viewer
[4785]361  COMMAND python2 viewer.py -t
[4275]362  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
Note: See TracBrowser for help on using the repository browser.