-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
184 lines (154 loc) · 5.27 KB
/
CMakeLists.txt
File metadata and controls
184 lines (154 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# Root CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(SimpleLang)
enable_testing()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE Debug)
# Add cmake modules path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
# Options
option(SIMD_DEBUG "Enable SIMD debugging" OFF)
option(ENABLE_DEBUGGER "Enable kernel debugger" ON)
option(USE_MLIR "Enable MLIR integration" OFF)
option(USE_TCMALLOC "Use tcmalloc as default allocator" ON)
# LLVM setup
# LLVM_DIR should be set via -DLLVM_DIR=... when running cmake
# build.sh will set this to the correct location
find_package(LLVM REQUIRED CONFIG)
find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)
find_package(Threads REQUIRED)
# Handle readline dependency
include(FindPkgConfig)
pkg_check_modules(READLINE readline)
if(NOT READLINE_FOUND)
find_path(READLINE_INCLUDE_DIR readline/readline.h)
find_library(READLINE_LIBRARY NAMES readline)
if(READLINE_LIBRARY AND READLINE_INCLUDE_DIR)
set(READLINE_FOUND TRUE)
endif()
endif()
if(NOT READLINE_FOUND)
message(FATAL_ERROR "readline library not found. Install libreadline-dev or equivalent.")
endif()
# tcmalloc setup (for better memory allocation performance)
if(USE_TCMALLOC AND NOT CMAKE_CROSSCOMPILING)
find_library(TCMALLOC_LIBRARY NAMES tcmalloc_minimal tcmalloc)
if(TCMALLOC_LIBRARY)
set(TCMALLOC_FOUND TRUE)
message(STATUS "Found tcmalloc: ${TCMALLOC_LIBRARY}")
else()
set(TCMALLOC_FOUND FALSE)
message(WARNING "tcmalloc not found, using system malloc. Install with: apt install libtcmalloc-minimal4 libgoogle-perftools-dev")
endif()
else()
set(TCMALLOC_FOUND FALSE)
if(CMAKE_CROSSCOMPILING)
message(STATUS "tcmalloc disabled for cross-compilation")
endif()
endif()
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message(STATUS "Found readline: ${READLINE_LIBRARY}")
# MLIR setup (optional, controlled by USE_MLIR option)
if(USE_MLIR)
# MLIR_DIR should be set via -DMLIR_DIR=... when running cmake
# build.sh will set this to the correct location
find_package(MLIR REQUIRED CONFIG)
message(STATUS "MLIR integration ENABLED")
message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
# Add MLIR include directories
include_directories(
${MLIR_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/include/mlir
${CMAKE_BINARY_DIR}/src/mlir # For generated .inc files
)
# MLIR requires these definitions
add_definitions(${MLIR_DEFINITIONS})
# Include MLIR's CMake modules for mlir_tablegen()
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(TableGen)
include(AddLLVM)
include(AddMLIR)
include(HandleLLVMOptions)
# For cross-compilation, create dummy targets for missing dependencies
if(CMAKE_CROSSCOMPILING)
include(${CMAKE_SOURCE_DIR}/cmake/CrossCompileDeps.cmake)
endif()
else()
message(STATUS "MLIR integration DISABLED (use -DUSE_MLIR=ON to enable)")
endif()
include_directories(
${LLVM_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/include/kernel_debugger
${CMAKE_SOURCE_DIR}/runtime/include
${READLINE_INCLUDE_DIR}
)
add_definitions(${LLVM_DEFINITIONS})
# Create build_all target first
add_custom_target(build_all
COMMENT "Building all targets"
)
# Add subdirectories
add_subdirectory(simpblas) # SimpBLAS optimized kernels library
add_subdirectory(runtime) # Runtime library and utilities first
add_subdirectory(src) # SimpleLang compiler
# Add MLIR dialect if enabled
if(USE_MLIR)
add_subdirectory(src/mlir) # MLIR dialect implementation
endif()
add_subdirectory(tests) # Tests directory
add_subdirectory(tests/benchmark) # Benchmarks
add_subdirectory(simptensor) # SimpTensor library tests
add_subdirectory(mobilenet_poc) # MobileNet POC demonstration
# Update build_all dependencies
add_dependencies(build_all
simpblas # SimpBLAS optimized kernels library
simplang
simplang_runtime
host_runner
# test_simd_runner # DEPRECATED: old SIMD implementation
# debug_test_runner # DEPRECATED: old SIMD implementation
simplang_runner
)
# Add the runner executable
add_executable(simplang_runner
runtime/src/host.cpp
)
# Link tcmalloc first to override malloc
if(TCMALLOC_FOUND)
target_link_libraries(simplang_runner PRIVATE ${TCMALLOC_LIBRARY})
endif()
# Link against required libraries
target_link_libraries(simplang_runner
PRIVATE
simplang_runtime
${CMAKE_DL_LIBS}
)
# Add readline libraries only if not cross-compiling
if(NOT CMAKE_CROSSCOMPILING)
target_link_libraries(simplang_runner PRIVATE ${READLINE_LIBRARIES})
endif()
# Add compile definitions
target_compile_definitions(simplang_runner
PRIVATE
ENABLE_PROFILING=1
)
# Set include directories
target_include_directories(simplang_runner
PRIVATE
${CMAKE_SOURCE_DIR}/runtime/include
${CMAKE_SOURCE_DIR}/src
)
# Install the runner
install(TARGETS simplang_runner
RUNTIME DESTINATION bin
)
# Optional: Add test that uses the runner
add_test(
NAME runner_test
COMMAND simplang_runner ${CMAKE_BINARY_DIR}/tests/obj/test_arithmetic.so
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)