Skip to content

Commit

Permalink
#14688 Scan the repo with clang-tidy as part of post-commit (#15071)
Browse files Browse the repository at this point in the history
### Ticket
#14688 

### Problem description
To leverage clang-tidy we need assurance that the entire repo conforms
to the specified clang-tidy config.

### What's changed
Added a scan in post-commit and fixed up the repo as needed for the scan
to come up clean.
Now we have a baseline to work from.

### Checklist
- [x] Post commit CI passes
https://github.com/tenstorrent/tt-metal/actions/runs/11853360350
- [ ] Blackhole Post commit (if applicable)
- [ ] Model regression CI testing passes (if applicable)
- [ ] Device performance regression CI testing passes (if applicable)
- [x] New/Existing tests provide coverage for changes
  • Loading branch information
afuller-TT authored Nov 15, 2024
1 parent 282e7e2 commit c9b9db0
Show file tree
Hide file tree
Showing 10 changed files with 372 additions and 32 deletions.
3 changes: 1 addition & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Checks: >
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-integer-division,
-bugprone-macro-parentheses,
-bugprone-misplaced-widening-cast,
-bugprone-narrowing-conversions,
-bugprone-string-integer-assignment,
-bugprone-suspicious-include,
Expand Down Expand Up @@ -98,7 +99,6 @@ Checks: >
-hicpp-named-parameter,
-hicpp-no-array-decay,
-hicpp-no-malloc,
-hicpp-no-malloc,
-hicpp-noexcept-move,
-hicpp-signed-bitwise,
-hicpp-special-member-functions,
Expand Down Expand Up @@ -154,7 +154,6 @@ Checks: >
-performance-inefficient-string-concatenation,
-performance-inefficient-vector-operation,
-performance-move-const-arg,
-performance-move-const-arg,
-performance-move-constructor-init,
-performance-no-int-to-ptr,
-performance-noexcept-move-constructor,
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/all-post-commit-workflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ jobs:
with:
arch: ${{ matrix.test-group.arch }}
runner-label: ${{ matrix.test-group.runner-label }}
code-analysis:
needs: build-docker-image-2204
uses: ./.github/workflows/code-analysis.yaml
secrets: inherit
with:
os: ubuntu-22.04-amd64
tt-train-cpp-unit-tests:
needs: build-artifact
secrets: inherit
Expand Down
105 changes: 105 additions & 0 deletions .github/workflows/code-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: "Code analysis"

on:
workflow_call:
inputs:
os:
required: false
type: string
default: "ubuntu-22.04-amd64"
workflow_dispatch:
inputs:
os:
required: false
type: string
default: "ubuntu-22.04-amd64"

jobs:
build-docker-image:
uses: ./.github/workflows/build-docker-artifact.yaml
secrets: inherit
with:
os: ${{ inputs.os }}


clang-tidy:
needs: build-docker-image
env:
ARCH_NAME: wormhole_b0
runs-on:
- build
- in-service
steps:
- name: Verify ccache availability
shell: bash
run: |
if [ ! -d "/mnt/MLPerf/ccache" ]; then
echo "::error title=ccache-mlperf-not-mounted::NFS drive is not mounted; build machine not properly provisioned."
exit 1
fi
if [ ! -d "$HOME/.ccache-ci" ]; then
echo "::error title=ccache-not-provisioned::Ccache is not properly provisioned."
exit 1
fi
- uses: tenstorrent-metal/metal-workflows/.github/actions/[email protected]
- name: Set up dynamic env vars for build
run: |
echo "TT_METAL_HOME=$(pwd)" >> $GITHUB_ENV
echo "RUNNER_UID=$(id -u)" >> $GITHUB_ENV
echo "RUNNER_GID=$(id -g)" >> $GITHUB_ENV
- name: Update submodules
run: |
git submodule update --init --recursive
- name: Generate docker tag
id: generate-docker-tag
uses: ./.github/actions/generate-docker-tag
with:
image: ${{ inputs.os }}
- name: Docker login
uses: docker/login-action@v3
with:
registry: https://ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull docker image
run: docker pull ${{ env.TT_METAL_DOCKER_IMAGE_TAG }}
- name: Analyze code with clang-tidy
uses: addnab/docker-run-action@v3
with:
image: ${{ env.TT_METAL_DOCKER_IMAGE_TAG }}
options: |
--rm
--tmpfs /tmp
-u ${{ env.RUNNER_UID }}:${{ env.RUNNER_GID }}
--group-add 1457
-v ${{ github.workspace }}:${{ github.workspace }}
-v /etc/passwd:/etc/passwd:ro
-v /etc/shadow:/etc/shadow:ro
-v /etc/bashrc:/etc/bashrc:ro
-v /home/ubuntu/.ccache-ci:/home/ubuntu/.ccache
-v /mnt/MLPerf/ccache:/mnt/MLPerf/ccache
-e ARCH_NAME=${{ env.ARCH_NAME }}
-e CARGO_HOME=${{ github.workspace }}/.cargo
-w ${{ github.workspace }}
run: |
set -eu # basic shell hygiene
# /tmp is a tmpfs; more efficient than persisted storage
mkdir -p /tmp/ccache
export CCACHE_TEMPDIR=/tmp/ccache
# Zero out the stats so we can see how we did this build
# NOTE: may be inaccurate if we have >1 build runner on the same machine, using the same local cache
ccache -z
cmake --preset clang-tidy
# cmake -B .build/clang-tidy -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CXX_CLANG_TIDY=clang-tidy-17 -DTT_UNITY_BUILDS=FALSE -DCMAKE_DISABLE_PRECOMPILE_HEADERS=TRUE -DENABLE_CCACHE=TRUE -DTT_METAL_BUILD_TESTS=TRUE -DTTNN_BUILD_TESTS=TRUE -DBUILD_PROGRAMMING_EXAMPLES=TRUE -DBUILD_TT_TRAIN=TRUE
nice -n 19 cmake --build --preset clang-tidy
mkdir out
ccache -s > out/ccache.stats
- name: Publish Ccache summary
run: |
echo '## CCache Summary' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
cat out/ccache.stats >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tt_debug
build
build_*
/python_env/
CMakeUserPresets.json

/llk_out/
/out/
Expand Down
46 changes: 46 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"version": 3,
"configurePresets": [
{
"name": "default",
"displayName": "Default Config",
"description": "Default build of all the code using Ninja",
"generator": "Ninja Multi-Config",
"binaryDir": "${sourceDir}/.build/default",
"cacheVariables": {
"TT_METAL_BUILD_TESTS": {"value": "TRUE"},
"TTNN_BUILD_TESTS": {"value": "TRUE"},
"TT_UMD_BUILD_TESTS": {"value": "TRUE"},
"BUILD_PROGRAMMING_EXAMPLES": {"value": "TRUE"},
"BUILD_TT_TRAIN": {"value": "TRUE"},
"CMAKE_DISABLE_PRECOMPILE_HEADERS": {"value": "TRUE"},
"ENABLE_CCACHE": {"value": "TRUE"},
"TT_UNITY_BUILDS": {"value": "FALSE"}
}
},
{
"name": "clang-tidy",
"inherits": "default",
"description": "Run Clang Tidy",
"binaryDir": "${sourceDir}/.build/clang-tidy",
"cacheVariables": {
"CMAKE_CXX_CLANG_TIDY": {"value": "clang-tidy-17;--warnings-as-errors=*"},
"CMAKE_VERIFY_INTERFACE_HEADER_SETS": {"value": "TRUE"},
"CMAKE_EXPORT_COMPILE_COMMANDS": {"value": "TRUE"}
}
}
],
"buildPresets": [
{
"name": "dev",
"configurePreset": "default",
"configuration": "RelWithDebInfo",
"targets": ["all"]
},
{
"name": "clang-tidy",
"configurePreset": "clang-tidy",
"configuration": "RelWithDebInfo"
}
]
}
1 change: 1 addition & 0 deletions dockerfile/ubuntu-20.04-amd64.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ RUN apt-get -y update \
&& apt-get install -y --no-install-recommends \
libc++-17-dev \
libc++abi-17-dev \
clang-tidy-17 \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p /usr/app
Expand Down
1 change: 1 addition & 0 deletions dockerfile/ubuntu-22.04-amd64.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ RUN apt-get -y update \
&& apt-get install -y --no-install-recommends \
libc++-17-dev \
libc++abi-17-dev \
clang-tidy-17 \
&& rm -rf /var/lib/apt/lists/*

# Setup Env variables to setup Python Virtualenv - Install TT-Metal Python deps
Expand Down
Loading

0 comments on commit c9b9db0

Please sign in to comment.