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

Last change on this file since 4908 was 4908, checked in by cameron, 3 years ago

Turn off predefined UCD functions by default

File size: 11.2 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")
[4908]18option(ENABLE_PREGENERATED_UCD_FUNCTIONS "Enable 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)
[4878]57SET(REQ_BOOST_COMPONENTS ${REQ_BOOST_COMPONENTS} system)
[4778]58if(USE_BOOST_MMAP)
[4878]59  SET(REQ_BOOST_COMPONENTS ${REQ_BOOST_COMPONENTS} iostreams filesystem)
[4778]60endif()
[4878]61find_package(Boost COMPONENTS ${REQ_BOOST_COMPONENTS} REQUIRED)
[4212]62
[4741]63SET(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)
[4907]64SET(PABLO_SRC ${PABLO_SRC} pablo/pablo_compiler.cpp pablo/carry_manager.cpp pablo/carry_data.cpp IDISA/idisa_builder.cpp IDISA/idisa_avx_builder.cpp IDISA/idisa_sse_builder.cpp kernels/s2p_gen.cpp kernels/scanmatchgen.cpp)
[4766]65SET(PABLO_SRC ${PABLO_SRC} pablo/analysis/pabloverifier.cpp)
[4885]66SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/codemotionpass.cpp pablo/optimizers/distributivepass.cpp pablo/passes/flattenassociativedfg.cpp pablo/passes/factorizedfg.cpp)
[4896]67SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/schedulingprepass.cpp)
[4583]68IF (ENABLE_MULTIPLEXING)
[4741]69SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_automultiplexing.cpp pablo/optimizers/pablo_bddminimization.cpp)
[4583]70ENDIF()
71
72add_library(PabloADT ${PABLO_SRC})
[4684]73add_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)
74add_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]75add_library(CCADT cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
[4684]76add_library(UCDlib UCD/unicode_set.cpp UCD/ucd_compiler.cpp UCD/PropertyObjects.cpp UCD/resolve_properties.cpp)
[4198]77
[4583]78
[4684]79# add the executable
80target_link_libraries (PabloADT ${REQ_LLVM_LIBRARIES})
81target_link_libraries (CCADT PabloADT)
82target_link_libraries (UCDlib RegExpADT PabloADT CCADT)
83target_link_libraries (RegExpADT PabloADT CCADT UCDlib)
84target_link_libraries (RegExpCompiler RegExpADT)
85
[4686]86set(PRECOMPILED_FILES "")
87
[4908]88IF(NOT ENABLE_PREGENERATED_UCD_FUNCTIONS)
[4686]89set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDISABLE_PREGENERATED_UCD_FUNCTIONS")
90ELSE()
[4908]91MESSAGE("Enabling predefined UCD functions...")
[4684]92# add the executable
93add_executable(generate_predefined_ucd_functions generate_predefined_ucd_functions.cpp)
[4784]94llvm_map_components_to_libnames(REQ_LLVM_TARGETS ${LLVM_TARGETS_TO_BUILD})
95target_link_libraries (generate_predefined_ucd_functions RegExpADT UCDlib PabloADT CCADT ${REQ_LLVM_TARGETS})
[4684]96
97set(PRECOMPILED_PROPERTIES_OBJ ${PROJECT_BINARY_DIR}/precompiled_properties.o)
98set(PRECOMPILED_FILES ${PRECOMPILED_PROPERTIES_OBJ} ${PROJECT_SOURCE_DIR}/UCD/precompiled_properties.cpp)
99
[4777]100if(ENABLE_MULTIPLEXING)
[4799]101set(MULTIPLEXING_FLAG -multiplexing -reassoc -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv) # -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv #-ldc=ldc.csv
[4777]102endif()
[4684]103
104add_custom_command(OUTPUT ${PRECOMPILED_FILES}
105  COMMAND generate_predefined_ucd_functions
[4788]106  ARGS -o ${PRECOMPILED_PROPERTIES_OBJ} -dir ${PROJECT_SOURCE_DIR}/UCD/ ${MULTIPLEXING_FLAG} -DefaultIfHierarchy
[4684]107  DEPENDS generate_predefined_ucd_functions
108  COMMENT "Building predefined UCD functions..."
109  VERBATIM)
110
[4692]111add_custom_target(run_generate_predefined_ucd_functions DEPENDS ${PRECOMPILED_FILES})
[4684]112
[4686]113add_dependencies(RegExpCompiler run_generate_predefined_ucd_functions)
114ENDIF()
115
[4801]116add_executable(icgrep icgrep.cpp toolchain.cpp do_grep.cpp ${PRECOMPILED_FILES})
[4908]117IF(ENABLE_PREGENERATED_UCD_FUNCTIONS)
[4686]118add_dependencies(icgrep run_generate_predefined_ucd_functions)
119ENDIF()
[4583]120IF(Boost_FOUND)
121    include_directories("${Boost_INCLUDE_DIRS}")
122    link_directories(${Boost_LIBRARY_DIR})
123    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST")
[4778]124    target_link_libraries(icgrep ${Boost_LIBRARIES})
[4583]125ENDIF()
126
[4734]127target_link_libraries (icgrep UCDlib PabloADT RegExpCompiler CCADT ${REQ_LLVM_LIBRARIES})
128
[4778]129IF(USE_BOOST_MMAP)
130  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST_MMAP")
131ENDIF()
[4734]132
133
[4583]134IF (ENABLE_MULTIPLEXING)
135message(STATUS "Enabling Multiplexing")
[4868]136SET(BUDDY_ROOT "${CMAKE_SOURCE_DIR}/../buddy-2.4")
137file(GLOB BUDDY_SOURCES "${BUDDY_ROOT}/src/*.cpp")
138add_library(BUDDY ${BUDDY_SOURCES})
139include_directories(${BUDDY_ROOT}/src)
140target_link_libraries (PabloADT BUDDY)
[4583]141SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_MULTIPLEXING")
142ENDIF()
143
[4096]144include_directories("${PROJECT_SOURCE_DIR}")
145
[4152]146#Check compiler support for 0x / 11
147include(CheckCXXCompilerFlag)
148CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
149if(COMPILER_SUPPORTS_CXX11)
150  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
151else()
152  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
153  if(COMPILER_SUPPORTS_CXX0X)
154    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
155  else()
156    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
157    if(COMPILER_SUPPORTS_GNU11)
158      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
159    else() 
160      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
161      if(COMPILER_SUPPORTS_GNU0X)
162        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
163      endif()
164    endif()
165  endif()
166endif()
[4096]167
[4200]168#Disable RunTime Type Information
169IF (MSVC) # using Visual Studio C++
[4436]170  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
[4200]171ELSE() # using Clang, GCC, Intel C++, etc
[4436]172  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
[4200]173ENDIF()
174
[4227]175#Enable all warnings
[4356]176SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
[4200]177
178#Check compiler and system architecture support for SSE or AVX
[4152]179include(CheckCXXSourceRuns)
180
181set(SSE1_CODE "
182#include <xmmintrin.h>
183int main()
184{
185__m128 a;
186float vals[4] = {0,0,0,0};
187a = _mm_loadu_ps(vals);
188return 0;
189}")
190
191set(SSE2_CODE "
192#include <emmintrin.h>
193int main()
194{
195__m128d a;
196double vals[2] = {0,0};
197a = _mm_loadu_pd(vals);
198return 0;
199}")
200
201set(SSE3_CODE "
202#include <pmmintrin.h>
203int main( )
204{
205const int vals[4] = {0,0,0,0};
206__m128i a;
207a = _mm_lddqu_si128( (const __m128i*)vals );
208return 0;
209}")
210
211set(SSE4_1_CODE "
212#include <smmintrin.h>
213int main ()
214{
215__m128i a, b;
216__m128i res = _mm_max_epi8(a, b);
217return 0;
218}")
219
220set(SSE4_2_CODE "
221#include <nmmintrin.h>
222int main()
223{
224__m128i a, b, c;
225c = _mm_cmpgt_epi64(a, b);
226return 0;
227}")
228
[4480]229set(AVX1_CODE "
[4152]230#include <immintrin.h>
231int main()
232{
233__m256* a=(__m256*)_mm_malloc(4, 32);
234__m256 b = _mm256_load_ps((float*)a);
235b = _mm256_or_ps(b, b);
236_mm_free(a);
237return 0;
238}")
239
[4480]240set(AVX2_CODE "
[4152]241#include <immintrin.h>
242int main()
243{
244__m256i* a = (__m256i*)_mm_malloc(4, 32);
245__m256i b = _mm256_load_si256(a);
246b = _mm256_or_si256(b, b);
247_mm_free(a);
248return 0;
249}")
250
251IF (MSVC) # using Visual Studio C++
252  SET(ENABLE_SSE1 "/arch:SSE")
253  SET(ENABLE_SSE2 "/arch:SSE2")
254  SET(ENABLE_SSE3 "/arch:SSE3")
255  SET(ENABLE_SSE4_1 "/arch:SSE4")
256  SET(ENABLE_SSE4_2 "/arch:SSE4")
[4480]257  SET(ENABLE_AVX1 "/arch:AVX1")
258  SET(ENABLE_AVX2 "/arch:AVX2")
[4209]259ELSE() # using Clang, GCC, Intel C++, etc 
[4152]260  SET(ENABLE_SSE1 "-msse")
261  SET(ENABLE_SSE2 "-msse2")
262  SET(ENABLE_SSE3 "-msse3")
263  SET(ENABLE_SSE4_1 "-msse4.1")
264  SET(ENABLE_SSE4_2 "-msse4.2")
[4209]265  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
[4480]266    SET(ENABLE_AVX1 "-mavx -fabi-version=6")
267    SET(ENABLE_AVX2 "-mavx2 -fabi-version=6") 
[4209]268  ELSE()
[4480]269    SET(ENABLE_AVX1 "-mavx")
270    SET(ENABLE_AVX2 "-mavx2")
[4209]271  ENDIF()
[4152]272ENDIF()
273
[4480]274SET(CMAKE_REQUIRED_FLAGS)
[4152]275
[4480]276MACRO(CHECK_SIMD_SUPPORT SIMD_TYPE RESULT)
277  IF(NOT RESULT) 
278    SET(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
279    SET(CMAKE_REQUIRED_FLAGS ${ENABLE_${SIMD_TYPE}})
280    SET(SUCCESS "${SIMD_TYPE}")
281    check_cxx_source_runs("${${SIMD_TYPE}_CODE}" ${SUCCESS})   
282    IF(${SUCCESS})
283      SET(${RESULT} "${SIMD_TYPE}")
[4152]284    ENDIF()
285    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
286  ENDIF()
287ENDMACRO()
288
[4480]289IF(NOT SIMD_SUPPORT)
290SET(RESULT)
291CHECK_SIMD_SUPPORT("AVX2" RESULT)
292CHECK_SIMD_SUPPORT("AVX1" RESULT)
293CHECK_SIMD_SUPPORT("SSE4_2" RESULT)
294CHECK_SIMD_SUPPORT("SSE4_1" RESULT)
295CHECK_SIMD_SUPPORT("SSE3" RESULT)
296CHECK_SIMD_SUPPORT("SSE2" RESULT)
297CHECK_SIMD_SUPPORT("SSE1" RESULT)
298SET(SIMD_SUPPORT ${RESULT} CACHE STRING "SSE2")
299ENDIF()
[4750]300#message("SIMD_SUPPORT=" ${SIMD_SUPPORT})
[4480]301SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ENABLE_${SIMD_SUPPORT}}")
[4152]302
[4118]303# detect LLVM version and add compiler flags.
[4508]304IF (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
[4152]305  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
[4480]306ENDIF()
[4118]307
[4209]308IF (BLOCK_SIZE_256)
[4750]309    IF ("${SIMD_SUPPORT}" STREQUAL "AVX1")
310        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX -DUSE_AVX -DBLOCK_SIZE=256 -mavx -m64")
311    ELSEIF ("${SIMD_SUPPORT}" STREQUAL "AVX2")
312        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -m64")
313    ENDIF()
[4209]314ENDIF()
[4151]315
[4200]316SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
[4522]317IF (${CMAKE_SYSTEM} MATCHES "Linux")
[4880]318    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -fsanitize=address -fno-omit-frame-pointer")
[4522]319ENDIF()
[4152]320
[4096]321add_test(
322  NAME greptest
323  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
[4785]324  COMMAND python2 greptest.py ${CMAKE_BINARY_DIR}/icgrep)
[4096]325
[4137]326add_test(
[4456]327  NAME proptest
328  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
[4785]329  COMMAND python2 greptest.py -d ${PROJECT_SOURCE_DIR}/../QA -t ${PROJECT_SOURCE_DIR}/../QA/proptest.xml ${CMAKE_BINARY_DIR}/icgrep)
[4456]330
331add_test(
[4137]332  NAME abc_test
333  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
334  COMMAND ./run_abc ../icgrep-build/icgrep)
335
336add_custom_target (abc_test
[4785]337  COMMAND python2 abc_testgen.py
[4137]338  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
339
[4096]340add_custom_target (check
[4130]341  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
[4137]342  DEPENDS icgrep abc_test)
[4128]343
344add_custom_target (perf_icgrep
[4785]345  COMMAND python2 perf.py icgrep
[4128]346  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
347  DEPENDS icgrep)
348
349add_custom_target (viewer
[4785]350  COMMAND python2 viewer.py
[4128]351  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
352
[4275]353add_custom_target (text_viewer
[4785]354  COMMAND python2 viewer.py -t
[4275]355  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
Note: See TracBrowser for help on using the repository browser.