Skip to content

Commit dcfade4

Browse files
authored
Merge branch 'main' into integrates/iree
2 parents 15233f9 + d179453 commit dcfade4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1480
-855
lines changed

.github/workflows/ci-sharkfuser.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ jobs:
3535
runs-on: ${{ matrix.runs-on }}
3636
defaults:
3737
run:
38-
shell: bash
38+
# github actions swaps the {0} at the end for your script
39+
shell: bash --noprofile --norc -exo pipefail {0}
3940
strategy:
4041
fail-fast: false
4142
matrix:
@@ -47,6 +48,7 @@ jobs:
4748
-DCMAKE_C_COMPILER=clang-18
4849
-DCMAKE_CXX_COMPILER=clang++-18
4950
-DCMAKE_LINKER_TYPE=LLD
51+
-DPython3_EXECUTABLE=$(which python3)
5052
-DSHARKFUSER_DEBUG_BUILD=OFF
5153
-DSHARKFUSER_CODE_COVERAGE=OFF
5254
additional-packages: clang lld
@@ -59,6 +61,7 @@ jobs:
5961
-DCMAKE_C_COMPILER=clang-18
6062
-DCMAKE_CXX_COMPILER=clang++-18
6163
-DCMAKE_LINKER_TYPE=LLD
64+
-DPython3_EXECUTABLE=$(which python3)
6265
-DSHARKFUSER_DEBUG_BUILD=ON
6366
-DSHARKFUSER_CODE_COVERAGE=OFF
6467
additional-packages: clang lld
@@ -70,6 +73,7 @@ jobs:
7073
cmake-options:
7174
-DCMAKE_C_COMPILER=gcc-13
7275
-DCMAKE_CXX_COMPILER=g++-13
76+
-DPython3_EXECUTABLE=$(which python3)
7377
-DSHARKFUSER_DEBUG_BUILD=OFF
7478
-DSHARKFUSER_CODE_COVERAGE=ON
7579
additional-packages: lcov

docs/shortfin/llm/user/llama_serving.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ python -m sharktank.examples.export_paged_llm_v1 \
385385
--output-config /path/to/output/llama3.1-405b.config.json \
386386
--bs-prefill 4 \
387387
--bs-decode 4 \
388-
--use-attention-mask
388+
--use-attention-mask \
389+
--tensor-parallelism-size=8
389390
```
390391
391392
### Compiling to VMFB

sharkfuser/CMakeLists.txt

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,14 @@ message(STATUS " - Host")
7777
################################################################################
7878

7979
set(IREE_VISIBILITY_HIDDEN OFF)
80-
set(IREE_BUILD_COMPILER OFF)
80+
set(IREE_BUILD_COMPILER ON)
8181
set(IREE_BUILD_TESTS OFF)
8282
set(IREE_BUILD_SAMPLES OFF)
8383
set(IREE_ERROR_ON_MISSING_SUBMODULES OFF)
8484
set(IREE_HAL_DRIVER_DEFAULTS OFF)
85+
set(IREE_TARGET_BACKEND_DEFAULTS OFF)
86+
set(IREE_INPUT_STABLEHLO OFF)
87+
set(IREE_INPUT_TOSA OFF)
8588
set(IREE_HAL_DRIVER_LOCAL_SYNC OFF)
8689
set(IREE_HAL_DRIVER_LOCAL_TASK OFF)
8790
set(IREE_HAL_DRIVER_VULKAN OFF)
@@ -94,7 +97,15 @@ if(SHARKFUSER_IREE_SOURCE_DIR)
9497
add_subdirectory(${SHARKFUSER_IREE_SOURCE_DIR} sharkfuser_iree SYSTEM EXCLUDE_FROM_ALL)
9598
else()
9699
message(STATUS "Fetching IREE sources from tag ${SHARKFUSER_IREE_GIT_TAG}")
97-
set(IREE_SUBMODULES "third_party/benchmark third_party/cpuinfo third_party/flatcc third_party/hip-build-deps")
100+
set(IREE_SUBMODULES "")
101+
list(APPEND IREE_SUBMODULES "third_party/benchmark")
102+
list(APPEND IREE_SUBMODULES "third_party/cpuinfo")
103+
list(APPEND IREE_SUBMODULES "third_party/flatcc")
104+
list(APPEND IREE_SUBMODULES "third_party/hip-build-deps")
105+
if(IREE_BUILD_COMPILER)
106+
list(APPEND IREE_SUBMODULES "third_party/llvm-project")
107+
list(APPEND IREE_SUBMODULES "third_party/torch-mlir")
108+
endif()
98109
FetchContent_Declare(
99110
sharkfuser_iree
100111
GIT_REPOSITORY https://github.com/iree-org/iree.git
@@ -107,6 +118,18 @@ else()
107118
FetchContent_GetProperties(sharkfuser_iree)
108119
if(NOT sharkfuser_iree_POPULATED)
109120
FetchContent_MakeAvailable(sharkfuser_iree)
121+
122+
# LLVM repo has several .gcda and .gcno files as test fixtures for llvm-cov.
123+
# Those .g* files will have version issues + errors when importing with our
124+
# code coverage. It's remarkably difficult to convince lcov to ignore files,
125+
# so the easiest thing to do is just strip them out.
126+
message(STATUS "Removing codecov files from LLVM")
127+
execute_process(
128+
COMMAND ${CMAKE_COMMAND}
129+
-DSHARKFUSER_IREE_SOURCE_DIR=${sharkfuser_iree_SOURCE_DIR}
130+
-P ${CMAKE_CURRENT_SOURCE_DIR}/build_tools/cmake/strip_codecov_files.cmake
131+
WORKING_DIRECTORY ${sharkfuser_iree_SOURCE_DIR}
132+
)
110133
endif()
111134
endif()
112135

@@ -119,6 +142,15 @@ endif()
119142
# Build tests
120143
if(SHARKFUSER_BUILD_TESTS)
121144
message(STATUS "Building SharkFuser tests")
145+
146+
# Require Python 3.8+ for lit tests
147+
find_package(Python3 3.8 REQUIRED COMPONENTS Interpreter)
148+
149+
# Grab lit from IREE LLVM. We could also look into using a python pip
150+
# dependency.
151+
set(LLVM_EXTERNAL_LIT "${LLVM_SOURCE_DIR}/utils/lit/lit.py")
152+
message(STATUS "Using LIT from IREE LLVM: ${LLVM_EXTERNAL_LIT}")
153+
122154
add_subdirectory(tests)
123155
enable_testing()
124156
endif()

sharkfuser/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ A side note on naming: 'SharkFuser' is the name of the project (may change as th
1111
## Developer Guide:
1212

1313
### Build and test (debug build):
14+
15+
**Python Requirements:** [`lit`](https://llvm.org/docs/CommandGuide/lit.html)
16+
tests require Python. No external Python dependencies are needed - you can use
17+
your system Python or create a virtual environment.
18+
1419
```shell
1520
cmake -GNinja -S. -Bbuild \
1621
-DCMAKE_C_COMPILER=clang \
1722
-DCMAKE_CXX_COMPILER=clang++ \
1823
-DCMAKE_LINKER_TYPE=LLD \
24+
-DPython3_EXECUTABLE=$(which python3) \
1925
-DSHARKFUSER_DEBUG_BUILD=ON
2026
cmake --build build --target all
2127
ctest --test-dir build
@@ -37,6 +43,7 @@ To generate code coverage metrics:
3743
cmake -GNinja -S. -Bbuild \
3844
-DCMAKE_C_COMPILER=gcc \
3945
-DCMAKE_CXX_COMPILER=g++ \
46+
-DPython3_EXECUTABLE=$(which python3) \
4047
-DSHARKFUSER_CODE_COVERAGE=ON
4148
cmake --build build --target all
4249
ctest --test-dir build -T test -T coverage

sharkfuser/build_tools/cmake/CTestMacros.cmake

Lines changed: 151 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,21 @@
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

77

8-
function(_add_sharkfuser_target)
8+
# Creates an executable target for use in a test.
9+
#
10+
# NAME
11+
# The name of the executable target to create (required)
12+
#
13+
# SRCS
14+
# Source files to compile into the executable (required)
15+
#
16+
# DEPS
17+
# Additional library dependencies beyond the standard ones
18+
# (libfusili and Catch2::Catch2WithMain are always linked)
19+
#
20+
# BIN_SUBDIR
21+
# Subdirectory under build/bin/ where the executable will be placed
22+
function(_add_sharkfuser_executable_for_test)
923
cmake_parse_arguments(
1024
_RULE # prefix
1125
"" # options
@@ -29,6 +43,33 @@ function(_add_sharkfuser_target)
2943
target_link_options(${_RULE_NAME} PRIVATE -coverage)
3044
endif()
3145

46+
# Place executable in the build/bin sub-directory
47+
set_target_properties(
48+
${_RULE_NAME} PROPERTIES
49+
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${_RULE_BIN_SUBDIR}
50+
)
51+
endfunction()
52+
53+
54+
# Creates an executable target + test.
55+
function(_add_sharkfuser_ctest_target)
56+
cmake_parse_arguments(
57+
_RULE # prefix
58+
"" # options
59+
"NAME;BIN_SUBDIR" # one value keywords
60+
"SRCS;DEPS" # multi-value keywords
61+
${ARGN} # extra arguments
62+
)
63+
64+
# Create the target first
65+
_add_sharkfuser_executable_for_test(
66+
NAME ${_RULE_NAME}
67+
SRCS ${_RULE_SRCS}
68+
DEPS ${_RULE_DEPS}
69+
BIN_SUBDIR ${_RULE_BIN_SUBDIR}
70+
)
71+
72+
# Add the test
3273
add_test(NAME ${_RULE_NAME} COMMAND ${_RULE_NAME})
3374

3475
# Set logging environment variables
@@ -38,16 +79,25 @@ function(_add_sharkfuser_target)
3879
ENVIRONMENT "FUSILI_LOG_INFO=1;FUSILI_LOG_FILE=stdout"
3980
)
4081
endif()
41-
42-
# Place executable in the build/bin sub-directory
43-
set_target_properties(
44-
${_RULE_NAME} PROPERTIES
45-
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${_RULE_BIN_SUBDIR}
46-
)
4782
endfunction()
4883

4984

85+
# Creates a sharkfuser test.
86+
#
87+
# NAME
88+
# The name of the executable target to create (required)
89+
#
90+
# SRCS
91+
# Source files to compile into the executable (required)
92+
#
93+
# DEPS
94+
# Additional library dependencies beyond the standard ones
95+
# (libfusili and Catch2::Catch2WithMain are always linked)
5096
function(add_sharkfuser_test)
97+
if(NOT SHARKFUSER_BUILD_TESTS)
98+
return()
99+
endif()
100+
51101
cmake_parse_arguments(
52102
_RULE
53103
""
@@ -56,11 +106,7 @@ function(add_sharkfuser_test)
56106
${ARGN}
57107
)
58108

59-
if(NOT SHARKFUSER_BUILD_TESTS)
60-
return()
61-
endif()
62-
63-
_add_sharkfuser_target(
109+
_add_sharkfuser_ctest_target(
64110
NAME ${_RULE_NAME}
65111
SRCS ${_RULE_SRCS}
66112
DEPS ${_RULE_DEPS}
@@ -69,7 +115,22 @@ function(add_sharkfuser_test)
69115
endfunction()
70116

71117

118+
# Creates a sharkfuser sample.
119+
#
120+
# NAME
121+
# The name of the executable target to create (required)
122+
#
123+
# SRCS
124+
# Source files to compile into the executable (required)
125+
#
126+
# DEPS
127+
# Additional library dependencies beyond the standard ones
128+
# (libfusili and Catch2::Catch2WithMain are always linked)
72129
function(add_sharkfuser_sample)
130+
if(NOT SHARKFUSER_BUILD_SAMPLES)
131+
return()
132+
endif()
133+
73134
cmake_parse_arguments(
74135
_RULE
75136
""
@@ -78,14 +139,87 @@ function(add_sharkfuser_sample)
78139
${ARGN}
79140
)
80141

81-
if(NOT SHARKFUSER_BUILD_SAMPLES)
82-
return()
83-
endif()
84-
85-
_add_sharkfuser_target(
142+
_add_sharkfuser_ctest_target(
86143
NAME ${_RULE_NAME}
87144
SRCS ${_RULE_SRCS}
88145
DEPS ${_RULE_DEPS}
89146
BIN_SUBDIR samples
90147
)
91148
endfunction()
149+
150+
151+
# Creates a lit test that compiles a source file and runs lit on it.
152+
#
153+
# add_sharkfuser_lit_test(
154+
# SRC <source-file>
155+
# [TOOLS <tool1> <tool2> ...]
156+
# [DEPS <dep1> <dep2> ...]
157+
# )
158+
#
159+
# SRC
160+
# The source file to compile and test (required)
161+
#
162+
# TOOLS
163+
# External tools needed for the test (e.g., FileCheck)
164+
#
165+
# DEPS
166+
# Library dependencies for the compiled executable
167+
function(add_sharkfuser_lit_test)
168+
if(NOT SHARKFUSER_BUILD_TESTS)
169+
return()
170+
endif()
171+
172+
cmake_parse_arguments(
173+
_RULE # prefix
174+
"" # options
175+
"SRC" # one value keywords
176+
"TOOLS;DEPS" # multi-value keywords
177+
${ARGN}
178+
)
179+
if(NOT _RULE_SRC)
180+
message(FATAL_ERROR "add_sharkfuser_lit_test: SRC parameter is required")
181+
endif()
182+
183+
get_filename_component(_ABSOLUTE_RULE_SRC ${_RULE_SRC} ABSOLUTE)
184+
get_filename_component(_TEST_NAME ${_RULE_SRC} NAME_WE)
185+
186+
# The executable who's output is being lit tested.
187+
_add_sharkfuser_executable_for_test(
188+
NAME ${_TEST_NAME}
189+
SRCS ${_RULE_SRC}
190+
DEPS ${_RULE_DEPS}
191+
BIN_SUBDIR lit
192+
)
193+
194+
# Pass lit locations of tools in build directory through `--path` arguments.
195+
set(_LIT_PATH_ARGS
196+
"--path" "$<TARGET_FILE_DIR:${_TEST_NAME}>" # include test itself
197+
"--path" "$<TARGET_FILE_DIR:FileCheck>" # include FileCheck by default
198+
)
199+
foreach(_TOOL IN LISTS _RULE_TOOLS)
200+
list(APPEND _LIT_PATH_ARGS "--path" "$<TARGET_FILE_DIR:${_TOOL}>")
201+
endforeach()
202+
203+
add_test(
204+
NAME
205+
${_TEST_NAME}
206+
COMMAND
207+
"${Python3_EXECUTABLE}"
208+
"${LLVM_EXTERNAL_LIT}"
209+
"${_ABSOLUTE_RULE_SRC}"
210+
${_LIT_PATH_ARGS}
211+
# lit config sets the "%test_exe" substitution based on this param.
212+
"--param" "TEST_EXE=$<TARGET_FILE:${_TEST_NAME}>"
213+
# Ensures lit prints a (more) useful error message on failure.
214+
"--verbose"
215+
)
216+
217+
# Apparently this flag helps FileCheck spit out nicer error messages.
218+
set_tests_properties(${_TEST_NAME} PROPERTIES ENVIRONMENT
219+
"FILECHECK_OPTS=--enable-var-scope")
220+
221+
# Dependencies for the test.
222+
if(_RULE_TOOLS)
223+
set_tests_properties(${_TEST_NAME} PROPERTIES DEPENDS "${_RULE_TOOLS}")
224+
endif()
225+
endfunction()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
if(NOT DEFINED SHARKFUSER_IREE_SOURCE_DIR)
2+
message(FATAL_ERROR "SHARKFUSER_IREE_SOURCE_DIR must be defined")
3+
endif()
4+
5+
set(THIRD_PARTY_DIR "${SHARKFUSER_IREE_SOURCE_DIR}/third_party")
6+
7+
# Find all .gcda files
8+
file(GLOB_RECURSE GCDA_FILES "${THIRD_PARTY_DIR}/*.gcda")
9+
10+
# Find all .gcno files
11+
file(GLOB_RECURSE GCNO_FILES "${THIRD_PARTY_DIR}/*.gcno")
12+
13+
# Combine the lists
14+
set(CODECOV_FILES ${GCDA_FILES} ${GCNO_FILES})
15+
16+
message(STATUS "CODECOV_FILES: ${CODECOV_FILES}")
17+
18+
# Remove files
19+
if(CODECOV_FILES)
20+
file(REMOVE ${CODECOV_FILES})
21+
else()
22+
message(STATUS "No .gcda/.gcno files found.")
23+
endif()

0 commit comments

Comments
 (0)