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

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

Preliminary steps for removal of superfluous Assigns.

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