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

Last change on this file since 4598 was 4598, checked in by nmedfort, 4 years ago

Added the ability to compute all unique combinations of potential multiplexing sets.

File size: 9.2 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")
17
18
19# configure a header file to pass some of the CMake settings
20# to the source code
21#configure_file (
22#  "${PROJECT_SOURCE_DIR}/icgrepconfig.h.in"
23#  "${PROJECT_BINARY_DIR}/icgrepconfig.h"
24#  )
25
26# LLVM set up
27#
28# A convenience variable:
29set(LLVM_ROOT "../libllvm" CACHE PATH "Root of LLVM install.")
30
31# A bit of a sanity check:
32if( NOT EXISTS ${LLVM_ROOT}/include/llvm )
33message(FATAL_ERROR "LLVM_ROOT (${LLVM_ROOT}) is not a valid LLVM install")
34endif()
35
36# We incorporate the CMake features provided by LLVM:
37set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT}/share/llvm/cmake")
38include(LLVMConfig)
39
40# Now set the header and library paths:
41include_directories( ${LLVM_INCLUDE_DIRS} )
42link_directories( ${LLVM_LIBRARY_DIRS} )
43add_definitions( ${LLVM_DEFINITIONS} )
44
45# Let's suppose we want to build a JIT compiler with support for
46# binary code (no interpreter):
47llvm_map_components_to_libnames(REQ_LLVM_LIBRARIES mcjit native)
48
49message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
50
51# Check if boost has been installed on this system.
52set(Boost_USE_STATIC_LIBS ON)
53set(Boost_USE_MULTITHREADED OFF)
54set(Boost_USE_STATIC_RUNTIME ON)
55
56if(ENABLE_MULTIPLEXING)
57find_package(Boost COMPONENTS system)
58else()
59find_package(Boost)
60endif()
61
62SET(PABLO_SRC 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 pablo/optimizers/pablo_codesinking.cpp pablo/carry_data.cpp)
63IF (ENABLE_MULTIPLEXING)
64SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_automultiplexing.cpp)
65ENDIF()
66
67add_library(PabloADT ${PABLO_SRC})
68add_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)
69add_library(CCADT cc/cc_namemap.cpp cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
70add_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)
71
72
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")
77ENDIF()
78
79IF (ENABLE_MULTIPLEXING)
80message(STATUS "Enabling Multiplexing")
81SET(CUDD_ROOT "${CMAKE_SOURCE_DIR}/../cudd-2.5.1")
82message(STATUS ${CUDD_ROOT})
83file(GLOB CUDD_SOURCES "${CUDD_ROOT}/cudd/*.c")
84file(GLOB EPD_SOURCES "${CUDD_ROOT}/epd/*.c")
85file(GLOB MTR_SOURCES "${CUDD_ROOT}/mtr/*.c")
86file(GLOB ST_SOURCES "${CUDD_ROOT}/st/*.c")
87file(GLOB UTIL_SOURCES "${CUDD_ROOT}/util/*.c")
88add_library(CUDD ${UTIL_SOURCES} ${MTR_SOURCES} ${CUDD_SOURCES} ${ST_SOURCES} ${EPD_SOURCES})
89include_directories(${CUDD_ROOT}/cudd)
90include_directories(${CUDD_ROOT}/epd)
91include_directories(${CUDD_ROOT}/mtr)
92include_directories(${CUDD_ROOT}/st)
93include_directories(${CUDD_ROOT}/util)
94target_link_libraries (PabloADT CUDD)
95SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_MULTIPLEXING")
96ENDIF()
97
98include_directories("${PROJECT_SOURCE_DIR}")
99include_directories("${PROJECT_SOURCE_DIR}/re")
100include_directories("${PROJECT_SOURCE_DIR}/cc")
101include_directories("${PROJECT_SOURCE_DIR}/pablo")
102include_directories("${PROJECT_SOURCE_DIR}/UCD")
103include_directories("${PROJECT_SOURCE_DIR}/include")
104include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib")
105include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib/idisa_cpp")
106
107# add the executable
108add_executable(icgrep icgrep.cpp do_grep.cpp compiler.cpp)
109
110target_link_libraries (CCADT PabloADT RegExpADT)
111target_link_libraries (PabloADT ${REQ_LLVM_LIBRARIES})
112target_link_libraries (icgrep UCDlib PabloADT RegExpADT CCADT ${REQ_LLVM_LIBRARIES})
113
114#Check compiler support for 0x / 11
115include(CheckCXXCompilerFlag)
116CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
117if(COMPILER_SUPPORTS_CXX11)
118  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
119else()
120  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
121  if(COMPILER_SUPPORTS_CXX0X)
122    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
123  else()
124    CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_GNU11)
125    if(COMPILER_SUPPORTS_GNU11)
126      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
127    else() 
128      CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" COMPILER_SUPPORTS_GNU0X)   
129      if(COMPILER_SUPPORTS_GNU0X)
130        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
131      endif()
132    endif()
133  endif()
134endif()
135
136#Disable RunTime Type Information
137IF (MSVC) # using Visual Studio C++
138  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
139ELSE() # using Clang, GCC, Intel C++, etc
140  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
141ENDIF()
142
143#Enable all warnings
144SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
145
146#Check compiler and system architecture support for SSE or AVX
147include(CheckCXXSourceRuns)
148
149set(SSE1_CODE "
150#include <xmmintrin.h>
151int main()
152{
153__m128 a;
154float vals[4] = {0,0,0,0};
155a = _mm_loadu_ps(vals);
156return 0;
157}")
158
159set(SSE2_CODE "
160#include <emmintrin.h>
161int main()
162{
163__m128d a;
164double vals[2] = {0,0};
165a = _mm_loadu_pd(vals);
166return 0;
167}")
168
169set(SSE3_CODE "
170#include <pmmintrin.h>
171int main( )
172{
173const int vals[4] = {0,0,0,0};
174__m128i a;
175a = _mm_lddqu_si128( (const __m128i*)vals );
176return 0;
177}")
178
179set(SSE4_1_CODE "
180#include <smmintrin.h>
181int main ()
182{
183__m128i a, b;
184__m128i res = _mm_max_epi8(a, b);
185return 0;
186}")
187
188set(SSE4_2_CODE "
189#include <nmmintrin.h>
190int main()
191{
192__m128i a, b, c;
193c = _mm_cmpgt_epi64(a, b);
194return 0;
195}")
196
197set(AVX1_CODE "
198#include <immintrin.h>
199int main()
200{
201__m256* a=(__m256*)_mm_malloc(4, 32);
202__m256 b = _mm256_load_ps((float*)a);
203b = _mm256_or_ps(b, b);
204_mm_free(a);
205return 0;
206}")
207
208set(AVX2_CODE "
209#include <immintrin.h>
210int main()
211{
212__m256i* a = (__m256i*)_mm_malloc(4, 32);
213__m256i b = _mm256_load_si256(a);
214b = _mm256_or_si256(b, b);
215_mm_free(a);
216return 0;
217}")
218
219IF (MSVC) # using Visual Studio C++
220  SET(ENABLE_SSE1 "/arch:SSE")
221  SET(ENABLE_SSE2 "/arch:SSE2")
222  SET(ENABLE_SSE3 "/arch:SSE3")
223  SET(ENABLE_SSE4_1 "/arch:SSE4")
224  SET(ENABLE_SSE4_2 "/arch:SSE4")
225  SET(ENABLE_AVX1 "/arch:AVX1")
226  SET(ENABLE_AVX2 "/arch:AVX2")
227ELSE() # using Clang, GCC, Intel C++, etc 
228  SET(ENABLE_SSE1 "-msse")
229  SET(ENABLE_SSE2 "-msse2")
230  SET(ENABLE_SSE3 "-msse3")
231  SET(ENABLE_SSE4_1 "-msse4.1")
232  SET(ENABLE_SSE4_2 "-msse4.2")
233  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
234    SET(ENABLE_AVX1 "-mavx -fabi-version=6")
235    SET(ENABLE_AVX2 "-mavx2 -fabi-version=6") 
236  ELSE()
237    SET(ENABLE_AVX1 "-mavx")
238    SET(ENABLE_AVX2 "-mavx2")
239  ENDIF()
240ENDIF()
241
242SET(CMAKE_REQUIRED_FLAGS)
243
244MACRO(CHECK_SIMD_SUPPORT SIMD_TYPE RESULT)
245  IF(NOT RESULT) 
246    SET(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
247    SET(CMAKE_REQUIRED_FLAGS ${ENABLE_${SIMD_TYPE}})
248    SET(SUCCESS "${SIMD_TYPE}")
249    check_cxx_source_runs("${${SIMD_TYPE}_CODE}" ${SUCCESS})   
250    IF(${SUCCESS})
251      SET(${RESULT} "${SIMD_TYPE}")
252    ENDIF()
253    SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
254  ENDIF()
255ENDMACRO()
256
257IF(NOT SIMD_SUPPORT)
258SET(RESULT)
259CHECK_SIMD_SUPPORT("AVX2" RESULT)
260CHECK_SIMD_SUPPORT("AVX1" RESULT)
261CHECK_SIMD_SUPPORT("SSE4_2" RESULT)
262CHECK_SIMD_SUPPORT("SSE4_1" RESULT)
263CHECK_SIMD_SUPPORT("SSE3" RESULT)
264CHECK_SIMD_SUPPORT("SSE2" RESULT)
265CHECK_SIMD_SUPPORT("SSE1" RESULT)
266SET(SIMD_SUPPORT ${RESULT} CACHE STRING "SSE2")
267ENDIF()
268
269SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ENABLE_${SIMD_SUPPORT}}")
270
271# detect LLVM version and add compiler flags.
272IF (${LLVM_PACKAGE_VERSION} MATCHES "3.5")
273  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LLVM_3_5")
274ENDIF()
275
276IF (BLOCK_SIZE_256)
277    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_S2P_AVX2 -DBLOCK_SIZE=256 -march=core-avx2 -m64")
278ENDIF()
279
280SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
281IF (${CMAKE_SYSTEM} MATCHES "Linux")
282    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -fsanitize=address")
283ENDIF()
284
285add_test(
286  NAME greptest
287  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
288  COMMAND python greptest.py ${CMAKE_BINARY_DIR}/icgrep)
289
290add_test(
291  NAME proptest
292  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
293  COMMAND python greptest.py -d ${PROJECT_SOURCE_DIR}/../QA -t ${PROJECT_SOURCE_DIR}/../QA/proptest.xml ${CMAKE_BINARY_DIR}/icgrep)
294
295add_test(
296  NAME abc_test
297  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
298  COMMAND ./run_abc ../icgrep-build/icgrep)
299
300add_custom_target (abc_test
301  COMMAND python abc_testgen.py
302  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA)
303
304add_custom_target (check
305  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
306  DEPENDS icgrep abc_test)
307
308add_custom_target (perf_icgrep
309  COMMAND python perf.py icgrep
310  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance
311  DEPENDS icgrep)
312
313add_custom_target (viewer
314  COMMAND python viewer.py
315  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
316
317add_custom_target (text_viewer
318  COMMAND python viewer.py -t
319  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../performance)
Note: See TracBrowser for help on using the repository browser.