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

Last change on this file since 4654 was 4654, checked in by cameron, 4 years ago

Move logic for advance operations entirely within carry manager.

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