Skip to content

Commit

Permalink
Merge branch 'main' into llama_fp8
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-garvey authored Sep 4, 2024
2 parents b93aa68 + 547ced4 commit 9becccf
Show file tree
Hide file tree
Showing 224 changed files with 2,213 additions and 816 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/ci_linux_x64-libshortfin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Advanced Micro Devices, Inc
# Copyright 2024 Advanced Micro Devices, Inc.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
Expand Down Expand Up @@ -46,6 +46,7 @@ jobs:
repository: iree-org/iree
path: ${{ env.IREE_REPO_DIR }}
submodules: false
ref: candidate-20240904.1006

- name: Initalize IREE submodules
run : |
Expand Down Expand Up @@ -83,8 +84,8 @@ jobs:
- name: Install Python packages
# TODO: Switch to `pip install -r requirements.txt -e libshortfin/`.
run: |
pip install nanobind
pip install -r ${{ env.LIBSHORTFIN_DIR }}/requirements-tests.txt
pip freeze
- name: Build libshortfin (full)
run: |
Expand All @@ -94,6 +95,7 @@ jobs:
-DCMAKE_C_COMPILER=clang-18 \
-DCMAKE_CXX_COMPILER=clang++-18 \
-DCMAKE_LINKER_TYPE=LLD \
-DSHORTFIN_BUNDLE_DEPS=ON \
-DCMAKE_PREFIX_PATH=${{ env.IREE_REPO_DIR }}/build/lib/cmake/IREE \
-DSHORTFIN_BUILD_PYTHON_BINDINGS=ON \
..
Expand All @@ -111,12 +113,16 @@ jobs:
run: |
mkdir ${{ env.LIBSHORTFIN_DIR }}/build-host-only
cd ${{ env.LIBSHORTFIN_DIR }}/build-host-only
# In this configuration, also build static+dynamic in order to verify
# that path structurally works.
cmake -GNinja \
-DCMAKE_C_COMPILER=clang-18 \
-DCMAKE_CXX_COMPILER=clang++-18 \
-DCMAKE_LINKER_TYPE=LLD \
-DCMAKE_PREFIX_PATH=${{ env.IREE_REPO_DIR }}/build/lib/cmake/IREE \
-DSHORTFIN_BUILD_PYTHON_BINDINGS=ON \
-DSHORTFIN_HAVE_AMDGPU=OFF \
-DSHORTFIN_BUILD_STATIC=ON \
-DSHORTFIN_BUILD_DYNAMIC=ON \
..
cmake --build . --target all
26 changes: 16 additions & 10 deletions .github/workflows/ci_linux_x64_asan-libshortfin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Advanced Micro Devices, Inc
# Copyright 2024 Advanced Micro Devices, Inc.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -23,16 +23,19 @@ env:
PYENV_ROOT: ${{ github.workspace }}/pyenv
PYENV_REF: 9ecd803bffaffb949fbdd8c70cb086227f6a3202 # v2.4.10
PYTHON_VER: 3.12.3
CACHE_ASAN_VER: 1
CACHE_ASAN_VER: 2
CACHE_DEPS_VER: 1
IREE_SOURCE_DIR: ${{ github.workspace }}/iree
LIBSHORTFIN_DIR: ${{ github.workspace }}/libshortfin/


jobs:
setup-python-asan:
name: Setup Python ASan
runs-on: ubuntu-24.04
env:
# The Python build process leaks. Here we just disable leak checking vs
# being more precise.
ASAN_OPTIONS: detect_leaks=0

steps:
- name: Cache Python ASan
Expand Down Expand Up @@ -64,15 +67,18 @@ jobs:
cd ${{ env.PYENV_ROOT }}
src/configure && make -C src
export PATH=${{ env.PYENV_ROOT }}/bin:$PATH && eval "$(pyenv init -)"
CC=clang-18 CXX=clang++-18 LDFLAGS="-lstdc++" PYTHON_CONFIGURE_OPTS="--with-address-sanitizer" pyenv install -v -g ${{ env.PYTHON_VER }}
pyenv global ${{ env.PYTHON_VER }}-debug
CC=clang-18 CXX=clang++-18 LDFLAGS="-lstdc++" PYTHON_CONFIGURE_OPTS="--with-address-sanitizer" pyenv install -v ${{ env.PYTHON_VER }}
pyenv global ${{ env.PYTHON_VER }}
build-and-test:
name: Build and test libshortfin
needs: [setup-python-asan]
runs-on: ubuntu-24.04

env:
# TODO(#151): Don't ignore ODR violations
ASAN_OPTIONS: detect_odr_violation=0
LSAN_OPTIONS: suppressions=${{ github.workspace }}/libshortfin/build_tools/python_lsan_suppressions.txt
steps:
- name: Install dependencies
run: |
Expand All @@ -90,6 +96,7 @@ jobs:
repository: iree-org/iree
path: ${{ env.IREE_SOURCE_DIR }}
submodules: false
ref: candidate-20240904.1006

- name: Initalize IREE submodules
run : |
Expand Down Expand Up @@ -124,6 +131,8 @@ jobs:
run: |
eval "$(pyenv init -)"
pip install -r ${{ env.LIBSHORTFIN_DIR }}/requirements-tests.txt
pip install -r ${{ env.LIBSHORTFIN_DIR }}/requirements-iree-compiler.txt
pip freeze
- name: Save Python dependencies cache
if: steps.cache-python-deps-restore.outputs.cache-hit != 'true'
Expand All @@ -134,9 +143,6 @@ jobs:
key: ${{ steps.cache-python-deps-restore.outputs.cache-primary-key }}

- name: Build libshortfin
env:
# TODO(#151): Don't ignore ODR violations
ASAN_OPTIONS=detect_odr_violation: 0
run: |
eval "$(pyenv init -)"
mkdir ${{ env.LIBSHORTFIN_DIR }}/build
Expand Down Expand Up @@ -167,4 +173,4 @@ jobs:
run: |
eval "$(pyenv init -)"
cd ${{ env.LIBSHORTFIN_DIR }}
pytest -m "not requires_amd_gpu"
pytest -m "not requires_amd_gpu" -s
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright 2024 Advanced Micro Devices, Inc
# Copyright 2024 Advanced Micro Devices, Inc.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
Expand Down
24 changes: 21 additions & 3 deletions libshortfin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Advanced Micro Devices, Inc
# Copyright 2024 Advanced Micro Devices, Inc.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions. See
# https://llvm.org/LICENSE.txt for license information. SPDX-License-Identifier:
Expand All @@ -18,6 +18,8 @@ project(
VERSION 0.9
LANGUAGES C CXX)

include(CMakeDependentOption)

set(SOVERSION 1)

set(CMAKE_C_STANDARD 11)
Expand All @@ -34,10 +36,26 @@ endif()
# build options
option(SHORTFIN_BUILD_PYTHON_BINDINGS "Builds Python Bindings" OFF)
option(SHORTFIN_BUILD_TESTS "Builds C++ tests" ON)
option(SHORTFIN_BUNDLE_DEPS "Download dependencies instead of using system libraries" OFF)
option(SHORTFIN_BUNDLE_DEPS "Download dependencies instead of using system libraries" ON)

set(SHORTFIN_IREE_SOURCE_DIR "" CACHE FILEPATH "Path to IREE source")

# Options for building static or dynamic libraries.
option(SHORTFIN_BUILD_STATIC "Builds static libraries" OFF)
option(SHORTFIN_BUILD_DYNAMIC "Builds dynamic libraries" ON)
cmake_dependent_option(SHORTFIN_LINK_DYNAMIC "Links internal binaries against static libshortfin.a" ON "SHORTFIN_BUILD_DYNAMIC" OFF)
if(NOT SHORTFIN_BUILD_STATIC AND NOT SHORTFIN_BUILD_DYNAMIC)
message(FATAL_ERROR "One of SHORTFIN_BUILD_STATIC or SHORTFIN_BUILD_DYNAMIC must be ON")
endif()
message(STATUS "Shortfin build static = ${SHORTFIN_BUILD_STATIC}, dynamic = ${SHORTFIN_BUILD_DYNAMIC}")
if(SHORTFIN_LINK_DYNAMIC)
message(STATUS "Dynamic linking to shortfin")
set(SHORTFIN_LINK_LIBRARY_NAME "shortfin")
else()
message(STATUS "Static linking to shortfin-static")
set(SHORTFIN_LINK_LIBRARY_NAME "shortfin-static")
endif()

# Enabling ASAN. Note that this will work best if building in a completely
# bundled fashion and with an ASAN rigged CPython. Otherwise, various LD_PRELOAD
# hacks are needed. This is merely a develope convenience: people are more
Expand Down Expand Up @@ -112,7 +130,7 @@ if (NOT SHORTFIN_IREE_SOURCE_DIR AND SHORTFIN_BUNDLE_DEPS)
FetchContent_Declare(
iree
GIT_REPOSITORY https://github.com/iree-org/iree.git
GIT_TAG candidate-20240821.992
GIT_TAG candidate-20240904.1006
# TODO: We shouldn't have to pull googletest when we are not building tests.
# This needs to be fixed with IREE.
GIT_SUBMODULES "third_party/benchmark third_party/cpuinfo third_party/flatcc third_party/hip-build-deps third_party/googletest"
Expand Down
19 changes: 9 additions & 10 deletions libshortfin/bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Advanced Micro Devices, Inc
# Copyright 2024 Advanced Micro Devices, Inc.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions. See
# https://llvm.org/LICENSE.txt for license information. SPDX-License-Identifier:
Expand All @@ -10,12 +10,13 @@
# build. - _shortfin_tracing.lib: Native library with tracing enabled (TODO). -
# Others.

# Detect the installed nanobind package and import it into CMake
execute_process(
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE nanobind_ROOT)
find_package(nanobind CONFIG REQUIRED)
# nanobind
FetchContent_Declare(
nanobind
GIT_REPOSITORY https://github.com/wjakob/nanobind.git
GIT_TAG 9641bb7151f04120013b812789b3ebdfa7e7324f # 2.1.0
)
FetchContent_MakeAvailable(nanobind)

nanobind_add_module(shortfin_python_extension NB_STATIC LTO
array_binding.cc
Expand All @@ -26,9 +27,7 @@ set_target_properties(shortfin_python_extension
PROPERTIES OUTPUT_NAME "_shortfin_default/lib")

target_link_libraries(shortfin_python_extension
# TODO: This should be configurable as to whether we link to the static
# or dynamic version.
PRIVATE shortfin
PRIVATE ${SHORTFIN_LINK_LIBRARY_NAME}
)

nanobind_add_stub(
Expand Down
2 changes: 1 addition & 1 deletion libshortfin/bindings/python/_shortfin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Advanced Micro Devices, Inc
# Copyright 2024 Advanced Micro Devices, Inc.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
Expand Down
2 changes: 1 addition & 1 deletion libshortfin/bindings/python/_shortfin/asyncio_bridge.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Advanced Micro Devices, Inc
# Copyright 2024 Advanced Micro Devices, Inc.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
Expand Down
Loading

0 comments on commit 9becccf

Please sign in to comment.