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

Last change on this file since 4207 was 4207, checked in by nmedfort, 5 years ago

Minor changes; moved printers to re and pablo folders.

File size: 7.4 KB
Line 
1cmake_minimum_required (VERSION 2.8)
2
3project (icgrep)
4
5enable_testing()
6# The version number.
7set (icgrep_VERSION_MAJOR 0)
8set (icgrep_VERSION_MINOR 8)
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()
16
17# configure a header file to pass some of the CMake settings
18# to the source code
19#configure_file (
20#  "${PROJECT_SOURCE_DIR}/icgrepconfig.h.in"
21#  "${PROJECT_BINARY_DIR}/icgrepconfig.h"
22#  )
23
24# LLVM set up
25#
26# A convenience variable:
27set(LLVM_ROOT "../libllvm" CACHE PATH "Root of LLVM install.")
28
29# A bit of a sanity check:
30if( NOT EXISTS ${LLVM_ROOT}/include/llvm )
31message(FATAL_ERROR "LLVM_ROOT (${LLVM_ROOT}) is not a valid LLVM install")
32endif()
33
34# We incorporate the CMake features provided by LLVM:
35set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT}/share/llvm/cmake")
36include(LLVMConfig)
37
38# Now set the header and library paths:
39include_directories( ${LLVM_INCLUDE_DIRS} )
40link_directories( ${LLVM_LIBRARY_DIRS} )
41add_definitions( ${LLVM_DEFINITIONS} )
42
43# Let's suppose we want to build a JIT compiler with support for
44# binary code (no interpreter):
45llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES mcjit native)
46
47message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
48
49# Check if boost has been installed on this system.
50set(Boost_USE_STATIC_LIBS ON)
51set(Boost_USE_MULTITHREADED OFF) 
52set(Boost_USE_STATIC_RUNTIME OFF)
53include(FindBoost)
54
55add_library(PabloADT pablo/pe_advance.cpp pablo/pe_all.cpp pablo/pe_and.cpp pablo/pe_call.cpp pablo/pe_charclass.cpp  pablo/pe_matchstar.cpp pablo/pe_scanthru.cpp pablo/pe_not.cpp  pablo/pe_or.cpp  pablo/pe_pabloe.cpp  pablo/pe_sel.cpp  pablo/pe_var.cpp  pablo/pe_xor.cpp pablo/ps_assign.cpp  pablo/ps_if.cpp  pablo/codegenstate.cpp  pablo/ps_while.cpp pablo/printer_pablos.cpp)
56
57add_library(RegExpADT re/re_alt.cpp re/re_cc.cpp re/re_end.cpp re/re_name.cpp re/re_parser.cpp re/re_re.cpp re/re_rep.cpp re/re_seq.cpp re/re_start.cpp re/parsefailure.cpp re/re_reducer.cpp re/re_nullable.cpp re/re_simplifier.cpp re/re_compiler.cpp re/symbol_generator.cpp re/printer_re.cpp)
58
59add_library(CCADT cc/cc_compiler.cpp utf_encoding.cpp utf8_encoder.cpp unicode_categories.h unicode_categories-flat.h unicode_categories-simple.h)
60
61include_directories("${PROJECT_SOURCE_DIR}")
62include_directories("${PROJECT_SOURCE_DIR}/re")
63include_directories("${PROJECT_SOURCE_DIR}/cc")
64include_directories("${PROJECT_SOURCE_DIR}/pablo")
65include_directories("${PROJECT_SOURCE_DIR}/include")
66include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib")
67include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib/idisa_cpp")
68
69if (Boost_FOUND)
70    include_directories(${Boost_INCLUDE_DIRS})
71endif()
72
73# add the executable
74add_executable(icgrep icgrep.cpp llvm_gen.cpp llvm_gen_helper.cpp compiler.cpp)
75
76target_link_libraries (CCADT PabloADT)
77target_link_libraries (icgrep PabloADT RegExpADT CCADT ${REQ_LLVM_LIBRARIES})
78if (Boost_FOUND)
79    target_link_libraries (icgrep ${Boost_LIBRARIES})
80endif()
81
82
83#Check compiler support for 0x / 11
84include(CheckCXXCompilerFlag)
85CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
86if(COMPILER_SUPPORTS_CXX11)
87  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
88else()
89  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
90  if(COMPILER_SUPPORTS_CXX0X)
91    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
92  else()
93    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
94    if(COMPILER_SUPPORTS_GNU11)
95      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
96    else() 
97      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
98      if(COMPILER_SUPPORTS_GNU0X)
99        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
100      endif()
101    endif()
102  endif()
103endif()
104
105#Disable RunTime Type Information
106
107IF (MSVC) # using Visual Studio C++
108  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
109ELSE() # using Clang, GCC, Intel C++, etc
110  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
111ENDIF()
112
113
114#Check compiler and system architecture support for SSE or AVX
115include(CheckCXXSourceRuns)
116
117set(SSE1_CODE "
118#include <xmmintrin.h>
119int main()
120{
121__m128 a;
122float vals[4] = {0,0,0,0};
123a = _mm_loadu_ps(vals);
124return 0;
125}")
126
127set(SSE2_CODE "
128#include <emmintrin.h>
129int main()
130{
131__m128d a;
132double vals[2] = {0,0};
133a = _mm_loadu_pd(vals);
134return 0;
135}")
136
137set(SSE3_CODE "
138#include <pmmintrin.h>
139int main( )
140{
141const int vals[4] = {0,0,0,0};
142__m128i a;
143a = _mm_lddqu_si128( (const __m128i*)vals );
144return 0;
145}")
146
147set(SSE4_1_CODE "
148#include <smmintrin.h>
149int main ()
150{
151__m128i a, b;
152__m128i res = _mm_max_epi8(a, b);
153return 0;
154}")
155
156set(SSE4_2_CODE "
157#include <nmmintrin.h>
158int main()
159{
160__m128i a, b, c;
161c = _mm_cmpgt_epi64(a, b);
162return 0;
163}")
164
165set(AVX_1_CODE "
166#include <immintrin.h>
167int main()
168{
169__m256* a=(__m256*)_mm_malloc(4, 32);
170__m256 b = _mm256_load_ps((float*)a);
171b = _mm256_or_ps(b, b);
172_mm_free(a);
173return 0;
174}")
175
176set(AVX_2_CODE "
177#include <immintrin.h>
178int main()
179{
180__m256i* a = (__m256i*)_mm_malloc(4, 32);
181__m256i b = _mm256_load_si256(a);
182b = _mm256_or_si256(b, b);
183_mm_free(a);
184return 0;
185}")
186
187IF (MSVC) # using Visual Studio C++
188  SET(ENABLE_SSE1 "/arch:SSE")
189  SET(ENABLE_SSE2 "/arch:SSE2")
190  SET(ENABLE_SSE3 "/arch:SSE3")
191  SET(ENABLE_SSE4_1 "/arch:SSE4")
192  SET(ENABLE_SSE4_2 "/arch:SSE4")
193  SET(ENABLE_AVX_1 "/arch:AVX1")
194  SET(ENABLE_AVX_2 "/arch:AVX2")
195ELSE() # using Clang, GCC, Intel C++, etc
196  SET(ENABLE_SSE1 "-msse")
197  SET(ENABLE_SSE2 "-msse2")
198  SET(ENABLE_SSE3 "-msse3")
199  SET(ENABLE_SSE4_1 "-msse4.1")
200  SET(ENABLE_SSE4_2 "-msse4.2")
201  SET(ENABLE_AVX_1 "-mavx")
202  SET(ENABLE_AVX_2 "-mavx2")   
203ENDIF()
204
205set(CMAKE_REQUIRED_FLAGS)
206set(SIMD_SUPPORT_FOUND)
207
208MACRO(CHECK_SIMD_SUPPORT type) 
209  IF(NOT SIMD_SUPPORT_FOUND) 
210    set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
211    set(CMAKE_REQUIRED_FLAGS ${ENABLE_${type}})
212    check_cxx_source_runs("${${type}_CODE}" ${type})   
213    IF(${type})
214      SET(SIMD_SUPPORT_FOUND ${CMAKE_REQUIRED_FLAGS})
215    ENDIF()
216    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
217  ENDIF()
218ENDMACRO()
219
220CHECK_SIMD_SUPPORT("AVX_2")
221CHECK_SIMD_SUPPORT("AVX_1")
222CHECK_SIMD_SUPPORT("SSE4_2")
223CHECK_SIMD_SUPPORT("SSE4_1")
224CHECK_SIMD_SUPPORT("SSE3")
225CHECK_SIMD_SUPPORT("SSE2")
226CHECK_SIMD_SUPPORT("SSE1")
227
228SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SIMD_SUPPORT_FOUND}")
229
230# detect LLVM version and add compiler flags.
231if (${LLVM_PACKAGE_VERSION} MATCHES "3.4")
232  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_4")
233elseif (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
234  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
235endif(${LLVM_PACKAGE_VERSION} MATCHES "3.4")
236
237if (BLOCK_SIZE_256)
238  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -mavx2 -m64 -fabi-version=6")
239endif()
240
241SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
242
243add_test(
244  NAME greptest
245  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
246  COMMAND python greptest.py ${CMAKE_BINARY_DIR}/icgrep)
247
248add_test(
249  NAME abc_test
250  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
251  COMMAND ./run_abc ../icgrep-build/icgrep)
252
253add_custom_target (abc_test
254  COMMAND python abc_testgen.py
255  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
256
257add_custom_target (check
258  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
259  DEPENDS icgrep abc_test)
260
261add_custom_target (perf_icgrep
262  COMMAND python perf.py icgrep
263  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
264  DEPENDS icgrep)
265
266add_custom_target (viewer
267  COMMAND python viewer.py
268  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
269
Note: See TracBrowser for help on using the repository browser.