Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aknezevic/ci2 #3

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ RUN echo "Building $PROJECT_NAME at $GIT_SHA"
RUN mkdir -p $BUILD_DIR && \
mkdir -p $TTMLIR_TOOLCHAIN_DIR

# Clone tt-mlir
RUN git clone [email protected]:tenstorrent/tt-mlir.git $BUILD_DIR/$PROJECT_NAME && \
cd $BUILD_DIR/$PROJECT_NAME && \
git checkout $GIT_SHA
# Copy the project from host, cloned in build-image.yml
COPY . $BUILD_DIR/$PROJECT_NAME

# Build the toolchain
WORKDIR $BUILD_DIR/$PROJECT_NAME
RUN source env/activate && \
RUN cmake -B toolchain -DTOOLCHAIN=ON third_party/ && \
cd third_party/tt-mlir/src/tt-mlir/ && \
source env/activate && \
cmake -B env/build env && \
cmake --build env/build

Expand Down
146 changes: 146 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: Build and Test

on:
workflow_dispatch:
workflow_call:

jobs:
build-ttxla:

timeout-minutes: 120
strategy:
fail-fast: false

name: Build tt-xla
runs-on: ubuntu-latest

container:
image: ghcr.io/${{ github.repository }}/tt-mlir-ci-ubuntu-22-04:latest #TODO update this to the correct image
options: --user root

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
lfs: true

- name: Set reusable strings
id: strings
shell: bash
run: |
echo "work-dir=$(pwd)" >> "$GITHUB_OUTPUT"
echo "build-output-dir=$(pwd)/build" >> "$GITHUB_OUTPUT"
echo "install-output-dir=$(pwd)/install" >> "$GITHUB_OUTPUT"

- name: Git safe dir
run: git config --global --add safe.directory ${{ steps.strings.outputs.work-dir }}


# Build project

- name: Configure CMake
shell: bash
run: |
source venv/activate
cmake -G Ninja \
-B ${{ steps.strings.outputs.build-output-dir }}
-S ${{ steps.strings.outputs.work-dir }}

- name: Build
shell: bash
run: |
source venv/activate
cmake --build ${{ steps.strings.outputs.build-output-dir }}



# This is needed to preserve file permissions
# https://github.com/actions/upload-artifact?tab=readme-ov-file#permission-loss
- name: 'Tar install directory'
shell: bash
working-directory: ${{ steps.strings.outputs.install-output-dir }}
run: tar cvf artifact.tar .

- name: Upload install folder to archive
uses: actions/upload-artifact@v4
with:
name: install-artifacts
path: ${{ steps.strings.outputs.install-output-dir }}/artifact.tar

- name: Get the latest tag
shell: bash
run: |
latest_tag=$(git describe --tags --abbrev=0)
latest_tag=${latest_tag#v}
echo "latest_tag=$latest_tag" >> $GITHUB_ENV
commit_count=$(git rev-list ${{ env.latest_tag }}..HEAD --count)
echo "commit_count=$commit_count" >> $GITHUB_ENV
version="${{ env.latest_tag }}.${{ env.commit_count }}"
echo "version=$version" >> $GITHUB_ENV
echo $version


# Run tests on TT hardware

run-tests:

timeout-minutes: 30
needs: build-ttxla
strategy:
fail-fast: false
matrix:
build: [
{runs-on: n150, name: "run"},
{runs-on: n300, name: "run"},
]

runs-on:
- in-service
- ${{ matrix.build.runs-on }}

container:
image: ghcr.io/${{ github.repository }}/tt-mlir-ci-ubuntu-22-04:latest
options: --user root --device /dev/tenstorrent/0
volumes:
- /dev/hugepages:/dev/hugepages
- /dev/hugepages-1G:/dev/hugepages-1G
- /etc/udev/rules.d:/etc/udev/rules.d
- /lib/modules:/lib/modules
- /opt/tt_metal_infra/provisioning/provisioning_env:/opt/tt_metal_infra/provisioning/provisioning_env

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set reusable strings
id: strings
shell: bash
run: |
echo "work-dir=$(pwd)" >> "$GITHUB_OUTPUT"
echo "build-output-dir=$(pwd)/build" >> "$GITHUB_OUTPUT"
echo "install-output-dir=$(pwd)/install" >> "$GITHUB_OUTPUT"

- name: Git safe dir
run: git config --global --add safe.directory ${{ steps.strings.outputs.work-dir }}

- name: Use build artifacts
uses: actions/download-artifact@v4
with:
name: install-artifacts
path: ${{ steps.strings.outputs.install-output-dir }}

# This is needed to preserve file permissions
# https://github.com/actions/upload-artifact?tab=readme-ov-file#permission-loss
- name: 'Untar install directory'
shell: bash
working-directory: ${{ steps.strings.outputs.install-output-dir }}
run: tar xvf artifact.tar


- name: Run tests
shell: bash
run: |
source venv/activate
pytest -v tests/
19 changes: 3 additions & 16 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:

- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
lfs: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand All @@ -37,7 +40,6 @@ jobs:
- name: Build and export base Docker image
uses: docker/build-push-action@v6
with:
context: .github
file: .github/Dockerfile.base
push: true
build-args: |
Expand All @@ -48,32 +50,18 @@ jobs:
- name: Build and export CI Docker image
uses: docker/build-push-action@v6
with:
context: .github
file: .github/Dockerfile.ci
push: true
build-args: |
GIT_SHA=${{ github.sha }}
tags: |
${{ env.CI_IMAGE_NAME}}:${{ github.sha }}

- name: Build and export IRD Docker image
uses: docker/build-push-action@v6
with:
context: .github
file: .github/Dockerfile.ird
push: true
build-args: |
GIT_SHA=${{ github.sha }}
FROM_IMAGE=ci
tags: |
${{ env.IRD_IMAGE_NAME}}:${{ github.sha }}

# Tag images as latest

- name: Build and push base Docker image
uses: docker/build-push-action@v6
with:
context: .github
file: .github/Dockerfile.base
push: true
build-args: |
Expand All @@ -84,7 +72,6 @@ jobs:
- name: Build and push CI Docker image
uses: docker/build-push-action@v6
with:
context: .github
file: .github/Dockerfile.ci
push: true
build-args: |
Expand Down
112 changes: 66 additions & 46 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,50 +1,70 @@
include(ExternalProject)
add_subdirectory(pjrt_c_api)
set(TT_MLIR_VERSION "f955a08e8836e41a3333ca20a3bbe193ce91b2a0")
set(LOGURU_VERSION "4adaa185883e3c04da25913579c451d3c32cfac1")

set(TTMLIR_LIB_DIR ${PROJECT_SOURCE_DIR}/third_party/tt-mlir/src/tt-mlir-build/lib/SharedLib)
ExternalProject_Add(
tt-mlir
PREFIX ${TTPJRT_SOURCE_DIR}/third_party/tt-mlir
CMAKE_GENERATOR Ninja
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER=clang-17
-DCMAKE_CXX_COMPILER=clang++-17
-DTT_RUNTIME_ENABLE_TTNN=ON
-DTTMLIR_ENABLE_STABLEHLO=ON
-DTTMLIR_ENABLE_RUNTIME=ON
GIT_REPOSITORY [email protected]:tenstorrent/tt-mlir.git
GIT_TAG f955a08e8836e41a3333ca20a3bbe193ce91b2a0
GIT_PROGRESS ON
INSTALL_COMMAND ""
)
if (TOOLCHAIN STREQUAL "ON")
cmake_minimum_required(VERSION 3.20)
project(ttmlir-toolchain LANGUAGES CXX C)
execute_process(
COMMAND git clone --recursive https://github.com/tenstorrent/tt-mlir.git ${PROJECT_SOURCE_DIR}/tt-mlir/src/tt-mlir
RESULT_VARIABLE result1
OUTPUT_VARIABLE output1
ERROR_VARIABLE error_output1
)
if (NOT ${result1} EQUAL 0)
message(FATAL_ERROR "Failed to clone tt-mlir: ${error_output1}")
endif()
execute_process(
COMMAND /bin/bash -c "cd ${PROJECT_SOURCE_DIR}/tt-mlir/src/tt-mlir && git checkout ${TT_MLIR_VERSION}"
)
else()
include(ExternalProject)
add_subdirectory(pjrt_c_api)
set(TTMLIR_LIB_DIR ${PROJECT_SOURCE_DIR}/third_party/tt-mlir/src/tt-mlir-build/lib/SharedLib)
ExternalProject_Add(
tt-mlir
PREFIX ${TTPJRT_SOURCE_DIR}/third_party/tt-mlir
CMAKE_GENERATOR Ninja
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER=clang-17
-DCMAKE_CXX_COMPILER=clang++-17
-DTT_RUNTIME_ENABLE_TTNN=ON
-DTTMLIR_ENABLE_STABLEHLO=ON
-DTTMLIR_ENABLE_RUNTIME=ON
GIT_REPOSITORY [email protected]:tenstorrent/tt-mlir.git
GIT_TAG ${TT_MLIR_VERSION}
GIT_PROGRESS ON
INSTALL_COMMAND ""
)

set_target_properties(tt-mlir PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(tt-mlir PROPERTIES EXCLUDE_FROM_ALL TRUE)

# Link to all TTMLIR libraries in ${TTMLIR_INSTALL_DIR}/install/lib
set(TTMLIR_LIB_DIR ${TTMLIR_LIB_DIR} PARENT_SCOPE)
message(STATUS "Linking to TTMLIR libraries in ${TTMLIR_LIB_DIR}")
file(GLOB TTMLIR_LIBRARIES "${TTMLIR_LIB_DIR}/*.so")
foreach(TTMLIR_LIBRARY ${TTMLIR_LIBRARIES})
get_filename_component(lib_name ${TTMLIR_LIBRARY} NAME_WE)
string(REPLACE "lib" "" lib_name ${lib_name}) # Remove the "lib" prefix if it exists
add_library(${lib_name} SHARED IMPORTED GLOBAL)
set_target_properties(${lib_name} PROPERTIES EXCLUDE_FROM_ALL TRUE IMPORTED_LOCATION ${TTMLIR_LIBRARY})
add_dependencies(${lib_name} tt-mlir)
endforeach()
# Link to all TTMLIR libraries in ${TTMLIR_INSTALL_DIR}/install/lib
set(TTMLIR_LIB_DIR ${TTMLIR_LIB_DIR} PARENT_SCOPE)
message(STATUS "Linking to TTMLIR libraries in ${TTMLIR_LIB_DIR}")
file(GLOB TTMLIR_LIBRARIES "${TTMLIR_LIB_DIR}/*.so")
foreach(TTMLIR_LIBRARY ${TTMLIR_LIBRARIES})
get_filename_component(lib_name ${TTMLIR_LIBRARY} NAME_WE)
string(REPLACE "lib" "" lib_name ${lib_name}) # Remove the "lib" prefix if it exists
add_library(${lib_name} SHARED IMPORTED GLOBAL)
set_target_properties(${lib_name} PROPERTIES EXCLUDE_FROM_ALL TRUE IMPORTED_LOCATION ${TTMLIR_LIBRARY})
add_dependencies(${lib_name} tt-mlir)
endforeach()

set(FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wno-undef -Wno-unsafe-buffer-usage -Wno-disabled-macro-expansion")
ExternalProject_Add(
loguru
PREFIX ${TTPJRT_SOURCE_DIR}/third_party/loguru
CMAKE_GENERATOR Ninja
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER=clang-17
-DCMAKE_CXX_COMPILER=clang++-17
-DCMAKE_CXX_FLAGS=${FLAGS}
-DCMAKE_INSTALL_PREFIX=${TTPJRT_SOURCE_DIR}/third_party/loguru/src/loguru-install
GIT_REPOSITORY [email protected]:emilk/loguru.git
GIT_TAG 4adaa185883e3c04da25913579c451d3c32cfac1
GIT_PROGRESS ON
)
set(FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wno-undef -Wno-unsafe-buffer-usage -Wno-disabled-macro-expansion")
ExternalProject_Add(
loguru
PREFIX ${TTPJRT_SOURCE_DIR}/third_party/loguru
CMAKE_GENERATOR Ninja
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER=clang-17
-DCMAKE_CXX_COMPILER=clang++-17
-DCMAKE_CXX_FLAGS=${FLAGS}
-DCMAKE_INSTALL_PREFIX=${TTPJRT_SOURCE_DIR}/third_party/loguru/src/loguru-install
GIT_REPOSITORY [email protected]:emilk/loguru.git
GIT_TAG ${LOGURU_VERSION}
GIT_PROGRESS ON
)

endif()