Skip to content

Commit

Permalink
Merge branch 'main' into add_tuner
Browse files Browse the repository at this point in the history
  • Loading branch information
RattataKing authored Aug 28, 2024
2 parents 213e6be + ba58e4d commit 654c935
Show file tree
Hide file tree
Showing 66 changed files with 3,361 additions and 614 deletions.
49 changes: 33 additions & 16 deletions .github/workflows/ci_linux_x64-libshortfin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/bash
# Copyright 2024 Advanced Micro Devices, Inc
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
Expand All @@ -22,7 +21,7 @@ permissions:

env:
IREE_REPO_DIR: ${{ github.workspace }}/iree
BUILD_DIR: ${{ github.workspace }}/libshortfin/build
LIBSHORTFIN_DIR: ${{ github.workspace }}/libshortfin/

jobs:
build-and-test:
Expand All @@ -47,16 +46,15 @@ jobs:
repository: iree-org/iree
path: ${{ env.IREE_REPO_DIR }}
submodules: false
depth: 1

- name: Initalize IREE submodules
run : |
cd ${{ env.IREE_REPO_DIR }}
git submodule update --init -- third_party/benchmark
git submodule update --init -- third_party/cpuinfo/
git submodule update --init -- third_party/flatcc
git submodule update --init -- third_party/googletest
git submodule update --init -- third_party/hip-build-deps/
git submodule update --init --depth 1 -- third_party/benchmark
git submodule update --init --depth 1 -- third_party/cpuinfo/
git submodule update --init --depth 1 -- third_party/flatcc
git submodule update --init --depth 1 -- third_party/googletest
git submodule update --init --depth 1 -- third_party/hip-build-deps/
- name: Build IREE runtime
run: |
Expand All @@ -80,16 +78,18 @@ jobs:
- name: Setup Python
uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
with:
python-version: "3.11"
python-version: "3.12"
cache: "pip"
- name: Install Python packages
# TODO: Switch to `pip install -r requirements.txt -e libshortfin/`.
run: pip install nanobind typing_extensions
run: |
pip install nanobind
pip install -r ${{ env.LIBSHORTFIN_DIR }}/requirements-tests.txt
- name: Build libshortfin
- name: Build libshortfin (full)
run: |
mkdir ${{ env.BUILD_DIR }}
cd ${{ env.BUILD_DIR }}
mkdir ${{ env.LIBSHORTFIN_DIR }}/build
cd ${{ env.LIBSHORTFIN_DIR }}/build
cmake -GNinja \
-DCMAKE_C_COMPILER=clang-18 \
-DCMAKE_CXX_COMPILER=clang++-18 \
Expand All @@ -98,8 +98,25 @@ jobs:
-DSHORTFIN_BUILD_PYTHON_BINDINGS=ON \
..
cmake --build . --target all
pip install -v -e .
- name: Test libshortfin (full)
run: |
cd ${{ env.LIBSHORTFIN_DIR }}/build
ctest --timeout 30 --output-on-failure
cd ${{ env.LIBSHORTFIN_DIR }}
pytest -s -v -m "not requires_amd_gpu"
- name: Test libshortfin
- name: Build libshortfin (host-only)
run: |
cd ${{ env.BUILD_DIR }}
cmake --build . --target test
mkdir ${{ env.LIBSHORTFIN_DIR }}/build-host-only
cd ${{ env.LIBSHORTFIN_DIR }}/build-host-only
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 \
..
cmake --build . --target all
170 changes: 170 additions & 0 deletions .github/workflows/ci_linux_x64_asan-libshortfin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# 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: Apache-2.0 WITH LLVM-exception

name: CI - libshortfin - ASan

on:
workflow_dispatch:
pull_request:
push:
branches:
- main
paths:
- '.github/workflows/ci_linux_x64_asan-libshortfin.yml'
- 'libshortfin/**'

permissions:
contents: read

env:
PYENV_ROOT: ${{ github.workspace }}/pyenv
PYENV_REF: 9ecd803bffaffb949fbdd8c70cb086227f6a3202 # v2.4.10
PYTHON_VER: 3.12.3
CACHE_ASAN_VER: 1
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

steps:
- name: Cache Python ASan
id: cache-python-asan
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ${{ env.PYENV_ROOT }}
key: ${{ runner.os }}-python-asan-${{ env.PYENV_REF }}-${{ env.PYTHON_VER }}-v${{ env.CACHE_ASAN_VER }}
lookup-only: 'true'

- name: Install dependencies
if: steps.cache-python-asan.outputs.cache-hit != 'true'
run: |
sudo apt update
sudo apt install clang lld cmake ninja-build
sudo apt install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl git libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
- name: Checkout pyenv
if: steps.cache-python-asan.outputs.cache-hit != 'true'
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
repository: pyenv/pyenv
ref: ${{ env.PYENV_REF }}
path: ${{ env.PYENV_ROOT }}

- name: Install pyenv & Python
if: steps.cache-python-asan.outputs.cache-hit != 'true'
run: |
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
build-and-test:
name: Build and test libshortfin
needs: [setup-python-asan]
runs-on: ubuntu-24.04

steps:
- name: Install dependencies
run: |
sudo apt update
sudo apt install clang lld cmake ninja-build
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
submodules: false

- name: Checkout IREE repo
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
repository: iree-org/iree
path: ${{ env.IREE_SOURCE_DIR }}
submodules: false

- name: Initalize IREE submodules
run : |
cd ${{ env.IREE_SOURCE_DIR }}
git submodule update --init --depth 1 -- third_party/benchmark
git submodule update --init --depth 1 -- third_party/cpuinfo/
git submodule update --init --depth 1 -- third_party/flatcc
git submodule update --init --depth 1 -- third_party/googletest
git submodule update --init --depth 1 -- third_party/hip-build-deps/
- name: Restore Python dependencies cache
id: cache-python-deps-restore
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ${{ env.PYENV_ROOT }}
key: ${{ runner.os }}-python-deps-${{ hashFiles('libshortfin/requirements-tests.txt') }}-v${{ env.CACHE_DEPS_VER }}

- name: Restore Python ASan cache
id: cache-python-asan
if: steps.cache-python-deps-restore.outputs.cache-hit != 'true'
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ${{ env.PYENV_ROOT }}
key: ${{ runner.os }}-python-asan-${{ env.PYENV_REF }}-${{ env.PYTHON_VER }}-v${{ env.CACHE_ASAN_VER }}

- name: Set path
run:
echo "${{ env.PYENV_ROOT }}/bin" >> $GITHUB_PATH

- name: Install Python dependencies
if: steps.cache-python-deps-restore.outputs.cache-hit != 'true'
run: |
eval "$(pyenv init -)"
pip install -r ${{ env.LIBSHORTFIN_DIR }}/requirements-tests.txt
- name: Save Python dependencies cache
if: steps.cache-python-deps-restore.outputs.cache-hit != 'true'
id: cache-python-deps-save
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ${{ env.PYENV_ROOT }}
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
cd ${{ env.LIBSHORTFIN_DIR }}/build
cmake -GNinja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_COMPILER=clang-18 \
-DCMAKE_CXX_COMPILER=clang++-18 \
-DCMAKE_LINKER_TYPE=LLD \
-DSHORTFIN_BUNDLE_DEPS=ON \
-DSHORTFIN_IREE_SOURCE_DIR=${{ env.IREE_SOURCE_DIR }} \
-DSHORTFIN_BUILD_PYTHON_BINDINGS=ON \
-DSHORTFIN_ENABLE_ASAN=ON \
..
cmake --build . --target all
pip install -v -e .
- name: Run ctest
if: ${{ !cancelled() }}
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: |
cd ${{ env.LIBSHORTFIN_DIR }}/build
ctest --timeout 30 --output-on-failure
- name: Run pytest
if: ${{ !cancelled() }}
run: |
eval "$(pyenv init -)"
cd ${{ env.LIBSHORTFIN_DIR }}
pytest -m "not requires_amd_gpu"
7 changes: 6 additions & 1 deletion docs/amdgpu_kernel_optimization_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Author: Jakub Kuderski @kuhar

Date: 2024-06-24

Last Update: 2024-08-14
Last Update: 2024-08-22

## Introduction

Expand Down Expand Up @@ -280,6 +280,11 @@ at once.
A sequence of up to 4 adjacent `global_load_dwordx4` instructions (implicitly)
forms a *clause* that translates to a single data fabric transaction.
> [!TIP]
> To achieve peak L1 bandwidth, make sure that your memory access engages all
> four L1 cache sets. That is, at the level of the workgroup, you should be
> loading 4 cache lines (128 B) that each map to a different cache set.
> [!TIP]
> For data that is 'streamed' and does not need to be cached, consider
> using *non-temporal* loads/stores. This disables coherency and invalidates
Expand Down
29 changes: 28 additions & 1 deletion libshortfin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ project(
VERSION 0.9
LANGUAGES C CXX)

set(SOVERSION 1)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
# https://discourse.cmake.org/t/cmake-3-28-cmake-cxx-compiler-clang-scan-deps-notfound-not-found/9244/3
Expand All @@ -33,8 +35,30 @@ endif()
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)

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

# 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
# than welcome to set flags themselves.
option(SHORTFIN_ENABLE_ASAN "Enable ASAN" OFF)
if(SHORTFIN_ENABLE_ASAN)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)

# Enable more ASAN checks.
add_compile_definitions(IREE_SANITIZER_ADDRESS)
endif()

option(SHORTFIN_SYSTEMS_AMDGPU "Builds for AMD GPU systems" ON)
message(STATUS "libshortfin supported systems:")
if(SHORTFIN_SYSTEMS_AMDGPU)
message(STATUS " - AMD GPU")
add_compile_definitions("SHORTFIN_HAVE_AMDGPU")
endif()
message(STATUS " - Host")

include(FetchContent)

# Includes.
Expand Down Expand Up @@ -92,6 +116,7 @@ if (NOT SHORTFIN_IREE_SOURCE_DIR AND SHORTFIN_BUNDLE_DEPS)
# 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"
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(iree)
if(NOT iree_POPULATED)
Expand All @@ -110,7 +135,9 @@ if(SHORTFIN_IREE_SOURCE_DIR)
set(IREE_HAL_DRIVER_DEFAULTS OFF)
set(IREE_HAL_DRIVER_LOCAL_SYNC ON)
set(IREE_HAL_DRIVER_LOCAL_TASK ON)
set(IREE_HAL_DRIVER_HIP ON)
if(SHORTFIN_SYSTEMS_AMDGPU)
set(IREE_HAL_DRIVER_HIP ON)
endif()
add_subdirectory(${SHORTFIN_IREE_SOURCE_DIR} shortfin_iree SYSTEM EXCLUDE_FROM_ALL)
else()
# Try to find iree using find_package
Expand Down
3 changes: 0 additions & 3 deletions libshortfin/bindings/python/_shortfin/asyncio_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

import asyncio
from collections.abc import Callable
from contextvars import Context
from typing_extensions import Unpack

from . import lib as sfl

Expand Down
Loading

0 comments on commit 654c935

Please sign in to comment.