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

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

CMake fix

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