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

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

Minor simplification of generate_predefined_ucd_functions.

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