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

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

Work on lowering + some timing and papi information that will be cleaned up later.

File size: 11.6 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(ENABLE_PREGENERATED_UCD_FUNCTIONS "Enable compiling the pregenerated UCD functions")
19option(PRINT_TIMING_INFORMATION "Write compilation and execution timing information to standard error stream")
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;${CMAKE_CURRENT_SOURCE_DIR}/cmake")
40
41include(LLVMConfig)
42
43# Now set the header and library paths:
44include_directories( ${LLVM_INCLUDE_DIRS} )
45link_directories( ${LLVM_LIBRARY_DIRS} )
46add_definitions( ${LLVM_DEFINITIONS} )
47
48# Let's suppose we want to build a JIT compiler with support for
49# binary code (no interpreter):
50llvm_map_components_to_libnames(REQ_LLVM_LIBRARIES mcjit native IRReader) # ipo
51
52message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
53
54# Check if boost has been installed on this system.
55set(Boost_USE_STATIC_LIBS ON)
56set(Boost_USE_MULTITHREADED OFF)
57set(Boost_USE_STATIC_RUNTIME ON)
58SET(REQ_BOOST_COMPONENTS ${REQ_BOOST_COMPONENTS} system)
59if(USE_BOOST_MMAP)
60  SET(REQ_BOOST_COMPONENTS ${REQ_BOOST_COMPONENTS} iostreams filesystem)
61endif()
62find_package(Boost COMPONENTS ${REQ_BOOST_COMPONENTS} REQUIRED)
63
64SET(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)
65SET(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)
66SET(PABLO_SRC ${PABLO_SRC} pablo/analysis/pabloverifier.cpp)
67SET(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)
68SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/schedulingprepass.cpp)
69IF (ENABLE_MULTIPLEXING)
70SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_automultiplexing.cpp pablo/optimizers/pablo_bddminimization.cpp)
71ENDIF()
72
73add_library(PabloADT ${PABLO_SRC})
74add_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)
75add_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)
76add_library(CCADT cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
77add_library(UCDlib UCD/unicode_set.cpp UCD/ucd_compiler.cpp UCD/PropertyObjects.cpp UCD/resolve_properties.cpp)
78
79
80# add the executable
81target_link_libraries (PabloADT ${REQ_LLVM_LIBRARIES})
82target_link_libraries (CCADT PabloADT)
83target_link_libraries (UCDlib RegExpADT PabloADT CCADT)
84target_link_libraries (RegExpADT PabloADT CCADT UCDlib)
85target_link_libraries (RegExpCompiler RegExpADT)
86
87set(PRECOMPILED_FILES "")
88
89IF(NOT ENABLE_PREGENERATED_UCD_FUNCTIONS)
90set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDISABLE_PREGENERATED_UCD_FUNCTIONS")
91ELSE()
92MESSAGE("Enabling predefined UCD functions...")
93# add the executable
94add_executable(generate_predefined_ucd_functions generate_predefined_ucd_functions.cpp)
95llvm_map_components_to_libnames(REQ_LLVM_TARGETS ${LLVM_TARGETS_TO_BUILD})
96target_link_libraries (generate_predefined_ucd_functions RegExpADT UCDlib PabloADT CCADT ${REQ_LLVM_TARGETS})
97
98set(PRECOMPILED_PROPERTIES_OBJ ${PROJECT_BINARY_DIR}/precompiled_properties.o)
99set(PRECOMPILED_FILES ${PRECOMPILED_PROPERTIES_OBJ} ${PROJECT_SOURCE_DIR}/UCD/precompiled_properties.cpp)
100
101if(ENABLE_MULTIPLEXING)
102set(MULTIPLEXING_FLAG -multiplexing -reassoc -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv) # -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv #-ldc=ldc.csv
103endif()
104
105add_custom_command(OUTPUT ${PRECOMPILED_FILES}
106  COMMAND generate_predefined_ucd_functions
107  ARGS -o ${PRECOMPILED_PROPERTIES_OBJ} -dir ${PROJECT_SOURCE_DIR}/UCD/ ${MULTIPLEXING_FLAG} -DefaultIfHierarchy
108  DEPENDS generate_predefined_ucd_functions
109  COMMENT "Building predefined UCD functions..."
110  VERBATIM)
111
112add_custom_target(run_generate_predefined_ucd_functions DEPENDS ${PRECOMPILED_FILES})
113
114add_dependencies(RegExpCompiler run_generate_predefined_ucd_functions)
115ENDIF()
116
117add_executable(icgrep icgrep.cpp toolchain.cpp do_grep.cpp ${PRECOMPILED_FILES})
118IF(ENABLE_PREGENERATED_UCD_FUNCTIONS)
119add_dependencies(icgrep run_generate_predefined_ucd_functions)
120ENDIF()
121IF(Boost_FOUND)
122    include_directories("${Boost_INCLUDE_DIRS}")
123    link_directories(${Boost_LIBRARY_DIR})
124    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST")
125    target_link_libraries(icgrep ${Boost_LIBRARIES})
126ENDIF()
127IF (PRINT_TIMING_INFORMATION)
128    find_package(PAPI REQUIRED)
129    include_directories(${PAPI_INCLUDE_DIRS})
130    target_link_libraries(icgrep ${PAPI_LIBRARIES})
131ENDIF()
132
133
134target_link_libraries (icgrep UCDlib PabloADT RegExpCompiler CCADT ${REQ_LLVM_LIBRARIES})
135
136IF(USE_BOOST_MMAP)
137  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST_MMAP")
138ENDIF()
139
140
141IF (ENABLE_MULTIPLEXING)
142message(STATUS "Enabling Multiplexing")
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)
148SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_MULTIPLEXING")
149ENDIF()
150
151include_directories("${PROJECT_SOURCE_DIR}")
152
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()
174
175#Disable RunTime Type Information
176IF (MSVC) # using Visual Studio C++
177  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
178ELSE() # using Clang, GCC, Intel C++, etc
179  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
180ENDIF()
181
182#Enable all warnings
183SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
184
185#Check compiler and system architecture support for SSE or AVX
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
236set(AVX1_CODE "
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
247set(AVX2_CODE "
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")
264  SET(ENABLE_AVX1 "/arch:AVX1")
265  SET(ENABLE_AVX2 "/arch:AVX2")
266ELSE() # using Clang, GCC, Intel C++, etc 
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")
272  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
273    SET(ENABLE_AVX1 "-mavx -fabi-version=6")
274    SET(ENABLE_AVX2 "-mavx2 -fabi-version=6") 
275  ELSE()
276    SET(ENABLE_AVX1 "-mavx")
277    SET(ENABLE_AVX2 "-mavx2")
278  ENDIF()
279ENDIF()
280
281SET(CMAKE_REQUIRED_FLAGS)
282
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}")
291    ENDIF()
292    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
293  ENDIF()
294ENDMACRO()
295
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()
307#message("SIMD_SUPPORT=" ${SIMD_SUPPORT})
308SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ENABLE_${SIMD_SUPPORT}}")
309
310# detect LLVM version and add compiler flags.
311IF (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
312  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
313ENDIF()
314
315IF (BLOCK_SIZE_256)
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()
321ENDIF()
322
323IF (PRINT_TIMING_INFORMATION)   
324    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPRINT_TIMING_INFORMATION")
325ENDIF()
326
327SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
328IF (${CMAKE_SYSTEM} MATCHES "Linux")
329    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -fsanitize=address -fno-omit-frame-pointer")
330ENDIF()
331
332add_test(
333  NAME greptest
334  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
335  COMMAND python2 greptest.py ${CMAKE_BINARY_DIR}/icgrep)
336
337add_test(
338  NAME proptest
339  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
340  COMMAND python2 greptest.py -d ${PROJECT_SOURCE_DIR}/../QA -t ${PROJECT_SOURCE_DIR}/../QA/proptest.xml ${CMAKE_BINARY_DIR}/icgrep)
341
342add_test(
343  NAME abc_test
344  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
345  COMMAND ./run_abc ../icgrep-build/icgrep)
346
347add_custom_target (abc_test
348  COMMAND python2 abc_testgen.py
349  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
350
351add_custom_target (check
352  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
353  DEPENDS icgrep abc_test)
354
355add_custom_target (perf_icgrep
356  COMMAND python2 perf.py icgrep
357  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
358  DEPENDS icgrep)
359
360add_custom_target (viewer
361  COMMAND python2 viewer.py
362  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
363
364add_custom_target (text_viewer
365  COMMAND python2 viewer.py -t
366  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
Note: See TracBrowser for help on using the repository browser.