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

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

Refactor and encapsulate grep codegen/execution in GrepEngine?

File size: 12.1 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")
13elseif (NOT BLOCK_SIZE_64)
14  message("-- Build with BLOCK_SIZE=128")
15endif()
16
17option(BLOCK_SIZE_64 "Compiling with BLOCK_SIZE=64")
18if (BLOCK_SIZE_64)
19  message("-- Build with BLOCK_SIZE=64")
20endif()
21
22option(ENABLE_MULTIPLEXING "Compiling the Multiplexing Module")
23option(USE_BOOST_MMAP "Using mmap from Boost.Iostreams")
24option(ENABLE_PREGENERATED_UCD_FUNCTIONS "Enable compiling the pregenerated UCD functions")
25option(PRINT_TIMING_INFORMATION "Write compilation and execution timing information to standard error stream")
26
27# configure a header file to pass some of the CMake settings
28# to the source code
29#configure_file (
30#  "${PROJECT_SOURCE_DIR}/icgrepconfig.h.in"
31#  "${PROJECT_BINARY_DIR}/icgrepconfig.h"
32#  )
33
34# LLVM set up
35#
36# A convenience variable:
37set(LLVM_ROOT "../libllvm" CACHE PATH "Root of LLVM install.")
38
39# A bit of a sanity check:
40if( NOT EXISTS ${LLVM_ROOT}/include/llvm )
41message(FATAL_ERROR "LLVM_ROOT (${LLVM_ROOT}) is not a valid LLVM install")
42endif()
43
44# We incorporate the CMake features provided by LLVM:
45set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${LLVM_ROOT}/share/llvm/cmake;${CMAKE_CURRENT_SOURCE_DIR}/cmake")
46
47include(LLVMConfig)
48
49# Now set the header and library paths:
50include_directories( ${LLVM_INCLUDE_DIRS} )
51link_directories( ${LLVM_LIBRARY_DIRS} )
52add_definitions( ${LLVM_DEFINITIONS} )
53
54# Let's suppose we want to build a JIT compiler with support for
55# binary code (no interpreter):
56llvm_map_components_to_libnames(REQ_LLVM_LIBRARIES mcjit native IRReader) # ipo
57
58message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
59
60# Check if boost has been installed on this system.
61set(Boost_USE_STATIC_LIBS ON)
62set(Boost_USE_MULTITHREADED OFF)
63set(Boost_USE_STATIC_RUNTIME ON)
64SET(REQ_BOOST_COMPONENTS ${REQ_BOOST_COMPONENTS} system)
65if(USE_BOOST_MMAP)
66  SET(REQ_BOOST_COMPONENTS ${REQ_BOOST_COMPONENTS} iostreams filesystem)
67endif()
68find_package(Boost COMPONENTS ${REQ_BOOST_COMPONENTS} REQUIRED)
69
70SET(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)
71SET(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_i64_builder.cpp IDISA/idisa_sse_builder.cpp kernels/s2p_kernel.cpp kernels/scanmatchgen.cpp kernels/kernel.cpp kernels/pipeline.cpp)
72SET(PABLO_SRC ${PABLO_SRC} pablo/analysis/pabloverifier.cpp)
73SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/codemotionpass.cpp)
74IF(ENABLE_MULTIPLEXING)
75SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/distributivepass.cpp pablo/passes/flattenassociativedfg.cpp pablo/passes/factorizedfg.cpp)
76SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/schedulingprepass.cpp pablo/optimizers/pablo_automultiplexing.cpp pablo/optimizers/pablo_bddminimization.cpp)
77ENDIF()
78
79add_library(PabloADT ${PABLO_SRC})
80add_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)
81add_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)
82add_library(CCADT cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
83add_library(UCDlib UCD/unicode_set.cpp UCD/ucd_compiler.cpp UCD/PropertyObjects.cpp UCD/resolve_properties.cpp)
84
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
92set(PRECOMPILED_FILES "")
93
94IF(NOT ENABLE_PREGENERATED_UCD_FUNCTIONS)
95set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDISABLE_PREGENERATED_UCD_FUNCTIONS")
96ELSE()
97MESSAGE("Enabling predefined UCD functions...")
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 toolchain.cpp grep_engine.cpp ${PRECOMPILED_FILES})
123IF(ENABLE_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()
132IF (PRINT_TIMING_INFORMATION)
133    find_package(PAPI REQUIRED)
134    include_directories(${PAPI_INCLUDE_DIRS})
135    target_link_libraries(icgrep ${PAPI_LIBRARIES})
136ENDIF()
137
138
139target_link_libraries (icgrep UCDlib PabloADT RegExpCompiler CCADT ${REQ_LLVM_LIBRARIES})
140
141IF(USE_BOOST_MMAP)
142  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST_MMAP")
143ENDIF()
144
145
146IF(ENABLE_MULTIPLEXING)
147message(STATUS "Enabling Multiplexing")
148SET(BUDDY_ROOT "${CMAKE_SOURCE_DIR}/../buddy-2.4/src")
149SET(BUDDY_SOURCES ${BUDDY_ROOT}/bddop.cpp ${BUDDY_ROOT}/cache.cpp ${BUDDY_ROOT}/imatrix.cpp ${BUDDY_ROOT}/kernel.cpp)
150SET(BUDDY_SOURCES ${BUDDY_SOURCES} ${BUDDY_ROOT}/prime.cpp ${BUDDY_ROOT}/pairs.cpp ${BUDDY_ROOT}/reorder.cpp ${BUDDY_ROOT}/tree.cpp)
151add_library(BUDDY ${BUDDY_SOURCES})
152include_directories(${BUDDY_ROOT})
153target_link_libraries (PabloADT BUDDY)
154SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_MULTIPLEXING")
155ENDIF()
156
157include_directories("${PROJECT_SOURCE_DIR}")
158
159#Check compiler support for 0x / 11
160include(CheckCXXCompilerFlag)
161CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
162if(COMPILER_SUPPORTS_CXX11)
163  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
164else()
165  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
166  if(COMPILER_SUPPORTS_CXX0X)
167    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
168  else()
169    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
170    if(COMPILER_SUPPORTS_GNU11)
171      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
172    else() 
173      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
174      if(COMPILER_SUPPORTS_GNU0X)
175        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
176      endif()
177    endif()
178  endif()
179endif()
180
181#Disable RunTime Type Information
182IF (MSVC) # using Visual Studio C++
183  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
184ELSE() # using Clang, GCC, Intel C++, etc
185  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
186ENDIF()
187
188#Enable all warnings
189SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
190
191#Check compiler and system architecture support for SSE or AVX
192include(CheckCXXSourceRuns)
193
194set(SSE1_CODE "
195#include <xmmintrin.h>
196int main()
197{
198__m128 a;
199float vals[4] = {0,0,0,0};
200a = _mm_loadu_ps(vals);
201return 0;
202}")
203
204set(SSE2_CODE "
205#include <emmintrin.h>
206int main()
207{
208__m128d a;
209double vals[2] = {0,0};
210a = _mm_loadu_pd(vals);
211return 0;
212}")
213
214set(SSE3_CODE "
215#include <pmmintrin.h>
216int main( )
217{
218const int vals[4] = {0,0,0,0};
219__m128i a;
220a = _mm_lddqu_si128( (const __m128i*)vals );
221return 0;
222}")
223
224set(SSE4_1_CODE "
225#include <smmintrin.h>
226int main ()
227{
228__m128i a, b;
229__m128i res = _mm_max_epi8(a, b);
230return 0;
231}")
232
233set(SSE4_2_CODE "
234#include <nmmintrin.h>
235int main()
236{
237__m128i a, b, c;
238c = _mm_cmpgt_epi64(a, b);
239return 0;
240}")
241
242set(AVX1_CODE "
243#include <immintrin.h>
244int main()
245{
246__m256* a=(__m256*)_mm_malloc(4, 32);
247__m256 b = _mm256_load_ps((float*)a);
248b = _mm256_or_ps(b, b);
249_mm_free(a);
250return 0;
251}")
252
253set(AVX2_CODE "
254#include <immintrin.h>
255int main()
256{
257__m256i* a = (__m256i*)_mm_malloc(4, 32);
258__m256i b = _mm256_load_si256(a);
259b = _mm256_or_si256(b, b);
260_mm_free(a);
261return 0;
262}")
263
264IF (MSVC) # using Visual Studio C++
265  SET(ENABLE_SSE1 "/arch:SSE")
266  SET(ENABLE_SSE2 "/arch:SSE2")
267  SET(ENABLE_SSE3 "/arch:SSE3")
268  SET(ENABLE_SSE4_1 "/arch:SSE4")
269  SET(ENABLE_SSE4_2 "/arch:SSE4")
270  SET(ENABLE_AVX1 "/arch:AVX1")
271  SET(ENABLE_AVX2 "/arch:AVX2")
272ELSE() # using Clang, GCC, Intel C++, etc 
273  SET(ENABLE_SSE1 "-msse")
274  SET(ENABLE_SSE2 "-msse2")
275  SET(ENABLE_SSE3 "-msse3")
276  SET(ENABLE_SSE4_1 "-msse4.1")
277  SET(ENABLE_SSE4_2 "-msse4.2")
278  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
279    SET(ENABLE_AVX1 "-mavx -fabi-version=6")
280    SET(ENABLE_AVX2 "-mavx2 -fabi-version=6") 
281  ELSE()
282    SET(ENABLE_AVX1 "-mavx")
283    SET(ENABLE_AVX2 "-mavx2")
284  ENDIF()
285ENDIF()
286
287SET(CMAKE_REQUIRED_FLAGS)
288
289MACRO(CHECK_SIMD_SUPPORT SIMD_TYPE RESULT)
290  IF(NOT RESULT) 
291    SET(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
292    SET(CMAKE_REQUIRED_FLAGS ${ENABLE_${SIMD_TYPE}})
293    SET(SUCCESS "${SIMD_TYPE}")
294    check_cxx_source_runs("${${SIMD_TYPE}_CODE}" ${SUCCESS})   
295    IF(${SUCCESS})
296      SET(${RESULT} "${SIMD_TYPE}")
297    ENDIF()
298    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
299  ENDIF()
300ENDMACRO()
301
302IF(NOT SIMD_SUPPORT)
303SET(RESULT)
304CHECK_SIMD_SUPPORT("AVX2" RESULT)
305CHECK_SIMD_SUPPORT("AVX1" RESULT)
306CHECK_SIMD_SUPPORT("SSE4_2" RESULT)
307CHECK_SIMD_SUPPORT("SSE4_1" RESULT)
308CHECK_SIMD_SUPPORT("SSE3" RESULT)
309CHECK_SIMD_SUPPORT("SSE2" RESULT)
310CHECK_SIMD_SUPPORT("SSE1" RESULT)
311SET(SIMD_SUPPORT ${RESULT} CACHE STRING "SSE2")
312ENDIF()
313#message("SIMD_SUPPORT=" ${SIMD_SUPPORT})
314SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ENABLE_${SIMD_SUPPORT}}")
315
316# detect LLVM version and add compiler flags.
317IF (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
318  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
319ENDIF()
320
321IF (BLOCK_SIZE_256)
322    IF ("${SIMD_SUPPORT}" STREQUAL "AVX1")
323        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX -DUSE_AVX -DBLOCK_SIZE=256 -mavx -m64")
324    ELSEIF ("${SIMD_SUPPORT}" STREQUAL "AVX2")
325        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -m64")
326    ENDIF()
327ELSEIF(BLOCK_SIZE_64)
328    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBLOCK_SIZE=64")
329ELSE ()
330    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBLOCK_SIZE=128")
331ENDIF()
332
333
334IF (PRINT_TIMING_INFORMATION)   
335    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPRINT_TIMING_INFORMATION")
336ENDIF()
337
338SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
339IF (${CMAKE_SYSTEM} MATCHES "Linux")
340    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -fsanitize=address -fno-omit-frame-pointer")
341ENDIF()
342
343add_test(
344  NAME greptest
345  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
346  COMMAND python2 greptest.py ${CMAKE_BINARY_DIR}/icgrep)
347
348add_test(
349  NAME proptest
350  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
351  COMMAND python2 greptest.py -d ${PROJECT_SOURCE_DIR}/../QA -t ${PROJECT_SOURCE_DIR}/../QA/proptest.xml ${CMAKE_BINARY_DIR}/icgrep)
352
353add_test(
354  NAME abc_test
355  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
356  COMMAND ./run_abc ../icgrep-build/icgrep)
357
358add_custom_target (abc_test
359  COMMAND python2 abc_testgen.py
360  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
361
362add_custom_target (check
363  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
364  DEPENDS icgrep abc_test)
365
366add_custom_target (perf_icgrep
367  COMMAND python2 perf.py icgrep
368  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
369  DEPENDS icgrep)
370
371add_custom_target (viewer
372  COMMAND python2 viewer.py
373  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
374
375add_custom_target (text_viewer
376  COMMAND python2 viewer.py -t
377  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
Note: See TracBrowser for help on using the repository browser.