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

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

More work towards n-ary And/Or/Xor? functions.

File size: 11.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")
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} system 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/codemotionpass.cpp pablo/passes/flattenassociativedfg.cpp)
73SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/booleanreassociationpass.cpp)
74IF (ENABLE_MULTIPLEXING)
75SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_automultiplexing.cpp pablo/optimizers/pablo_bddminimization.cpp)
76ENDIF()
77
78add_library(PabloADT ${PABLO_SRC})
79add_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)
80add_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)
81add_library(CCADT cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
82add_library(UCDlib UCD/unicode_set.cpp UCD/ucd_compiler.cpp UCD/PropertyObjects.cpp UCD/resolve_properties.cpp)
83
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(DISABLE_PREGENERATED_UCD_FUNCTIONS)
95set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDISABLE_PREGENERATED_UCD_FUNCTIONS")
96MESSAGE("Disabling predefined UCD functions...")
97ELSE()
98
99# add the executable
100add_executable(generate_predefined_ucd_functions generate_predefined_ucd_functions.cpp)
101llvm_map_components_to_libnames(REQ_LLVM_TARGETS ${LLVM_TARGETS_TO_BUILD})
102target_link_libraries (generate_predefined_ucd_functions RegExpADT UCDlib PabloADT CCADT ${REQ_LLVM_TARGETS})
103
104set(PRECOMPILED_PROPERTIES_OBJ ${PROJECT_BINARY_DIR}/precompiled_properties.o)
105set(PRECOMPILED_FILES ${PRECOMPILED_PROPERTIES_OBJ} ${PROJECT_SOURCE_DIR}/UCD/precompiled_properties.cpp)
106
107if(ENABLE_MULTIPLEXING)
108set(MULTIPLEXING_FLAG -multiplexing -reassoc -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv) # -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv #-ldc=ldc.csv
109endif()
110
111add_custom_command(OUTPUT ${PRECOMPILED_FILES}
112  COMMAND generate_predefined_ucd_functions
113  ARGS -o ${PRECOMPILED_PROPERTIES_OBJ} -dir ${PROJECT_SOURCE_DIR}/UCD/ ${MULTIPLEXING_FLAG} -DefaultIfHierarchy
114  DEPENDS generate_predefined_ucd_functions
115  COMMENT "Building predefined UCD functions..."
116  VERBATIM)
117
118add_custom_target(run_generate_predefined_ucd_functions DEPENDS ${PRECOMPILED_FILES})
119
120add_dependencies(RegExpCompiler run_generate_predefined_ucd_functions)
121ENDIF()
122
123add_executable(icgrep icgrep.cpp toolchain.cpp do_grep.cpp ${PRECOMPILED_FILES})
124IF(NOT DISABLE_PREGENERATED_UCD_FUNCTIONS)
125add_dependencies(icgrep run_generate_predefined_ucd_functions)
126ENDIF()
127IF(Boost_FOUND)
128    include_directories("${Boost_INCLUDE_DIRS}")
129    link_directories(${Boost_LIBRARY_DIR})
130    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST")
131    target_link_libraries(icgrep ${Boost_LIBRARIES})
132ENDIF()
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
323SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
324IF (${CMAKE_SYSTEM} MATCHES "Linux")
325    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -fsanitize=address") # -fsanitize=address
326ENDIF()
327
328add_test(
329  NAME greptest
330  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
331  COMMAND python2 greptest.py ${CMAKE_BINARY_DIR}/icgrep)
332
333add_test(
334  NAME proptest
335  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
336  COMMAND python2 greptest.py -d ${PROJECT_SOURCE_DIR}/../QA -t ${PROJECT_SOURCE_DIR}/../QA/proptest.xml ${CMAKE_BINARY_DIR}/icgrep)
337
338add_test(
339  NAME abc_test
340  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
341  COMMAND ./run_abc ../icgrep-build/icgrep)
342
343add_custom_target (abc_test
344  COMMAND python2 abc_testgen.py
345  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
346
347add_custom_target (check
348  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
349  DEPENDS icgrep abc_test)
350
351add_custom_target (perf_icgrep
352  COMMAND python2 perf.py icgrep
353  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
354  DEPENDS icgrep)
355
356add_custom_target (viewer
357  COMMAND python2 viewer.py
358  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
359
360add_custom_target (text_viewer
361  COMMAND python2 viewer.py -t
362  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
Note: See TracBrowser for help on using the repository browser.