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

Last change on this file since 4316 was 4316, checked in by cameron, 5 years ago

Case insensitive matching - initial check in.

File size: 8.1 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)
53find_package(Boost COMPONENTS system REQUIRED)
54
55add_library(PabloADT pablo/pe_and.cpp pablo/pe_not.cpp pablo/pe_or.cpp  pablo/pabloAST.cpp  pablo/pe_sel.cpp  pablo/pe_xor.cpp pablo/codegenstate.cpp  pablo/symbol_generator.cpp pablo/analysis/useanalysis.cpp pablo/printer_pablos.cpp pablo/pablo_compiler.cpp)
56add_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)
57add_library(CCADT cc/cc_namemap.cpp cc/cc_compiler.cpp utf_encoding.cpp utf8_encoder.cpp unicode_categories.h UCD/CaseFolding_txt.cpp)
58
59include_directories("${PROJECT_SOURCE_DIR}")
60include_directories("${PROJECT_SOURCE_DIR}/re")
61include_directories("${PROJECT_SOURCE_DIR}/cc")
62include_directories("${PROJECT_SOURCE_DIR}/pablo")
63include_directories("${PROJECT_SOURCE_DIR}/UCD")
64include_directories("${PROJECT_SOURCE_DIR}/include")
65include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib")
66include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib/idisa_cpp")
67
68# add the executable
69add_executable(icgrep icgrep.cpp compiler.cpp)
70
71target_link_libraries (CCADT PabloADT RegExpADT)
72target_link_libraries (PabloADT ${REQ_LLVM_LIBRARIES})
73target_link_libraries (icgrep PabloADT RegExpADT CCADT ${REQ_LLVM_LIBRARIES})
74# If Boost is on the system, include the headers and libraries
75IF(Boost_FOUND)
76    include_directories("${Boost_INCLUDE_DIRS}")
77    link_directories(${Boost_LIBRARY_DIR})
78    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST")
79    target_link_libraries (CCADT ${Boost_LIBRARIES})
80    target_link_libraries (PabloADT ${Boost_LIBRARIES})
81    target_link_libraries (RegExpADT ${Boost_LIBRARIES})
82ENDIF()
83
84#Check compiler support for 0x / 11
85include(CheckCXXCompilerFlag)
86CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
87if(COMPILER_SUPPORTS_CXX11)
88  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
89else()
90  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
91  if(COMPILER_SUPPORTS_CXX0X)
92    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
93  else()
94    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
95    if(COMPILER_SUPPORTS_GNU11)
96      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
97    else() 
98      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
99      if(COMPILER_SUPPORTS_GNU0X)
100        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
101      endif()
102    endif()
103  endif()
104endif()
105
106
107#Disable RunTime Type Information
108IF (MSVC) # using Visual Studio C++
109  #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
110ELSE() # using Clang, GCC, Intel C++, etc
111  #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
112ENDIF()
113
114#Enable all warnings
115#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
116
117#Check compiler and system architecture support for SSE or AVX
118include(CheckCXXSourceRuns)
119
120set(SSE1_CODE "
121#include <xmmintrin.h>
122int main()
123{
124__m128 a;
125float vals[4] = {0,0,0,0};
126a = _mm_loadu_ps(vals);
127return 0;
128}")
129
130set(SSE2_CODE "
131#include <emmintrin.h>
132int main()
133{
134__m128d a;
135double vals[2] = {0,0};
136a = _mm_loadu_pd(vals);
137return 0;
138}")
139
140set(SSE3_CODE "
141#include <pmmintrin.h>
142int main( )
143{
144const int vals[4] = {0,0,0,0};
145__m128i a;
146a = _mm_lddqu_si128( (const __m128i*)vals );
147return 0;
148}")
149
150set(SSE4_1_CODE "
151#include <smmintrin.h>
152int main ()
153{
154__m128i a, b;
155__m128i res = _mm_max_epi8(a, b);
156return 0;
157}")
158
159set(SSE4_2_CODE "
160#include <nmmintrin.h>
161int main()
162{
163__m128i a, b, c;
164c = _mm_cmpgt_epi64(a, b);
165return 0;
166}")
167
168set(AVX_1_CODE "
169#include <immintrin.h>
170int main()
171{
172__m256* a=(__m256*)_mm_malloc(4, 32);
173__m256 b = _mm256_load_ps((float*)a);
174b = _mm256_or_ps(b, b);
175_mm_free(a);
176return 0;
177}")
178
179set(AVX_2_CODE "
180#include <immintrin.h>
181int main()
182{
183__m256i* a = (__m256i*)_mm_malloc(4, 32);
184__m256i b = _mm256_load_si256(a);
185b = _mm256_or_si256(b, b);
186_mm_free(a);
187return 0;
188}")
189
190IF (MSVC) # using Visual Studio C++
191  SET(ENABLE_SSE1 "/arch:SSE")
192  SET(ENABLE_SSE2 "/arch:SSE2")
193  SET(ENABLE_SSE3 "/arch:SSE3")
194  SET(ENABLE_SSE4_1 "/arch:SSE4")
195  SET(ENABLE_SSE4_2 "/arch:SSE4")
196  SET(ENABLE_AVX_1 "/arch:AVX1")
197  SET(ENABLE_AVX_2 "/arch:AVX2")
198ELSE() # using Clang, GCC, Intel C++, etc 
199  SET(ENABLE_SSE1 "-msse")
200  SET(ENABLE_SSE2 "-msse2")
201  SET(ENABLE_SSE3 "-msse3")
202  SET(ENABLE_SSE4_1 "-msse4.1")
203  SET(ENABLE_SSE4_2 "-msse4.2")
204  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
205    SET(ENABLE_AVX_1 "-mavx -fabi-version=6")
206    SET(ENABLE_AVX_2 "-mavx2 -fabi-version=6") 
207  ELSE()
208    SET(ENABLE_AVX_1 "-mavx")
209    SET(ENABLE_AVX_2 "-mavx2")
210  ENDIF()
211ENDIF()
212
213set(CMAKE_REQUIRED_FLAGS)
214set(SIMD_SUPPORT_FOUND)
215set(SIMD_MAX_BLOCK_SIZE)
216
217MACRO(CHECK_SIMD_SUPPORT type maxBlockSize)
218  IF(NOT SIMD_SUPPORT_FOUND) 
219    set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
220    set(CMAKE_REQUIRED_FLAGS ${ENABLE_${type}})
221    check_cxx_source_runs("${${type}_CODE}" ${type})   
222    IF(${type})
223      SET(SIMD_SUPPORT_FOUND ${CMAKE_REQUIRED_FLAGS})
224      SET(SIMD_MAX_BLOCK_SIZE ${maxBlockSize})
225    ENDIF()
226    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
227  ENDIF()
228ENDMACRO()
229
230CHECK_SIMD_SUPPORT("AVX_2" 256)
231CHECK_SIMD_SUPPORT("AVX_1" 128)
232CHECK_SIMD_SUPPORT("SSE4_2" 128)
233CHECK_SIMD_SUPPORT("SSE4_1" 128)
234CHECK_SIMD_SUPPORT("SSE3" 128)
235CHECK_SIMD_SUPPORT("SSE2" 128)
236CHECK_SIMD_SUPPORT("SSE1" 128)
237
238SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SIMD_SUPPORT_FOUND}")
239
240# detect LLVM version and add compiler flags.
241if (${LLVM_PACKAGE_VERSION} MATCHES "3.4")
242  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_4")
243elseif (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
244  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
245endif(${LLVM_PACKAGE_VERSION} MATCHES "3.4")
246
247IF (BLOCK_SIZE_256)
248  IF(${SIMD_MAX_BLOCK_SIZE} GREATER 128)
249    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -m64")
250  ELSE()
251    MESSAGE(FATAL_ERROR "AVX2 or better is required for BLOCK_SIZE=256")
252  ENDIF()
253ENDIF()
254
255SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
256
257add_test(
258  NAME greptest
259  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
260  COMMAND python greptest.py ${CMAKE_BINARY_DIR}/icgrep)
261
262add_test(
263  NAME abc_test
264  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
265  COMMAND ./run_abc ../icgrep-build/icgrep)
266
267add_custom_target (abc_test
268  COMMAND python abc_testgen.py
269  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
270
271add_custom_target (check
272  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
273  DEPENDS icgrep abc_test)
274
275add_custom_target (perf_icgrep
276  COMMAND python perf.py icgrep
277  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
278  DEPENDS icgrep)
279
280add_custom_target (viewer
281  COMMAND python viewer.py
282  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
283
284add_custom_target (text_viewer
285  COMMAND python viewer.py -t
286  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
Note: See TracBrowser for help on using the repository browser.