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

Last change on this file since 4892 was 4892, checked in by cameron, 3 years ago

Move AVX2 specific IDISA function implementations into subclassed builder

File size: 11.1 KB
Line 
1cmake_minimum_required (VERSION 2.8)
2
3project (icgrep)
4
5enable_testing()
6# The version number.
7set (icgrep_VERSION_MAJOR 1)
8set (icgrep_VERSION_MINOR 0)
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()
16option(ENABLE_MULTIPLEXING "Compiling the Multiplexing Module")
17option(USE_BOOST_MMAP "Using mmap from Boost.Iostreams")
18option(DISABLE_PREGENERATED_UCD_FUNCTIONS "Disable compiling the pregenerated UCD functions")
19
20
21# configure a header file to pass some of the CMake settings
22# to the source code
23#configure_file (
24#  "${PROJECT_SOURCE_DIR}/icgrepconfig.h.in"
25#  "${PROJECT_BINARY_DIR}/icgrepconfig.h"
26#  )
27
28# LLVM set up
29#
30# A convenience variable:
31set(LLVM_ROOT "../libllvm" CACHE PATH "Root of LLVM install.")
32
33# A bit of a sanity check:
34if( NOT EXISTS ${LLVM_ROOT}/include/llvm )
35message(FATAL_ERROR "LLVM_ROOT (${LLVM_ROOT}) is not a valid LLVM install")
36endif()
37
38# We incorporate the CMake features provided by LLVM:
39set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT}/share/llvm/cmake")
40include(LLVMConfig)
41
42# Now set the header and library paths:
43include_directories( ${LLVM_INCLUDE_DIRS} )
44link_directories( ${LLVM_LIBRARY_DIRS} )
45add_definitions( ${LLVM_DEFINITIONS} )
46
47# Let's suppose we want to build a JIT compiler with support for
48# binary code (no interpreter):
49llvm_map_components_to_libnames(REQ_LLVM_LIBRARIES mcjit native IRReader)
50
51message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
52
53# Check if boost has been installed on this system.
54set(Boost_USE_STATIC_LIBS ON)
55set(Boost_USE_MULTITHREADED OFF)
56set(Boost_USE_STATIC_RUNTIME ON)
57SET(REQ_BOOST_COMPONENTS ${REQ_BOOST_COMPONENTS} system)
58if(USE_BOOST_MMAP)
59  SET(REQ_BOOST_COMPONENTS ${REQ_BOOST_COMPONENTS} iostreams filesystem)
60endif()
61find_package(Boost COMPONENTS ${REQ_BOOST_COMPONENTS} REQUIRED)
62
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 IDISA/idisa_avx_builder.cpp)
65SET(PABLO_SRC ${PABLO_SRC} pablo/analysis/pabloverifier.cpp)
66SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/codemotionpass.cpp pablo/optimizers/distributivepass.cpp pablo/passes/flattenassociativedfg.cpp pablo/passes/factorizedfg.cpp)
67SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/booleanreassociationpass.cpp)
68IF (ENABLE_MULTIPLEXING)
69SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_automultiplexing.cpp pablo/optimizers/pablo_bddminimization.cpp)
70ENDIF()
71
72add_library(PabloADT ${PABLO_SRC})
73add_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)
74add_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)
75add_library(CCADT cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
76add_library(UCDlib UCD/unicode_set.cpp UCD/ucd_compiler.cpp UCD/PropertyObjects.cpp UCD/resolve_properties.cpp)
77
78
79# add the executable
80target_link_libraries (PabloADT ${REQ_LLVM_LIBRARIES})
81target_link_libraries (CCADT PabloADT)
82target_link_libraries (UCDlib RegExpADT PabloADT CCADT)
83target_link_libraries (RegExpADT PabloADT CCADT UCDlib)
84target_link_libraries (RegExpCompiler RegExpADT)
85
86set(PRECOMPILED_FILES "")
87
88IF(DISABLE_PREGENERATED_UCD_FUNCTIONS)
89set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDISABLE_PREGENERATED_UCD_FUNCTIONS")
90MESSAGE("Disabling predefined UCD functions...")
91ELSE()
92
93# add the executable
94add_executable(generate_predefined_ucd_functions generate_predefined_ucd_functions.cpp)
95llvm_map_components_to_libnames(REQ_LLVM_TARGETS ${LLVM_TARGETS_TO_BUILD})
96target_link_libraries (generate_predefined_ucd_functions RegExpADT UCDlib PabloADT CCADT ${REQ_LLVM_TARGETS})
97
98set(PRECOMPILED_PROPERTIES_OBJ ${PROJECT_BINARY_DIR}/precompiled_properties.o)
99set(PRECOMPILED_FILES ${PRECOMPILED_PROPERTIES_OBJ} ${PROJECT_SOURCE_DIR}/UCD/precompiled_properties.cpp)
100
101if(ENABLE_MULTIPLEXING)
102set(MULTIPLEXING_FLAG -multiplexing -reassoc -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv) # -multiplexing-dist=${PROJECT_BINARY_DIR}/ucd-multiplexing.csv #-ldc=ldc.csv
103endif()
104
105add_custom_command(OUTPUT ${PRECOMPILED_FILES}
106  COMMAND generate_predefined_ucd_functions
107  ARGS -o ${PRECOMPILED_PROPERTIES_OBJ} -dir ${PROJECT_SOURCE_DIR}/UCD/ ${MULTIPLEXING_FLAG} -DefaultIfHierarchy
108  DEPENDS generate_predefined_ucd_functions
109  COMMENT "Building predefined UCD functions..."
110  VERBATIM)
111
112add_custom_target(run_generate_predefined_ucd_functions DEPENDS ${PRECOMPILED_FILES})
113
114add_dependencies(RegExpCompiler run_generate_predefined_ucd_functions)
115ENDIF()
116
117add_executable(icgrep icgrep.cpp toolchain.cpp do_grep.cpp ${PRECOMPILED_FILES})
118IF(NOT DISABLE_PREGENERATED_UCD_FUNCTIONS)
119add_dependencies(icgrep run_generate_predefined_ucd_functions)
120ENDIF()
121IF(Boost_FOUND)
122    include_directories("${Boost_INCLUDE_DIRS}")
123    link_directories(${Boost_LIBRARY_DIR})
124    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST")
125    target_link_libraries(icgrep ${Boost_LIBRARIES})
126ENDIF()
127
128target_link_libraries (icgrep UCDlib PabloADT RegExpCompiler CCADT ${REQ_LLVM_LIBRARIES})
129
130IF(USE_BOOST_MMAP)
131  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST_MMAP")
132ENDIF()
133
134
135IF (ENABLE_MULTIPLEXING)
136message(STATUS "Enabling Multiplexing")
137SET(BUDDY_ROOT "${CMAKE_SOURCE_DIR}/../buddy-2.4")
138file(GLOB BUDDY_SOURCES "${BUDDY_ROOT}/src/*.cpp")
139add_library(BUDDY ${BUDDY_SOURCES})
140include_directories(${BUDDY_ROOT}/src)
141target_link_libraries (PabloADT BUDDY)
142SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_MULTIPLEXING")
143ENDIF()
144
145include_directories("${PROJECT_SOURCE_DIR}")
146
147#Check compiler support for 0x / 11
148include(CheckCXXCompilerFlag)
149CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
150if(COMPILER_SUPPORTS_CXX11)
151  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
152else()
153  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
154  if(COMPILER_SUPPORTS_CXX0X)
155    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
156  else()
157    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
158    if(COMPILER_SUPPORTS_GNU11)
159      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
160    else() 
161      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
162      if(COMPILER_SUPPORTS_GNU0X)
163        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
164      endif()
165    endif()
166  endif()
167endif()
168
169#Disable RunTime Type Information
170IF (MSVC) # using Visual Studio C++
171  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
172ELSE() # using Clang, GCC, Intel C++, etc
173  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
174ENDIF()
175
176#Enable all warnings
177SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
178
179#Check compiler and system architecture support for SSE or AVX
180include(CheckCXXSourceRuns)
181
182set(SSE1_CODE "
183#include <xmmintrin.h>
184int main()
185{
186__m128 a;
187float vals[4] = {0,0,0,0};
188a = _mm_loadu_ps(vals);
189return 0;
190}")
191
192set(SSE2_CODE "
193#include <emmintrin.h>
194int main()
195{
196__m128d a;
197double vals[2] = {0,0};
198a = _mm_loadu_pd(vals);
199return 0;
200}")
201
202set(SSE3_CODE "
203#include <pmmintrin.h>
204int main( )
205{
206const int vals[4] = {0,0,0,0};
207__m128i a;
208a = _mm_lddqu_si128( (const __m128i*)vals );
209return 0;
210}")
211
212set(SSE4_1_CODE "
213#include <smmintrin.h>
214int main ()
215{
216__m128i a, b;
217__m128i res = _mm_max_epi8(a, b);
218return 0;
219}")
220
221set(SSE4_2_CODE "
222#include <nmmintrin.h>
223int main()
224{
225__m128i a, b, c;
226c = _mm_cmpgt_epi64(a, b);
227return 0;
228}")
229
230set(AVX1_CODE "
231#include <immintrin.h>
232int main()
233{
234__m256* a=(__m256*)_mm_malloc(4, 32);
235__m256 b = _mm256_load_ps((float*)a);
236b = _mm256_or_ps(b, b);
237_mm_free(a);
238return 0;
239}")
240
241set(AVX2_CODE "
242#include <immintrin.h>
243int main()
244{
245__m256i* a = (__m256i*)_mm_malloc(4, 32);
246__m256i b = _mm256_load_si256(a);
247b = _mm256_or_si256(b, b);
248_mm_free(a);
249return 0;
250}")
251
252IF (MSVC) # using Visual Studio C++
253  SET(ENABLE_SSE1 "/arch:SSE")
254  SET(ENABLE_SSE2 "/arch:SSE2")
255  SET(ENABLE_SSE3 "/arch:SSE3")
256  SET(ENABLE_SSE4_1 "/arch:SSE4")
257  SET(ENABLE_SSE4_2 "/arch:SSE4")
258  SET(ENABLE_AVX1 "/arch:AVX1")
259  SET(ENABLE_AVX2 "/arch:AVX2")
260ELSE() # using Clang, GCC, Intel C++, etc 
261  SET(ENABLE_SSE1 "-msse")
262  SET(ENABLE_SSE2 "-msse2")
263  SET(ENABLE_SSE3 "-msse3")
264  SET(ENABLE_SSE4_1 "-msse4.1")
265  SET(ENABLE_SSE4_2 "-msse4.2")
266  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
267    SET(ENABLE_AVX1 "-mavx -fabi-version=6")
268    SET(ENABLE_AVX2 "-mavx2 -fabi-version=6") 
269  ELSE()
270    SET(ENABLE_AVX1 "-mavx")
271    SET(ENABLE_AVX2 "-mavx2")
272  ENDIF()
273ENDIF()
274
275SET(CMAKE_REQUIRED_FLAGS)
276
277MACRO(CHECK_SIMD_SUPPORT SIMD_TYPE RESULT)
278  IF(NOT RESULT) 
279    SET(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
280    SET(CMAKE_REQUIRED_FLAGS ${ENABLE_${SIMD_TYPE}})
281    SET(SUCCESS "${SIMD_TYPE}")
282    check_cxx_source_runs("${${SIMD_TYPE}_CODE}" ${SUCCESS})   
283    IF(${SUCCESS})
284      SET(${RESULT} "${SIMD_TYPE}")
285    ENDIF()
286    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
287  ENDIF()
288ENDMACRO()
289
290IF(NOT SIMD_SUPPORT)
291SET(RESULT)
292CHECK_SIMD_SUPPORT("AVX2" RESULT)
293CHECK_SIMD_SUPPORT("AVX1" RESULT)
294CHECK_SIMD_SUPPORT("SSE4_2" RESULT)
295CHECK_SIMD_SUPPORT("SSE4_1" RESULT)
296CHECK_SIMD_SUPPORT("SSE3" RESULT)
297CHECK_SIMD_SUPPORT("SSE2" RESULT)
298CHECK_SIMD_SUPPORT("SSE1" RESULT)
299SET(SIMD_SUPPORT ${RESULT} CACHE STRING "SSE2")
300ENDIF()
301#message("SIMD_SUPPORT=" ${SIMD_SUPPORT})
302SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ENABLE_${SIMD_SUPPORT}}")
303
304# detect LLVM version and add compiler flags.
305IF (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
306  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
307ENDIF()
308
309IF (BLOCK_SIZE_256)
310    IF ("${SIMD_SUPPORT}" STREQUAL "AVX1")
311        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX -DUSE_AVX -DBLOCK_SIZE=256 -mavx -m64")
312    ELSEIF ("${SIMD_SUPPORT}" STREQUAL "AVX2")
313        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -m64")
314    ENDIF()
315ENDIF()
316
317SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
318IF (${CMAKE_SYSTEM} MATCHES "Linux")
319    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -fsanitize=address -fno-omit-frame-pointer")
320ENDIF()
321
322add_test(
323  NAME greptest
324  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
325  COMMAND python2 greptest.py ${CMAKE_BINARY_DIR}/icgrep)
326
327add_test(
328  NAME proptest
329  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
330  COMMAND python2 greptest.py -d ${PROJECT_SOURCE_DIR}/../QA -t ${PROJECT_SOURCE_DIR}/../QA/proptest.xml ${CMAKE_BINARY_DIR}/icgrep)
331
332add_test(
333  NAME abc_test
334  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
335  COMMAND ./run_abc ../icgrep-build/icgrep)
336
337add_custom_target (abc_test
338  COMMAND python2 abc_testgen.py
339  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
340
341add_custom_target (check
342  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
343  DEPENDS icgrep abc_test)
344
345add_custom_target (perf_icgrep
346  COMMAND python2 perf.py icgrep
347  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
348  DEPENDS icgrep)
349
350add_custom_target (viewer
351  COMMAND python2 viewer.py
352  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
353
354add_custom_target (text_viewer
355  COMMAND python2 viewer.py -t
356  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
Note: See TracBrowser for help on using the repository browser.