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

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

Transitory work towards using CC_Namer.

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