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

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

Initial check of carry manager - not yet enabled

File size: 9.4 KB
RevLine 
[3850]1cmake_minimum_required (VERSION 2.8)
2
3project (icgrep)
4
[4096]5enable_testing()
[3850]6# The version number.
[4508]7set (icgrep_VERSION_MAJOR 1)
8set (icgrep_VERSION_MINOR 0)
[4096]9
[4151]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()
[4583]16option(ENABLE_MULTIPLEXING "Compiling the Multiplexing Module")
[4151]17
[4583]18
[3850]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):
[4480]47llvm_map_components_to_libnames(REQ_LLVM_LIBRARIES mcjit native)
[3850]48
[4118]49message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
[4096]50
[4196]51# Check if boost has been installed on this system.
[4210]52set(Boost_USE_STATIC_LIBS ON)
53set(Boost_USE_MULTITHREADED OFF)
[4583]54set(Boost_USE_STATIC_RUNTIME ON)
55
56if(ENABLE_MULTIPLEXING)
57find_package(Boost COMPONENTS system)
58else()
[4416]59find_package(Boost)
[4583]60endif()
[4212]61
[4644]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)
[4583]63IF (ENABLE_MULTIPLEXING)
64SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_automultiplexing.cpp)
65ENDIF()
66
67add_library(PabloADT ${PABLO_SRC})
[4626]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)
[4418]69add_library(CCADT cc/cc_namemap.cpp cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
[4618]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)
[4198]71
[4583]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})
[4598]83file(GLOB CUDD_SOURCES "${CUDD_ROOT}/cudd/*.c")
84file(GLOB EPD_SOURCES "${CUDD_ROOT}/epd/*.c")
[4583]85file(GLOB MTR_SOURCES "${CUDD_ROOT}/mtr/*.c")
86file(GLOB ST_SOURCES "${CUDD_ROOT}/st/*.c")
[4598]87file(GLOB UTIL_SOURCES "${CUDD_ROOT}/util/*.c")
[4583]88add_library(CUDD ${UTIL_SOURCES} ${MTR_SOURCES} ${CUDD_SOURCES} ${ST_SOURCES} ${EPD_SOURCES})
[4598]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)
[4583]94target_link_libraries (PabloADT CUDD)
95SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_MULTIPLEXING")
96ENDIF()
97
[4096]98include_directories("${PROJECT_SOURCE_DIR}")
[4197]99include_directories("${PROJECT_SOURCE_DIR}/re")
[4198]100include_directories("${PROJECT_SOURCE_DIR}/cc")
101include_directories("${PROJECT_SOURCE_DIR}/pablo")
[4316]102include_directories("${PROJECT_SOURCE_DIR}/UCD")
[3850]103include_directories("${PROJECT_SOURCE_DIR}/include")
104include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib")
105include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib/idisa_cpp")
[4096]106
[3850]107# add the executable
[4324]108add_executable(icgrep icgrep.cpp do_grep.cpp compiler.cpp)
[3850]109
[4623]110target_link_libraries (PabloADT ${REQ_LLVM_LIBRARIES})
[4249]111target_link_libraries (CCADT PabloADT RegExpADT)
[4623]112target_link_libraries (UCDlib PabloADT CCADT)
113target_link_libraries (RegExpADT PabloADT CCADT UCDlib)
[4380]114target_link_libraries (icgrep UCDlib PabloADT RegExpADT CCADT ${REQ_LLVM_LIBRARIES})
[3916]115
[4152]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()
[4096]137
[4200]138#Disable RunTime Type Information
139IF (MSVC) # using Visual Studio C++
[4436]140  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
[4200]141ELSE() # using Clang, GCC, Intel C++, etc
[4436]142  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
[4200]143ENDIF()
144
[4227]145#Enable all warnings
[4356]146SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
[4200]147
148#Check compiler and system architecture support for SSE or AVX
[4152]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
[4480]199set(AVX1_CODE "
[4152]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
[4480]210set(AVX2_CODE "
[4152]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")
[4480]227  SET(ENABLE_AVX1 "/arch:AVX1")
228  SET(ENABLE_AVX2 "/arch:AVX2")
[4209]229ELSE() # using Clang, GCC, Intel C++, etc 
[4152]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")
[4209]235  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
[4480]236    SET(ENABLE_AVX1 "-mavx -fabi-version=6")
237    SET(ENABLE_AVX2 "-mavx2 -fabi-version=6") 
[4209]238  ELSE()
[4480]239    SET(ENABLE_AVX1 "-mavx")
240    SET(ENABLE_AVX2 "-mavx2")
[4209]241  ENDIF()
[4152]242ENDIF()
243
[4480]244SET(CMAKE_REQUIRED_FLAGS)
[4152]245
[4480]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}")
[4152]254    ENDIF()
255    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
256  ENDIF()
257ENDMACRO()
258
[4480]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()
[4152]270
[4480]271SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ENABLE_${SIMD_SUPPORT}}")
[4152]272
[4118]273# detect LLVM version and add compiler flags.
[4508]274IF (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
[4152]275  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
[4480]276ENDIF()
[4118]277
[4209]278IF (BLOCK_SIZE_256)
279    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -m64")
280ENDIF()
[4151]281
[4200]282SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
[4522]283IF (${CMAKE_SYSTEM} MATCHES "Linux")
[4594]284    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -fsanitize=address")
[4522]285ENDIF()
[4152]286
[4096]287add_test(
288  NAME greptest
289  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
290  COMMAND python greptest.py ${CMAKE_BINARY_DIR}/icgrep)
291
[4137]292add_test(
[4456]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(
[4137]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
[4096]306add_custom_target (check
[4130]307  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
[4137]308  DEPENDS icgrep abc_test)
[4128]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
[4275]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.