From f7ffb1212370005300d509f7c36ad869ed373685 Mon Sep 17 00:00:00 2001 From: Johannes Graner Date: Fri, 17 Oct 2025 18:28:38 +0200 Subject: [PATCH] Pre-commit in CI (#3029) * Pre-commit in CI * Specify python version, and install dos2unix for remod * Refactor remod hook to correctly install dependencies * Run pre-commit [ROCm/composable_kernel commit: 8a4cd32d8692c54a3a500ec65d2623c9d27bd7f5] --- .github/workflows/pre-commit.yml | 16 ++++++++++++++++ .pre-commit-config.yaml | 11 +++++++---- example/ck_tile/remod.py | 9 +++++++-- include/ck_tile/ops/gemm.hpp | 3 ++- include/ck_tile/remod.py | 8 ++++++-- script/install_precommit.sh | 3 --- script/remod_for_ck_tile.py | 13 +++++++++++++ script/remod_for_ck_tile.sh | 7 ------- 8 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/pre-commit.yml create mode 100755 script/remod_for_ck_tile.py delete mode 100755 script/remod_for_ck_tile.sh diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000000..16f7e2539c --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,16 @@ +name: pre-commit + +on: + pull_request: + push: + branches: [develop] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + with: + python-version: '3.12' + - uses: pre-commit/action@v3.0.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 03d33757b0..04ebc6b45a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,9 +32,12 @@ repos: language: script types_or: [c++, text] verbose: true - - id: run-remod-if-ck-tile-changed - name: Run remod.py if ck_tile files changed - entry: script/remod_for_ck_tile.sh - language: script + - id: remod-ck-tile + name: Run ck_tile remod.py + entry: python script/remod_for_ck_tile.py + language: python files: '^(include|example)/ck_tile/.*$' + additional_dependencies: + - dos2unix + - clang-format==18.1.3 pass_filenames: false diff --git a/example/ck_tile/remod.py b/example/ck_tile/remod.py index b2ac7c52bf..4fa3a4e430 100644 --- a/example/ck_tile/remod.py +++ b/example/ck_tile/remod.py @@ -1,3 +1,4 @@ +import os import pathlib from pathlib import Path import subprocess @@ -10,8 +11,12 @@ for p in sorted(Path("./").rglob("*")): # formatting for x in all_files: - subprocess.Popen(f"dos2unix -n {str(x)}", shell=True) - cmd = f"clang-format-18 -style=file -i {str(x)}" + subprocess.Popen( + f"python -m dos2unix {str(x)} {str(x)}", + shell=True, + stdout=open(os.devnull, "wb"), + ) + cmd = f"clang-format -style=file -i {str(x)}" # for xp in x.parents: # print(get_file_base(x)) subprocess.Popen(cmd, shell=True) diff --git a/include/ck_tile/ops/gemm.hpp b/include/ck_tile/ops/gemm.hpp index 6b587f81d5..e1026485d7 100644 --- a/include/ck_tile/ops/gemm.hpp +++ b/include/ck_tile/ops/gemm.hpp @@ -33,9 +33,10 @@ #include "ck_tile/ops/gemm/kernel/gemm_multi_abd_kernel.hpp" #include "ck_tile/ops/gemm/kernel/gemm_multi_d_kernel.hpp" #include "ck_tile/ops/gemm/kernel/gemm_tile_partitioner.hpp" -#include "ck_tile/ops/gemm/kernel/streamk_gemm_tile_partitioner.hpp" #include "ck_tile/ops/gemm/kernel/grouped_gemm_kernel.hpp" #include "ck_tile/ops/gemm/kernel/streamk_gemm_kernel.hpp" +#include "ck_tile/ops/gemm/kernel/streamk_gemm_tile_partitioner.hpp" +#include "ck_tile/ops/gemm/kernel/streamk_gemm_tile_partitioner_impl.hpp" #include "ck_tile/ops/gemm/kernel/universal_gemm_kernel.hpp" #include "ck_tile/ops/gemm/pipeline/gemm_pipeline_ag_bg_cr_base.hpp" #include "ck_tile/ops/gemm/pipeline/gemm_pipeline_ag_bg_cr_comp_async.hpp" diff --git a/include/ck_tile/remod.py b/include/ck_tile/remod.py index bd940036bd..a8ff2defe5 100644 --- a/include/ck_tile/remod.py +++ b/include/ck_tile/remod.py @@ -86,8 +86,12 @@ class submodule_t: submodule = submodule_t() # formatting for x in all_files: - subprocess.Popen(f"dos2unix -n {str(x)}", shell=True) - cmd = f"clang-format-18 -style=file -i {str(x)}" + subprocess.Popen( + f"python -m dos2unix {str(x)} {str(x)}", + shell=True, + stdout=open(os.devnull, "wb"), + ) + cmd = f"clang-format -style=file -i {str(x)}" # for xp in x.parents: # print(get_file_base(x)) subprocess.Popen(cmd, shell=True) diff --git a/script/install_precommit.sh b/script/install_precommit.sh index fd1840290e..545dcfa666 100755 --- a/script/install_precommit.sh +++ b/script/install_precommit.sh @@ -13,9 +13,6 @@ echo "I: Creating and activating virtual environment for pre-commit..." python3 -m venv "$(dirname "$0")/../.venv" source "$(dirname "$0")/../.venv/bin/activate" -echo "I: Installing tools required for pre-commit checks..." -run_and_check pip install dos2unix -run_and_check pip install clang-format==18.1.3 echo "I: Installing pre-commit in virtual environment..." run_and_check pip install pre-commit run_and_check pre-commit install diff --git a/script/remod_for_ck_tile.py b/script/remod_for_ck_tile.py new file mode 100755 index 0000000000..7601c9d619 --- /dev/null +++ b/script/remod_for_ck_tile.py @@ -0,0 +1,13 @@ +import os + +root_dir = os.getcwd() +ck_tile_include = root_dir + "/include/ck_tile" +ck_tile_example = root_dir + "/example/ck_tile" + +# Run for include +os.chdir(ck_tile_include) +_ = os.system("python remod.py") + +# Run for example +os.chdir(ck_tile_example) +_ = os.system("python remod.py") diff --git a/script/remod_for_ck_tile.sh b/script/remod_for_ck_tile.sh deleted file mode 100755 index 7b99ec60bd..0000000000 --- a/script/remod_for_ck_tile.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# Copyright © Advanced Micro Devices, Inc., or its affiliates. -# SPDX-License-Identifier: MIT - -# Run remod.py in both required locations -(cd include/ck_tile/ && python3 remod.py) -(cd example/ck_tile/ && python3 remod.py)