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

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

Work on bug fixes for multiplexing pass.

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