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

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

Added optional CMake command -DDISABLE_PREGENERATED_UCD_FUNCTIONS.

File size: 10.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(DISABLE_PREGENERATED_UCD_FUNCTIONS "Disable compiling the pregenerated UCD functions")
18
19
20# configure a header file to pass some of the CMake settings
21# to the source code
22#configure_file (
23#  "${PROJECT_SOURCE_DIR}/icgrepconfig.h.in"
24#  "${PROJECT_BINARY_DIR}/icgrepconfig.h"
25#  )
26
27# LLVM set up
28#
29# A convenience variable:
30set(LLVM_ROOT "../libllvm" CACHE PATH "Root of LLVM install.")
31
32# A bit of a sanity check:
33if( NOT EXISTS ${LLVM_ROOT}/include/llvm )
34message(FATAL_ERROR "LLVM_ROOT (${LLVM_ROOT}) is not a valid LLVM install")
35endif()
36
37# We incorporate the CMake features provided by LLVM:
38set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT}/share/llvm/cmake")
39include(LLVMConfig)
40
41# Now set the header and library paths:
42include_directories( ${LLVM_INCLUDE_DIRS} )
43link_directories( ${LLVM_LIBRARY_DIRS} )
44add_definitions( ${LLVM_DEFINITIONS} )
45
46# Let's suppose we want to build a JIT compiler with support for
47# binary code (no interpreter):
48llvm_map_components_to_libnames(REQ_LLVM_LIBRARIES mcjit native)
49
50message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
51
52# Check if boost has been installed on this system.
53set(Boost_USE_STATIC_LIBS ON)
54set(Boost_USE_MULTITHREADED OFF)
55set(Boost_USE_STATIC_RUNTIME ON)
56
57if(ENABLE_MULTIPLEXING)
58find_package(Boost COMPONENTS system REQUIRED)
59else()
60find_package(Boost)
61endif()
62
63SET(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 pablo/pablo_compiler.cpp pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/pablo_codesinking.cpp pablo/carry_data.cpp pablo/carry_manager.cpp IDISA/idisa_builder.cpp)
64IF (ENABLE_MULTIPLEXING)
65SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_automultiplexing.cpp)
66ENDIF()
67
68add_library(PabloADT ${PABLO_SRC})
69add_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)
70add_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)
71add_library(CCADT cc/cc_namemap.cpp cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
72add_library(UCDlib UCD/unicode_set.cpp UCD/ucd_compiler.cpp UCD/PropertyObjects.cpp UCD/resolve_properties.cpp)
73
74
75# add the executable
76target_link_libraries (PabloADT ${REQ_LLVM_LIBRARIES})
77target_link_libraries (CCADT PabloADT)
78target_link_libraries (UCDlib RegExpADT PabloADT CCADT)
79target_link_libraries (RegExpADT PabloADT CCADT UCDlib)
80target_link_libraries (RegExpCompiler RegExpADT)
81
82set(PRECOMPILED_FILES "")
83
84IF(DISABLE_PREGENERATED_UCD_FUNCTIONS)
85set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDISABLE_PREGENERATED_UCD_FUNCTIONS")
86MESSAGE("Disabling predefined UCD functions...")
87ELSE()
88# add the executable
89add_executable(generate_predefined_ucd_functions generate_predefined_ucd_functions.cpp)
90target_link_libraries (generate_predefined_ucd_functions RegExpADT UCDlib PabloADT CCADT)
91
92set(PRECOMPILED_PROPERTIES_OBJ ${PROJECT_BINARY_DIR}/precompiled_properties.o)
93set(PRECOMPILED_FILES ${PRECOMPILED_PROPERTIES_OBJ} ${PROJECT_SOURCE_DIR}/UCD/precompiled_properties.cpp)
94
95if(ENABLE_MULTIPLEXING)
96set(MULTIPLEXING_FLAG -multiplexing -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv)
97endif()
98
99add_custom_command(OUTPUT ${PRECOMPILED_FILES}
100  COMMAND generate_predefined_ucd_functions
101  ARGS -o ${PRECOMPILED_PROPERTIES_OBJ} -dir ${PROJECT_SOURCE_DIR}/UCD/ ${MULTIPLEXING_FLAG}
102  DEPENDS generate_predefined_ucd_functions
103  COMMENT "Building predefined UCD functions..."
104  VERBATIM)
105
106add_custom_target(run_generate_predefined_ucd_functions ALL DEPENDS ${PRECOMPILED_FILES})
107
108add_dependencies(RegExpCompiler run_generate_predefined_ucd_functions)
109ENDIF()
110
111add_executable(icgrep icgrep.cpp do_grep.cpp compiler.cpp ${PRECOMPILED_FILES})
112IF(NOT DISABLE_PREGENERATED_UCD_FUNCTIONS)
113add_dependencies(icgrep run_generate_predefined_ucd_functions)
114ENDIF()
115target_link_libraries (icgrep UCDlib PabloADT RegExpCompiler CCADT ${REQ_LLVM_LIBRARIES})
116
117IF(Boost_FOUND)
118    include_directories("${Boost_INCLUDE_DIRS}")
119    link_directories(${Boost_LIBRARY_DIR})
120    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST")
121ENDIF()
122
123IF (ENABLE_MULTIPLEXING)
124message(STATUS "Enabling Multiplexing")
125SET(CUDD_ROOT "${CMAKE_SOURCE_DIR}/../cudd-2.5.1")
126file(GLOB CUDD_SOURCES "${CUDD_ROOT}/cudd/*.c")
127file(GLOB EPD_SOURCES "${CUDD_ROOT}/epd/*.c")
128file(GLOB MTR_SOURCES "${CUDD_ROOT}/mtr/*.c")
129file(GLOB ST_SOURCES "${CUDD_ROOT}/st/*.c")
130file(GLOB UTIL_SOURCES "${CUDD_ROOT}/util/*.c")
131add_library(CUDD ${UTIL_SOURCES} ${MTR_SOURCES} ${CUDD_SOURCES} ${ST_SOURCES} ${EPD_SOURCES})
132include_directories(${CUDD_ROOT}/cudd)
133include_directories(${CUDD_ROOT}/epd)
134include_directories(${CUDD_ROOT}/mtr)
135include_directories(${CUDD_ROOT}/st)
136include_directories(${CUDD_ROOT}/util)
137target_link_libraries (PabloADT CUDD)
138SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_MULTIPLEXING")
139ENDIF()
140
141include_directories("${PROJECT_SOURCE_DIR}")
142
143#Check compiler support for 0x / 11
144include(CheckCXXCompilerFlag)
145CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
146if(COMPILER_SUPPORTS_CXX11)
147  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
148else()
149  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
150  if(COMPILER_SUPPORTS_CXX0X)
151    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
152  else()
153    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
154    if(COMPILER_SUPPORTS_GNU11)
155      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
156    else() 
157      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
158      if(COMPILER_SUPPORTS_GNU0X)
159        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
160      endif()
161    endif()
162  endif()
163endif()
164
165#Disable RunTime Type Information
166IF (MSVC) # using Visual Studio C++
167  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
168ELSE() # using Clang, GCC, Intel C++, etc
169  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
170ENDIF()
171
172#Enable all warnings
173SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
174
175#Check compiler and system architecture support for SSE or AVX
176include(CheckCXXSourceRuns)
177
178set(SSE1_CODE "
179#include <xmmintrin.h>
180int main()
181{
182__m128 a;
183float vals[4] = {0,0,0,0};
184a = _mm_loadu_ps(vals);
185return 0;
186}")
187
188set(SSE2_CODE "
189#include <emmintrin.h>
190int main()
191{
192__m128d a;
193double vals[2] = {0,0};
194a = _mm_loadu_pd(vals);
195return 0;
196}")
197
198set(SSE3_CODE "
199#include <pmmintrin.h>
200int main( )
201{
202const int vals[4] = {0,0,0,0};
203__m128i a;
204a = _mm_lddqu_si128( (const __m128i*)vals );
205return 0;
206}")
207
208set(SSE4_1_CODE "
209#include <smmintrin.h>
210int main ()
211{
212__m128i a, b;
213__m128i res = _mm_max_epi8(a, b);
214return 0;
215}")
216
217set(SSE4_2_CODE "
218#include <nmmintrin.h>
219int main()
220{
221__m128i a, b, c;
222c = _mm_cmpgt_epi64(a, b);
223return 0;
224}")
225
226set(AVX1_CODE "
227#include <immintrin.h>
228int main()
229{
230__m256* a=(__m256*)_mm_malloc(4, 32);
231__m256 b = _mm256_load_ps((float*)a);
232b = _mm256_or_ps(b, b);
233_mm_free(a);
234return 0;
235}")
236
237set(AVX2_CODE "
238#include <immintrin.h>
239int main()
240{
241__m256i* a = (__m256i*)_mm_malloc(4, 32);
242__m256i b = _mm256_load_si256(a);
243b = _mm256_or_si256(b, b);
244_mm_free(a);
245return 0;
246}")
247
248IF (MSVC) # using Visual Studio C++
249  SET(ENABLE_SSE1 "/arch:SSE")
250  SET(ENABLE_SSE2 "/arch:SSE2")
251  SET(ENABLE_SSE3 "/arch:SSE3")
252  SET(ENABLE_SSE4_1 "/arch:SSE4")
253  SET(ENABLE_SSE4_2 "/arch:SSE4")
254  SET(ENABLE_AVX1 "/arch:AVX1")
255  SET(ENABLE_AVX2 "/arch:AVX2")
256ELSE() # using Clang, GCC, Intel C++, etc 
257  SET(ENABLE_SSE1 "-msse")
258  SET(ENABLE_SSE2 "-msse2")
259  SET(ENABLE_SSE3 "-msse3")
260  SET(ENABLE_SSE4_1 "-msse4.1")
261  SET(ENABLE_SSE4_2 "-msse4.2")
262  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
263    SET(ENABLE_AVX1 "-mavx -fabi-version=6")
264    SET(ENABLE_AVX2 "-mavx2 -fabi-version=6") 
265  ELSE()
266    SET(ENABLE_AVX1 "-mavx")
267    SET(ENABLE_AVX2 "-mavx2")
268  ENDIF()
269ENDIF()
270
271SET(CMAKE_REQUIRED_FLAGS)
272
273MACRO(CHECK_SIMD_SUPPORT SIMD_TYPE RESULT)
274  IF(NOT RESULT) 
275    SET(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
276    SET(CMAKE_REQUIRED_FLAGS ${ENABLE_${SIMD_TYPE}})
277    SET(SUCCESS "${SIMD_TYPE}")
278    check_cxx_source_runs("${${SIMD_TYPE}_CODE}" ${SUCCESS})   
279    IF(${SUCCESS})
280      SET(${RESULT} "${SIMD_TYPE}")
281    ENDIF()
282    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
283  ENDIF()
284ENDMACRO()
285
286IF(NOT SIMD_SUPPORT)
287SET(RESULT)
288CHECK_SIMD_SUPPORT("AVX2" RESULT)
289CHECK_SIMD_SUPPORT("AVX1" RESULT)
290CHECK_SIMD_SUPPORT("SSE4_2" RESULT)
291CHECK_SIMD_SUPPORT("SSE4_1" RESULT)
292CHECK_SIMD_SUPPORT("SSE3" RESULT)
293CHECK_SIMD_SUPPORT("SSE2" RESULT)
294CHECK_SIMD_SUPPORT("SSE1" RESULT)
295SET(SIMD_SUPPORT ${RESULT} CACHE STRING "SSE2")
296ENDIF()
297
298SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ENABLE_${SIMD_SUPPORT}}")
299
300# detect LLVM version and add compiler flags.
301IF (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
302  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
303ENDIF()
304
305IF (BLOCK_SIZE_256)
306    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -m64")
307ENDIF()
308
309SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
310IF (${CMAKE_SYSTEM} MATCHES "Linux")
311    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -fsanitize=address")
312ENDIF()
313
314add_test(
315  NAME greptest
316  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
317  COMMAND python greptest.py ${CMAKE_BINARY_DIR}/icgrep)
318
319add_test(
320  NAME proptest
321  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
322  COMMAND python greptest.py -d ${PROJECT_SOURCE_DIR}/../QA -t ${PROJECT_SOURCE_DIR}/../QA/proptest.xml ${CMAKE_BINARY_DIR}/icgrep)
323
324add_test(
325  NAME abc_test
326  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
327  COMMAND ./run_abc ../icgrep-build/icgrep)
328
329add_custom_target (abc_test
330  COMMAND python abc_testgen.py
331  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
332
333add_custom_target (check
334  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
335  DEPENDS icgrep abc_test)
336
337add_custom_target (perf_icgrep
338  COMMAND python perf.py icgrep
339  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
340  DEPENDS icgrep)
341
342add_custom_target (viewer
343  COMMAND python viewer.py
344  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
345
346add_custom_target (text_viewer
347  COMMAND python viewer.py -t
348  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
Note: See TracBrowser for help on using the repository browser.