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

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

Bug fix for verifier and rewrite of the code sinking optimization pass.

File size: 11.4 KB
Line 
1cmake_minimum_required (VERSION 2.8)
2
3project (icgrep)
4
5enable_testing()
6# The version number.
7set (icgrep_VERSION_MAJOR 1)
8set (icgrep_VERSION_MINOR 0)
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()
16option(ENABLE_MULTIPLEXING "Compiling the Multiplexing Module")
17option(USE_BOOST_MMAP "Using mmap from Boost.Iostreams")
18option(DISABLE_PREGENERATED_UCD_FUNCTIONS "Disable compiling the pregenerated UCD functions")
19
20
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):
49llvm_map_components_to_libnames(REQ_LLVM_LIBRARIES mcjit native IRReader)
50
51message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
52
53# Check if boost has been installed on this system.
54set(Boost_USE_STATIC_LIBS ON)
55set(Boost_USE_MULTITHREADED OFF)
56set(Boost_USE_STATIC_RUNTIME ON)
57
58if(ENABLE_MULTIPLEXING)
59  SET(REQ_BOOST_COMPONENTS ${REQ_BOOST_COMPONENTS} system)
60endif()
61if(USE_BOOST_MMAP)
62  SET(REQ_BOOST_COMPONENTS ${REQ_BOOST_COMPONENTS} iostreams filesystem)
63endif()
64
65if(REQ_BOOST_COMPONENTS)
66  find_package(Boost COMPONENTS ${REQ_BOOST_COMPONENTS} REQUIRED)
67endif()
68
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)
71SET(PABLO_SRC ${PABLO_SRC} pablo/analysis/pabloverifier.cpp)
72SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/pablo_codesinking.cpp pablo/optimizers/booleanreassociationpass.cpp)
73IF (ENABLE_MULTIPLEXING)
74SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_automultiplexing.cpp pablo/optimizers/pablo_bddminimization.cpp)
75ENDIF()
76
77add_library(PabloADT ${PABLO_SRC})
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)
80add_library(CCADT cc/cc_namemap.cpp cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
81add_library(UCDlib UCD/unicode_set.cpp UCD/ucd_compiler.cpp UCD/PropertyObjects.cpp UCD/resolve_properties.cpp)
82
83
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
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()
97
98# add the executable
99add_executable(generate_predefined_ucd_functions generate_predefined_ucd_functions.cpp)
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})
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
106if(ENABLE_MULTIPLEXING)
107set(MULTIPLEXING_FLAG -multiplexing -reassoc -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv) # -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv #-ldc=ldc.csv
108endif()
109
110add_custom_command(OUTPUT ${PRECOMPILED_FILES}
111  COMMAND generate_predefined_ucd_functions
112  ARGS -o ${PRECOMPILED_PROPERTIES_OBJ} -dir ${PROJECT_SOURCE_DIR}/UCD/ ${MULTIPLEXING_FLAG} -DefaultIfHierarchy
113  DEPENDS generate_predefined_ucd_functions
114  COMMENT "Building predefined UCD functions..."
115  VERBATIM)
116
117add_custom_target(run_generate_predefined_ucd_functions DEPENDS ${PRECOMPILED_FILES})
118
119add_dependencies(RegExpCompiler run_generate_predefined_ucd_functions)
120ENDIF()
121
122add_executable(icgrep icgrep.cpp do_grep.cpp ${PRECOMPILED_FILES})
123IF(NOT DISABLE_PREGENERATED_UCD_FUNCTIONS)
124add_dependencies(icgrep run_generate_predefined_ucd_functions)
125ENDIF()
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")
130    target_link_libraries(icgrep ${Boost_LIBRARIES})
131ENDIF()
132
133target_link_libraries (icgrep UCDlib PabloADT RegExpCompiler CCADT ${REQ_LLVM_LIBRARIES})
134
135IF(USE_BOOST_MMAP)
136  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST_MMAP")
137ENDIF()
138
139
140IF (ENABLE_MULTIPLEXING)
141message(STATUS "Enabling Multiplexing")
142SET(CUDD_ROOT "${CMAKE_SOURCE_DIR}/../cudd-2.5.1")
143file(GLOB CUDD_SOURCES "${CUDD_ROOT}/cudd/*.c")
144file(GLOB EPD_SOURCES "${CUDD_ROOT}/epd/*.c")
145file(GLOB MTR_SOURCES "${CUDD_ROOT}/mtr/*.c")
146file(GLOB ST_SOURCES "${CUDD_ROOT}/st/*.c")
147file(GLOB UTIL_SOURCES "${CUDD_ROOT}/util/*.c")
148add_library(CUDD ${UTIL_SOURCES} ${MTR_SOURCES} ${CUDD_SOURCES} ${ST_SOURCES} ${EPD_SOURCES})
149include_directories(${CUDD_ROOT}/cudd)
150include_directories(${CUDD_ROOT}/epd)
151include_directories(${CUDD_ROOT}/mtr)
152include_directories(${CUDD_ROOT}/st)
153include_directories(${CUDD_ROOT}/util)
154target_link_libraries (PabloADT CUDD)
155SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_MULTIPLEXING")
156ENDIF()
157
158include_directories("${PROJECT_SOURCE_DIR}")
159
160#Check compiler support for 0x / 11
161include(CheckCXXCompilerFlag)
162CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
163if(COMPILER_SUPPORTS_CXX11)
164  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
165else()
166  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
167  if(COMPILER_SUPPORTS_CXX0X)
168    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
169  else()
170    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
171    if(COMPILER_SUPPORTS_GNU11)
172      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
173    else() 
174      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
175      if(COMPILER_SUPPORTS_GNU0X)
176        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
177      endif()
178    endif()
179  endif()
180endif()
181
182#Disable RunTime Type Information
183IF (MSVC) # using Visual Studio C++
184  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
185ELSE() # using Clang, GCC, Intel C++, etc
186  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
187ENDIF()
188
189#Enable all warnings
190SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
191
192#Check compiler and system architecture support for SSE or AVX
193include(CheckCXXSourceRuns)
194
195set(SSE1_CODE "
196#include <xmmintrin.h>
197int main()
198{
199__m128 a;
200float vals[4] = {0,0,0,0};
201a = _mm_loadu_ps(vals);
202return 0;
203}")
204
205set(SSE2_CODE "
206#include <emmintrin.h>
207int main()
208{
209__m128d a;
210double vals[2] = {0,0};
211a = _mm_loadu_pd(vals);
212return 0;
213}")
214
215set(SSE3_CODE "
216#include <pmmintrin.h>
217int main( )
218{
219const int vals[4] = {0,0,0,0};
220__m128i a;
221a = _mm_lddqu_si128( (const __m128i*)vals );
222return 0;
223}")
224
225set(SSE4_1_CODE "
226#include <smmintrin.h>
227int main ()
228{
229__m128i a, b;
230__m128i res = _mm_max_epi8(a, b);
231return 0;
232}")
233
234set(SSE4_2_CODE "
235#include <nmmintrin.h>
236int main()
237{
238__m128i a, b, c;
239c = _mm_cmpgt_epi64(a, b);
240return 0;
241}")
242
243set(AVX1_CODE "
244#include <immintrin.h>
245int main()
246{
247__m256* a=(__m256*)_mm_malloc(4, 32);
248__m256 b = _mm256_load_ps((float*)a);
249b = _mm256_or_ps(b, b);
250_mm_free(a);
251return 0;
252}")
253
254set(AVX2_CODE "
255#include <immintrin.h>
256int main()
257{
258__m256i* a = (__m256i*)_mm_malloc(4, 32);
259__m256i b = _mm256_load_si256(a);
260b = _mm256_or_si256(b, b);
261_mm_free(a);
262return 0;
263}")
264
265IF (MSVC) # using Visual Studio C++
266  SET(ENABLE_SSE1 "/arch:SSE")
267  SET(ENABLE_SSE2 "/arch:SSE2")
268  SET(ENABLE_SSE3 "/arch:SSE3")
269  SET(ENABLE_SSE4_1 "/arch:SSE4")
270  SET(ENABLE_SSE4_2 "/arch:SSE4")
271  SET(ENABLE_AVX1 "/arch:AVX1")
272  SET(ENABLE_AVX2 "/arch:AVX2")
273ELSE() # using Clang, GCC, Intel C++, etc 
274  SET(ENABLE_SSE1 "-msse")
275  SET(ENABLE_SSE2 "-msse2")
276  SET(ENABLE_SSE3 "-msse3")
277  SET(ENABLE_SSE4_1 "-msse4.1")
278  SET(ENABLE_SSE4_2 "-msse4.2")
279  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
280    SET(ENABLE_AVX1 "-mavx -fabi-version=6")
281    SET(ENABLE_AVX2 "-mavx2 -fabi-version=6") 
282  ELSE()
283    SET(ENABLE_AVX1 "-mavx")
284    SET(ENABLE_AVX2 "-mavx2")
285  ENDIF()
286ENDIF()
287
288SET(CMAKE_REQUIRED_FLAGS)
289
290MACRO(CHECK_SIMD_SUPPORT SIMD_TYPE RESULT)
291  IF(NOT RESULT) 
292    SET(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
293    SET(CMAKE_REQUIRED_FLAGS ${ENABLE_${SIMD_TYPE}})
294    SET(SUCCESS "${SIMD_TYPE}")
295    check_cxx_source_runs("${${SIMD_TYPE}_CODE}" ${SUCCESS})   
296    IF(${SUCCESS})
297      SET(${RESULT} "${SIMD_TYPE}")
298    ENDIF()
299    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
300  ENDIF()
301ENDMACRO()
302
303IF(NOT SIMD_SUPPORT)
304SET(RESULT)
305CHECK_SIMD_SUPPORT("AVX2" RESULT)
306CHECK_SIMD_SUPPORT("AVX1" RESULT)
307CHECK_SIMD_SUPPORT("SSE4_2" RESULT)
308CHECK_SIMD_SUPPORT("SSE4_1" RESULT)
309CHECK_SIMD_SUPPORT("SSE3" RESULT)
310CHECK_SIMD_SUPPORT("SSE2" RESULT)
311CHECK_SIMD_SUPPORT("SSE1" RESULT)
312SET(SIMD_SUPPORT ${RESULT} CACHE STRING "SSE2")
313ENDIF()
314#message("SIMD_SUPPORT=" ${SIMD_SUPPORT})
315SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ENABLE_${SIMD_SUPPORT}}")
316
317# detect LLVM version and add compiler flags.
318IF (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
319  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
320ENDIF()
321
322IF (BLOCK_SIZE_256)
323    IF ("${SIMD_SUPPORT}" STREQUAL "AVX1")
324        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX -DUSE_AVX -DBLOCK_SIZE=256 -mavx -m64")
325    ELSEIF ("${SIMD_SUPPORT}" STREQUAL "AVX2")
326        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -m64")
327    ENDIF()
328ENDIF()
329
330SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
331IF (${CMAKE_SYSTEM} MATCHES "Linux")
332    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g") # -fsanitize=address
333ENDIF()
334
335add_test(
336  NAME greptest
337  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
338  COMMAND python2 greptest.py ${CMAKE_BINARY_DIR}/icgrep)
339
340add_test(
341  NAME proptest
342  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
343  COMMAND python2 greptest.py -d ${PROJECT_SOURCE_DIR}/../QA -t ${PROJECT_SOURCE_DIR}/../QA/proptest.xml ${CMAKE_BINARY_DIR}/icgrep)
344
345add_test(
346  NAME abc_test
347  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
348  COMMAND ./run_abc ../icgrep-build/icgrep)
349
350add_custom_target (abc_test
351  COMMAND python2 abc_testgen.py
352  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
353
354add_custom_target (check
355  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
356  DEPENDS icgrep abc_test)
357
358add_custom_target (perf_icgrep
359  COMMAND python2 perf.py icgrep
360  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
361  DEPENDS icgrep)
362
363add_custom_target (viewer
364  COMMAND python2 viewer.py
365  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
366
367add_custom_target (text_viewer
368  COMMAND python2 viewer.py -t
369  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
Note: See TracBrowser for help on using the repository browser.