From f4e00a19fbc1f299b3e6e21c0dc0c2fb94397fea Mon Sep 17 00:00:00 2001 From: Aleks Knezevic Date: Mon, 16 Sep 2024 16:06:48 +0000 Subject: [PATCH] Added ci docker image --- .github/Dockerfile.base | 53 +++++++++++++++++ .github/Dockerfile.ci | 65 +++++++++++++++++++++ .github/workflows/build-image.yml | 94 +++++++++++++++++++++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 .github/Dockerfile.base create mode 100644 .github/Dockerfile.ci create mode 100644 .github/workflows/build-image.yml diff --git a/.github/Dockerfile.base b/.github/Dockerfile.base new file mode 100644 index 0000000..c0a01e6 --- /dev/null +++ b/.github/Dockerfile.base @@ -0,0 +1,53 @@ +FROM ubuntu:22.04 +SHELL ["/bin/bash", "-c"] + +# Set environment variables +ENV DEBIAN_FRONTEND=noninteractive + +# Install dependencies +RUN apt-get update && apt-get install -y \ + software-properties-common \ + build-essential \ + python3-dev \ + python3-venv \ + python3-pip \ + git \ + git-lfs \ + libhwloc-dev \ + pandoc \ + libtbb-dev \ + libcapstone-dev \ + pkg-config \ + linux-tools-generic \ + ninja-build \ + wget \ + libgtest-dev \ + cmake \ + ccache \ + doxygen \ + graphviz \ + patchelf \ + libyaml-cpp-dev \ + libboost-all-dev + +# Install clang 17 +RUN wget https://apt.llvm.org/llvm.sh && \ + chmod u+x llvm.sh && \ + ./llvm.sh 17 && \ + apt install -y libc++-17-dev libc++abi-17-dev && \ + ln -s /usr/bin/clang-17 /usr/bin/clang && \ + ln -s /usr/bin/clang++-17 /usr/bin/clang++ + +# Install python packages +RUN pip install cmake + +# Install Googletest +RUN git clone https://github.com/google/googletest.git -b release-1.12.1 && \ + cd googletest && \ + mkdir build && \ + cd build && \ + cmake .. -DBUILD_GMOCK=OFF && \ + make && \ + make install && \ + cd ../.. && \ + rm -rf googletest diff --git a/.github/Dockerfile.ci b/.github/Dockerfile.ci new file mode 100644 index 0000000..801a85d --- /dev/null +++ b/.github/Dockerfile.ci @@ -0,0 +1,65 @@ +ARG GIT_SHA +ARG FROM_TAG=${GIT_SHA:-latest} + +FROM ghcr.io/tenstorrent/tt-xla/tt-xla-base-ubuntu-22-04:${FROM_TAG} AS ci-build +SHELL ["/bin/bash", "-c"] + +# Create a directory for the build and toolchain +ARG GIT_SHA +ENV PROJECT_NAME=tt-xla +ENV BUILD_DIR=/home/build +ENV TTMLIR_TOOLCHAIN_DIR=/opt/ttmlir-toolchain + +RUN echo "Building $PROJECT_NAME at $GIT_SHA" + +RUN mkdir -p $BUILD_DIR && \ + mkdir -p $TTMLIR_TOOLCHAIN_DIR + +# Clone tt-mlir +RUN git clone git@github.com:tenstorrent/tt-mlir.git $BUILD_DIR/$PROJECT_NAME && \ + cd $BUILD_DIR/$PROJECT_NAME && \ + git checkout $GIT_SHA + +# Build the toolchain +WORKDIR $BUILD_DIR/$PROJECT_NAME +RUN source env/activate && \ + cmake -B env/build env && \ + cmake --build env/build + +# Self-test + +# Build project to test the container +RUN source env/activate && \ + cmake -G Ninja \ + -B build \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DTTMLIR_ENABLE_RUNTIME=ON \ + -DTTMLIR_ENABLE_RUNTIME_TESTS=ON \ + -DTTMLIR_ENABLE_STABLEHLO=ON + +RUN source env/activate && \ + cmake --build build --config Release + +RUN source env/activate && \ + cmake --build build -- ttrt + +# Run clang-tidy +RUN source env/activate && \ + cmake --build build -- clang-tidy + +# Run the tests +RUN source env/activate && \ + cmake --build build -- check-ttmlir + +# Final stage +FROM ghcr.io/tenstorrent/tt-xla/tt-xla-base-ubuntu-22-04:${FROM_TAG} AS ci + +# Copy the TTMLIR_TOOLCHAIN_DIR from the previous stage +ENV TTMLIR_TOOLCHAIN_DIR=/opt/ttmlir-toolchain +RUN echo "Copying from ci-build stage $TTMLIR_TOOLCHAIN_DIR" +COPY --from=ci-build $TTMLIR_TOOLCHAIN_DIR $TTMLIR_TOOLCHAIN_DIR + +RUN du -h --max-depth=2 $TTMLIR_TOOLCHAIN_DIR \ No newline at end of file diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml new file mode 100644 index 0000000..d109d33 --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,94 @@ +name: Build and Publish Docker Image + +on: + workflow_dispatch: + workflow_call: + +jobs: + build: + + runs-on: + - in-service + - builder + + env: + BASE_IMAGE_NAME: ghcr.io/${{ github.repository }}/tt-xla-base-ubuntu-22-04 + CI_IMAGE_NAME: ghcr.io/${{ github.repository }}/tt-xla-ci-ubuntu-22-04 + + steps: + + - name: Fix permissions + run: sudo chmod 777 -R $GITHUB_WORKSPACE + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Build images + + - name: Build and export base Docker image + uses: docker/build-push-action@v6 + with: + context: .github + file: .github/Dockerfile.base + push: true + build-args: | + GIT_SHA=${{ github.sha }} + tags: | + ${{ env.BASE_IMAGE_NAME}}:${{ github.sha }} + + - 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: | + GIT_SHA=${{ github.sha }} + tags: | + ${{ env.BASE_IMAGE_NAME}}:latest + + - name: Build and push 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}}:latest