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

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

More multiplexing work.

File size: 9.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")
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)
58else()
59find_package(Boost)
60endif()
61
62SET(PABLO_SRC pablo/pabloAST.cpp pablo/ps_assign.cpp pablo/ps_if.cpp pablo/ps_while.cpp pablo/codegenstate.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)
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_parser.cpp re/re_rep.cpp re/parsefailure.cpp re/re_nullable.cpp re/re_simplifier.cpp re/re_compiler.cpp re/printer_re.cpp re/re_diff.cpp re/re_intersect.cpp re/re_analysis.cpp)
69add_library(CCADT cc/cc_namemap.cpp cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
70add_library(UCDlib UCD/unicode_set.cpp UCD/precompiled_gc.cpp UCD/precompiled_sc.cpp UCD/precompiled_scx.cpp UCD/precompiled_blk.cpp UCD/precompiled_derivedcoreproperties.cpp UCD/precompiled_proplist.cpp)
71
72
73IF(Boost_FOUND)
74    include_directories("${Boost_INCLUDE_DIRS}")
75    link_directories(${Boost_LIBRARY_DIR})
76    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST")
77ENDIF()
78
79IF (ENABLE_MULTIPLEXING)
80message(STATUS "Enabling Multiplexing")
81SET(CUDD_ROOT "${CMAKE_SOURCE_DIR}/../cudd-2.5.1")
82message(STATUS ${CUDD_ROOT})
83file(GLOB UTIL_SOURCES "${CUDD_ROOT}/util/*.c")
84file(GLOB MTR_SOURCES "${CUDD_ROOT}/mtr/*.c")
85file(GLOB CUDD_SOURCES "${CUDD_ROOT}/cudd/*.c")
86file(GLOB ST_SOURCES "${CUDD_ROOT}/st/*.c")
87file(GLOB EPD_SOURCES "${CUDD_ROOT}/epd/*.c")
88add_library(CUDD ${UTIL_SOURCES} ${MTR_SOURCES} ${CUDD_SOURCES} ${ST_SOURCES} ${EPD_SOURCES})
89
90
91
92include_directories(${CUDD_ROOT}/include)
93target_link_libraries (PabloADT CUDD)
94SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_MULTIPLEXING")
95ENDIF()
96
97include_directories("${PROJECT_SOURCE_DIR}")
98include_directories("${PROJECT_SOURCE_DIR}/re")
99include_directories("${PROJECT_SOURCE_DIR}/cc")
100include_directories("${PROJECT_SOURCE_DIR}/pablo")
101include_directories("${PROJECT_SOURCE_DIR}/UCD")
102include_directories("${PROJECT_SOURCE_DIR}/include")
103include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib")
104include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib/idisa_cpp")
105
106# add the executable
107add_executable(icgrep icgrep.cpp do_grep.cpp compiler.cpp)
108
109target_link_libraries (CCADT PabloADT RegExpADT)
110target_link_libraries (PabloADT ${REQ_LLVM_LIBRARIES})
111target_link_libraries (icgrep UCDlib PabloADT RegExpADT CCADT ${REQ_LLVM_LIBRARIES})
112
113#Check compiler support for 0x / 11
114include(CheckCXXCompilerFlag)
115CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
116if(COMPILER_SUPPORTS_CXX11)
117  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
118else()
119  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
120  if(COMPILER_SUPPORTS_CXX0X)
121    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
122  else()
123    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
124    if(COMPILER_SUPPORTS_GNU11)
125      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
126    else() 
127      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
128      if(COMPILER_SUPPORTS_GNU0X)
129        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
130      endif()
131    endif()
132  endif()
133endif()
134
135#Disable RunTime Type Information
136IF (MSVC) # using Visual Studio C++
137  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
138ELSE() # using Clang, GCC, Intel C++, etc
139  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
140ENDIF()
141
142#Enable all warnings
143SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
144
145#Check compiler and system architecture support for SSE or AVX
146include(CheckCXXSourceRuns)
147
148set(SSE1_CODE "
149#include <xmmintrin.h>
150int main()
151{
152__m128 a;
153float vals[4] = {0,0,0,0};
154a = _mm_loadu_ps(vals);
155return 0;
156}")
157
158set(SSE2_CODE "
159#include <emmintrin.h>
160int main()
161{
162__m128d a;
163double vals[2] = {0,0};
164a = _mm_loadu_pd(vals);
165return 0;
166}")
167
168set(SSE3_CODE "
169#include <pmmintrin.h>
170int main( )
171{
172const int vals[4] = {0,0,0,0};
173__m128i a;
174a = _mm_lddqu_si128( (const __m128i*)vals );
175return 0;
176}")
177
178set(SSE4_1_CODE "
179#include <smmintrin.h>
180int main ()
181{
182__m128i a, b;
183__m128i res = _mm_max_epi8(a, b);
184return 0;
185}")
186
187set(SSE4_2_CODE "
188#include <nmmintrin.h>
189int main()
190{
191__m128i a, b, c;
192c = _mm_cmpgt_epi64(a, b);
193return 0;
194}")
195
196set(AVX1_CODE "
197#include <immintrin.h>
198int main()
199{
200__m256* a=(__m256*)_mm_malloc(4, 32);
201__m256 b = _mm256_load_ps((float*)a);
202b = _mm256_or_ps(b, b);
203_mm_free(a);
204return 0;
205}")
206
207set(AVX2_CODE "
208#include <immintrin.h>
209int main()
210{
211__m256i* a = (__m256i*)_mm_malloc(4, 32);
212__m256i b = _mm256_load_si256(a);
213b = _mm256_or_si256(b, b);
214_mm_free(a);
215return 0;
216}")
217
218IF (MSVC) # using Visual Studio C++
219  SET(ENABLE_SSE1 "/arch:SSE")
220  SET(ENABLE_SSE2 "/arch:SSE2")
221  SET(ENABLE_SSE3 "/arch:SSE3")
222  SET(ENABLE_SSE4_1 "/arch:SSE4")
223  SET(ENABLE_SSE4_2 "/arch:SSE4")
224  SET(ENABLE_AVX1 "/arch:AVX1")
225  SET(ENABLE_AVX2 "/arch:AVX2")
226ELSE() # using Clang, GCC, Intel C++, etc 
227  SET(ENABLE_SSE1 "-msse")
228  SET(ENABLE_SSE2 "-msse2")
229  SET(ENABLE_SSE3 "-msse3")
230  SET(ENABLE_SSE4_1 "-msse4.1")
231  SET(ENABLE_SSE4_2 "-msse4.2")
232  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
233    SET(ENABLE_AVX1 "-mavx -fabi-version=6")
234    SET(ENABLE_AVX2 "-mavx2 -fabi-version=6") 
235  ELSE()
236    SET(ENABLE_AVX1 "-mavx")
237    SET(ENABLE_AVX2 "-mavx2")
238  ENDIF()
239ENDIF()
240
241SET(CMAKE_REQUIRED_FLAGS)
242
243MACRO(CHECK_SIMD_SUPPORT SIMD_TYPE RESULT)
244  IF(NOT RESULT) 
245    SET(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
246    SET(CMAKE_REQUIRED_FLAGS ${ENABLE_${SIMD_TYPE}})
247    SET(SUCCESS "${SIMD_TYPE}")
248    check_cxx_source_runs("${${SIMD_TYPE}_CODE}" ${SUCCESS})   
249    IF(${SUCCESS})
250      SET(${RESULT} "${SIMD_TYPE}")
251    ENDIF()
252    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
253  ENDIF()
254ENDMACRO()
255
256IF(NOT SIMD_SUPPORT)
257SET(RESULT)
258CHECK_SIMD_SUPPORT("AVX2" RESULT)
259CHECK_SIMD_SUPPORT("AVX1" RESULT)
260CHECK_SIMD_SUPPORT("SSE4_2" RESULT)
261CHECK_SIMD_SUPPORT("SSE4_1" RESULT)
262CHECK_SIMD_SUPPORT("SSE3" RESULT)
263CHECK_SIMD_SUPPORT("SSE2" RESULT)
264CHECK_SIMD_SUPPORT("SSE1" RESULT)
265SET(SIMD_SUPPORT ${RESULT} CACHE STRING "SSE2")
266ENDIF()
267
268SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ENABLE_${SIMD_SUPPORT}}")
269
270# detect LLVM version and add compiler flags.
271IF (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
272  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
273ENDIF()
274
275IF (BLOCK_SIZE_256)
276    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -m64")
277ENDIF()
278
279SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
280IF (${CMAKE_SYSTEM} MATCHES "Linux")
281    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -fsanitize=alignment")
282ENDIF()
283
284add_test(
285  NAME greptest
286  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
287  COMMAND python greptest.py ${CMAKE_BINARY_DIR}/icgrep)
288
289add_test(
290  NAME proptest
291  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
292  COMMAND python greptest.py -d ${PROJECT_SOURCE_DIR}/../QA -t ${PROJECT_SOURCE_DIR}/../QA/proptest.xml ${CMAKE_BINARY_DIR}/icgrep)
293
294add_test(
295  NAME abc_test
296  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
297  COMMAND ./run_abc ../icgrep-build/icgrep)
298
299add_custom_target (abc_test
300  COMMAND python abc_testgen.py
301  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
302
303add_custom_target (check
304  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
305  DEPENDS icgrep abc_test)
306
307add_custom_target (perf_icgrep
308  COMMAND python perf.py icgrep
309  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
310  DEPENDS icgrep)
311
312add_custom_target (viewer
313  COMMAND python viewer.py
314  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
315
316add_custom_target (text_viewer
317  COMMAND python viewer.py -t
318  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
Note: See TracBrowser for help on using the repository browser.