Unverified Commit 5683e6a6 authored by Xuehai Pan's avatar Xuehai Pan Committed by GitHub
Browse files

[CI][Lint] Retire `format.sh` and add `clang-tidy` to GHA workflow (#1044)

* [Lint] Retire `format.sh` and add `clang-tidy` to GHA workflow

* chore: update clang-tidy settings

* chore: upgrade clang-format and clang-tidy version

* lint: resolve clang-tidy errors

* [Maint] restore format.sh

* [CI] pre-commit autoupdate

* [Minor] fix `command -v` usage
parent 151d9e6b
Checks: > ---
InheritParentConfig: true
ExtraArgs: ['-v']
FormatStyle: file
UseColor: true
WarningsAsErrors: '*'
ExcludeHeaderFilterRegex: '^(3rdparty|tvm)/.*$'
# NOTE: there must be no spaces before the '-', so put the comma last.
Checks: >-
# 1. Retained categories: easier to find bugs/performance issues # 1. Retained categories: easier to find bugs/performance issues
clang-analyzer-*, clang-analyzer-*,
cppcoreguidelines-pro-type-static-cast-downcast, cppcoreguidelines-pro-type-static-cast-downcast,
...@@ -47,7 +56,3 @@ Checks: > ...@@ -47,7 +56,3 @@ Checks: >
-clang-analyzer-deadcode.DeadStores, -clang-analyzer-deadcode.DeadStores,
-clang-analyzer-optin.cplusplus.VirtualCall, -clang-analyzer-optin.cplusplus.VirtualCall,
-clang-diagnostic-tautological-constant-compare, -clang-diagnostic-tautological-constant-compare,
WarningsAsErrors: '*'
HeaderFilterRegex: '^(?!.*(3rdparty|build)).*$'
\ No newline at end of file
...@@ -287,21 +287,39 @@ jobs: ...@@ -287,21 +287,39 @@ jobs:
echo "Clearing uv cache at ${UV_CACHE_DIR} due to failure." echo "Clearing uv cache at ${UV_CACHE_DIR} due to failure."
uv cache clean uv cache clean
- name: Run format check - name: Run clang-tidy
id: format-check id: clang-tidy
if: runner.os == 'Linux'
run: | run: |
mkdir -p build echo "\$ $(command -v clang-tidy) --version" && clang-tidy --version
if [[ -x "$(command -v run-clang-tidy)" ]]; then
echo "Using run-clang-tidy from $(command -v run-clang-tidy)"
CLANG_TIDY=(run-clang-tidy)
else
echo "Downloading run-clang-tidy script"
wget -O run-clang-tidy.py https://raw.githubusercontent.com/llvm/llvm-project/refs/heads/release/21.x/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
CLANG_TIDY=(uv run --no-project --script -- run-clang-tidy.py)
fi
if [[ -x "$(command -v clang-apply-replacements)" ]]; then
echo "Using clang-apply-replacements from $(command -v clang-apply-replacements)"
CLANG_TIDY+=(-fix -clang-apply-replacements-binary="$(command -v clang-apply-replacements)")
else
echo "::warning::clang-apply-replacements not found in PATH, automatic fixing disabled."
fi
# Run cmake to create the build directory with compile_commands.json # Run cmake to create the build directory with compile_commands.json
( cmake -S . -B cmake-build --fresh ${CLANG_TIDY_CMAKE_OPTIONS} # no quotes here
cd build
cmake .. ${CLANG_TIDY_CMAKE_OPTIONS} # no quotes here CXX_FILES=$(find src -type f -iname "*.[ch]pp" -o -iname "*.cc" -o -iname "*.c" -o -iname "*.h")
)
rc=0 rc=0
bash format.sh || rc="$?" "${CLANG_TIDY[@]}" -clang-tidy-binary="$(command -v clang-tidy)" \
rm -rf build -p="cmake-build" ${CXX_FILES} || rc="$?"
if [[ "${rc}" -ne 0 ]]; then rm -rf cmake-build run-clang-tidy.py
echo "::error::Format check failed. Please run 'bash format.sh' locally to fix the issues." if (( rc != 0 )); then
exit 1 echo "::error::clang-tidy found issues (exit code: ${rc}). Please run 'clang-tidy --fix' locally to fix them."
git diff --color=always || true
exit "${rc}"
fi fi
- name: Enable core dump generation (Linux / GitHub-hosted runners) - name: Enable core dump generation (Linux / GitHub-hosted runners)
......
...@@ -97,3 +97,7 @@ tilelang/jit/adapter/cython/.cycache ...@@ -97,3 +97,7 @@ tilelang/jit/adapter/cython/.cycache
# claude # claude
**/.claude **/.claude
# CMake
cmake-build/
cmake-build-*/
...@@ -32,7 +32,7 @@ repos: ...@@ -32,7 +32,7 @@ repos:
args: [--ignore-case] args: [--ignore-case]
files: ^docs/spelling_wordlist\.txt$ files: ^docs/spelling_wordlist\.txt$
- repo: https://github.com/pre-commit/mirrors-clang-format - repo: https://github.com/pre-commit/mirrors-clang-format
rev: v15.0.7 # sync with requirements-lint.txt rev: v21.1.2 # sync with requirements-lint.txt
hooks: hooks:
- id: clang-format - id: clang-format
exclude: | exclude: |
...@@ -41,7 +41,7 @@ repos: ...@@ -41,7 +41,7 @@ repos:
^.+\.json$ ^.+\.json$
) )
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.0 # sync with requirements-lint.txt rev: v0.14.1 # sync with requirements-lint.txt
hooks: hooks:
- id: ruff-check - id: ruff-check
args: [--fix, --exit-non-zero-on-fix] args: [--fix, --exit-non-zero-on-fix]
......
#!/usr/bin/env bash #!/usr/bin/env bash
# Usage: # Usage:
# # Do work and commit your work. # # Do work and commit your work.
#
# # Format files that differ from origin/main. # # Format files that differ from origin/main.
# bash format.sh # bash format.sh
#
# # Commit changed files with message 'Run yapf and ruff' # # Format all files.
# bash format.sh --all
# #
# #
# YAPF + Clang formatter (if installed). This script formats all changed files from the last mergebase. # YAPF + Clang formatter (if installed). This script formats all changed files from the last mergebase.
...@@ -14,255 +15,109 @@ ...@@ -14,255 +15,109 @@
# Cause the script to exit if a single command fails # Cause the script to exit if a single command fails
set -eo pipefail set -eo pipefail
if [[ -z "${BASH_VERSION}" ]]; then
echo "Please run this script using bash." >&2
exit 1
fi
# this stops git rev-parse from failing if we run this from the .git directory # this stops git rev-parse from failing if we run this from the .git directory
builtin cd "$(dirname "${BASH_SOURCE:-$0}")" builtin cd "$(dirname "${BASH_SOURCE:-$0}")"
ROOT="$(git rev-parse --show-toplevel)" ROOT="$(git rev-parse --show-toplevel)"
builtin cd "$ROOT" || exit 1 builtin cd "$ROOT" || exit 1
# If yapf/ruff/codespell is not installed, install according to the requirements ALL_FILES=''
if ! (yapf --version &>/dev/null && ruff --version &>/dev/null && codespell --version &>/dev/null); then ONLY_CHANGED=''
pip install -r requirements-lint.txt FILES=()
fi if (($# == 0)); then
if [[ -n "$(git status --porcelain)" ]]; then
YAPF_VERSION=$(yapf --version | awk '{print $2}') echo 'Detected uncommitted changes. Please commit or stash them before running format.sh.' >&2
RUFF_VERSION=$(ruff --version | awk '{print $2}') exit 1
CODESPELL_VERSION=$(codespell --version)
# # params: tool name, tool version, required version
tool_version_check() {
if [[ $2 != $3 ]]; then
echo "Wrong $1 version installed: $3 is required, not $2."
pip install -r requirements-lint.txt
fi fi
} ONLY_CHANGED='true'
else
tool_version_check "yapf" $YAPF_VERSION "$(grep yapf requirements-lint.txt | cut -d'=' -f3)" while (($# > 0)); do
tool_version_check "ruff" $RUFF_VERSION "$(grep "ruff==" requirements-lint.txt | cut -d'=' -f3)" case $1 in
tool_version_check "codespell" "$CODESPELL_VERSION" "$(grep codespell requirements-lint.txt | cut -d'=' -f3)" --files)
shift
echo 'tile-lang yapf: Check Start' while (($# > 0)); do
FILES+=("$1")
YAPF_FLAGS=( shift
'--recursive' done
'--parallel' ;;
) --all)
ALL_FILES='true'
YAPF_EXCLUDES=( shift
'--exclude' 'build/**' ;;
'--exclude' '3rdparty/**' *)
) echo "Unknown argument: '$1'" >&2
exit 1
# Format specified files ;;
format() { esac
yapf --in-place "${YAPF_FLAGS[@]}" "$@" done
} fi
# Format files that differ from main branch. Ignores dirs that are not slated MERGE_BASE=""
# for autoformat yet. get_merge_base() {
format_changed() {
# The `if` guard ensures that the list of filenames is not empty, which
# could cause yapf to receive 0 positional arguments, making it hang
# waiting for STDIN.
#
# `diff-filter=ACM` and $MERGEBASE is to ensure we only format files that
# exist on both branches.
UPSTREAM_REPO="https://github.com/tile-ai/tilelang" UPSTREAM_REPO="https://github.com/tile-ai/tilelang"
if git ls-remote --exit-code "${UPSTREAM_REPO}" main &>/dev/null; then
if git ls-remote --exit-code "$UPSTREAM_REPO" main &>/dev/null; then
# First try to use the upstream repository directly # First try to use the upstream repository directly
MERGEBASE="$(git fetch "$UPSTREAM_REPO" main &>/dev/null && git merge-base FETCH_HEAD HEAD)" MERGE_BASE="$(git fetch "${UPSTREAM_REPO}" main &>/dev/null && git merge-base FETCH_HEAD HEAD)"
elif git show-ref --verify --quiet refs/remotes/origin/main; then elif git show-ref --verify --quiet refs/remotes/origin/main; then
# Fall back to origin/main if available # Fall back to origin/main if available
BASE_BRANCH="origin/main" BASE_BRANCH="origin/main"
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)" MERGE_BASE="$(git merge-base "${BASE_BRANCH}" HEAD)"
else else
# Last resort, use local main # Last resort, use local main
BASE_BRANCH="main" BASE_BRANCH="main"
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)" MERGE_BASE="$(git merge-base "${BASE_BRANCH}" HEAD)"
fi fi
echo "${MERGE_BASE}"
if ! git diff --diff-filter=ACM --quiet --exit-code "$MERGEBASE" -- '*.py' '*.pyi' &>/dev/null; then
git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.py' '*.pyi' | xargs -P 5 \
yapf --in-place "${YAPF_EXCLUDES[@]}" "${YAPF_FLAGS[@]}"
fi
}
# Format all files
format_all() {
yapf --in-place "${YAPF_FLAGS[@]}" "${YAPF_EXCLUDES[@]}" .
} }
## This flag formats individual files. --files *must* be the first command line if [[ -n "${ALL_FILES}" ]]; then
## arg to use this option. echo "Checking all files..." >&2
if [[ "$1" == '--files' ]]; then elif [[ -n "${ONLY_CHANGED}" ]]; then
format "${@:2}" MERGE_BASE="$(get_merge_base)"
# If `--all` is passed, then any further arguments are ignored and the echo "Checking changed files compared to merge base (${MERGE_BASE})..." >&2
# entire python directory is formatted. elif [[ "${#FILES[@]}" -gt 0 ]]; then
elif [[ "$1" == '--all' ]]; then echo "Checking specified files: ${FILES[*]}..." >&2
format_all
else
# Format only the files that changed in last commit.
format_changed
fi fi
echo 'tile-lang yapf: Done'
echo 'tile-lang codespell: Check Start' # If pre-commit is not installed, install it.
# check spelling of specified files if ! python3 -m pre_commit --version &>/dev/null; then
spell_check() { python3 -m pip install pre-commit
codespell "$@"
}
spell_check_all(){
codespell --toml pyproject.toml
}
# Spelling check of files that differ from main branch.
spell_check_changed() {
# The `if` guard ensures that the list of filenames is not empty, which
# could cause ruff to receive 0 positional arguments, making it hang
# waiting for STDIN.
#
# `diff-filter=ACM` and $MERGEBASE is to ensure we only lint files that
# exist on both branches.
if git show-ref --verify --quiet refs/remotes/origin/main; then
BASE_BRANCH="origin/main"
else
BASE_BRANCH="main"
fi
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)"
if ! git diff --diff-filter=ACM --quiet --exit-code "$MERGEBASE" -- '*.py' '*.pyi' &>/dev/null; then
git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.py' '*.pyi' | xargs \
codespell
fi
}
# Run Codespell
## This flag runs spell check of individual files. --files *must* be the first command line
## arg to use this option.
if [[ "$1" == '--files' ]]; then
spell_check "${@:2}"
# If `--all` is passed, then any further arguments are ignored and the
# entire python directory is linted.
elif [[ "$1" == '--all' ]]; then
spell_check_all
else
# Check spelling only of the files that changed in last commit.
spell_check_changed
fi fi
echo 'tile-lang codespell: Done'
echo 'tile-lang ruff: Check Start'
# Lint specified files
lint() {
ruff check "$@"
}
# Lint files that differ from main branch. Ignores dirs that are not slated if [[ ! -f "${ROOT}/.git/hooks/pre-commit" ]]; then
# for autolint yet. echo "Installing and initializing pre-commit hooks..."
lint_changed() { python3 -m pre_commit install --install-hooks
# The `if` guard ensures that the list of filenames is not empty, which
# could cause ruff to receive 0 positional arguments, making it hang
# waiting for STDIN.
#
# `diff-filter=ACM` and $MERGEBASE is to ensure we only lint files that
# exist on both branches.
if git show-ref --verify --quiet refs/remotes/origin/main; then
BASE_BRANCH="origin/main"
else
BASE_BRANCH="main"
fi
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)"
if ! git diff --diff-filter=ACM --quiet --exit-code "$MERGEBASE" -- '*.py' '*.pyi' &>/dev/null; then
git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.py' '*.pyi' | xargs \
ruff check
fi
}
# Run Ruff
### This flag lints individual files. --files *must* be the first command line
### arg to use this option.
if [[ "$1" == '--files' ]]; then
lint "${@:2}"
# If `--all` is passed, then any further arguments are ignored and the
# entire python directory is linted.
elif [[ "$1" == '--all' ]]; then
lint python testing
else
# Format only the files that changed in last commit.
lint_changed
fi fi
echo 'tile-lang ruff: Done' echo 'tile-lang pre-commit: Check Start'
echo 'tile-lang clang-format: Check Start'
# If clang-format is available, run it; otherwise, skip
if command -v clang-format &>/dev/null; then
CLANG_FORMAT_VERSION=$(clang-format --version | awk '{print $3}')
tool_version_check "clang-format" "$CLANG_FORMAT_VERSION" "$(grep clang-format requirements-lint.txt | cut -d'=' -f3)"
CLANG_FORMAT_FLAGS=("-i")
# Apply clang-format to specified files
clang_format() {
clang-format "${CLANG_FORMAT_FLAGS[@]}" "$@"
}
# Format all C/C++ files in the repo, excluding specified directories
clang_format_all() {
find . -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) \
-not -path "./3rdparty/*" \
-not -path "./build/*" \
-exec clang-format -i {} +
}
# Format changed C/C++ files relative to main
clang_format_changed() {
if git show-ref --verify --quiet refs/remotes/origin/main; then
BASE_BRANCH="origin/main"
else
BASE_BRANCH="main"
fi
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)" if [[ -n "${ALL_FILES}" ]]; then
python3 -m pre_commit run --all-files
if ! git diff --diff-filter=ACM --quiet --exit-code "$MERGEBASE" -- '*.c' '*.cc' '*.cpp' '*.h' '*.hpp' &>/dev/null; then elif [[ -n "${ONLY_CHANGED}" ]]; then
git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.c' '*.cc' '*.cpp' '*.h' '*.hpp' | xargs clang-format -i python3 -m pre_commit run --from-ref "${MERGE_BASE}" --to-ref HEAD
fi elif [[ "${#FILES[@]}" -gt 0 ]]; then
} python3 -m pre_commit run --files "${FILES[@]}"
if [[ "$1" == '--files' ]]; then
# If --files is given, format only the provided files
clang_format "${@:2}"
elif [[ "$1" == '--all' ]]; then
# If --all is given, format all eligible C/C++ files
clang_format_all
else
# Otherwise, format only changed C/C++ files
clang_format_changed
fi
else
echo "clang-format not found. Skipping C/C++ formatting."
fi fi
echo 'tile-lang clang-format: Done'
echo 'tile-lang pre-commit: Done'
echo 'tile-lang clang-tidy: Check Start' echo 'tile-lang clang-tidy: Check Start'
# If clang-tidy is available, run it; otherwise, skip # If clang-tidy is available, run it; otherwise, skip
if command -v run-clang-tidy &>/dev/null; then if [[ -x "$(command -v run-clang-tidy)" ]]; then
# Check if clang-tidy is available # Check if clang-tidy is available
if ! command -v clang-tidy &>/dev/null; then if [[ ! -x "$(command -v clang-tidy)" ]]; then
echo "clang-tidy not found. Skipping clang-tidy checks." python3 -m pip install --upgrade --requirements "${ROOT}/requirements-lint.txt"
else fi
# Get clang-tidy version # Get clang-tidy version
CLANG_TIDY_VERSION=$(clang-tidy --version | head -n1 | awk '{print $4}') CLANG_TIDY_VERSION="$(clang-tidy --version | head -n1 | awk '{print $4}')"
echo "Using clang-tidy version: $CLANG_TIDY_VERSION" echo "Using clang-tidy version: ${CLANG_TIDY_VERSION}"
# Check if build directory exists # Check if build directory exists
if [ ! -d "build" ]; then if [[ ! -d "${ROOT}/build" ]]; then
echo "Build directory not found. Skipping clang-tidy checks." echo "Build directory not found. Skipping clang-tidy checks."
else else
# Run clang-tidy on specified files # Run clang-tidy on specified files
...@@ -277,40 +132,32 @@ if command -v run-clang-tidy &>/dev/null; then ...@@ -277,40 +132,32 @@ if command -v run-clang-tidy &>/dev/null; then
# Run clang-tidy on changed C/C++ files relative to main # Run clang-tidy on changed C/C++ files relative to main
clang_tidy_changed() { clang_tidy_changed() {
if git show-ref --verify --quiet refs/remotes/origin/main; then
BASE_BRANCH="origin/main"
else
BASE_BRANCH="main"
fi
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)"
# Get changed C/C++ files # Get changed C/C++ files
CHANGED_FILES=$(git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.c' '*.cc' '*.cpp' '*.h' '*.hpp' 2>/dev/null || true) CHANGED_FILES="$(git diff --name-only --diff-filter=ACM "${MERGE_BASE}" -- '*.c' '*.cc' '*.cpp' '*.h' '*.hpp' 2>/dev/null || true)"
if [ -n "$CHANGED_FILES" ]; then if [[ -n "${CHANGED_FILES}" ]]; then
echo "Running clang-tidy on changed files:" echo "Running clang-tidy on changed files:"
echo "$CHANGED_FILES" echo "${CHANGED_FILES}"
# Convert newline-separated files to space-separated and run clang-tidy once # Convert newline-separated files to space-separated and run clang-tidy once
CHANGED_FILES_SPACE=$(echo "$CHANGED_FILES" | tr '\n' ' ') CHANGED_FILES_SPACE="$(echo "${CHANGED_FILES}" | tr '\n' ' ')"
run-clang-tidy -j 64 $CHANGED_FILES_SPACE -p build -fix run-clang-tidy -j 64 ${CHANGED_FILES_SPACE} -p build -fix
else else
echo "No C/C++ files changed. Skipping clang-tidy." echo "No C/C++ files changed. Skipping clang-tidy."
fi fi
} }
if [[ "$1" == '--files' ]]; then if [[ -n "${ALL_FILES}" ]]; then
# If --files is given, run clang-tidy only on the provided files
clang_tidy_files "${@:2}"
elif [[ "$1" == '--all' ]]; then
# If --all is given, run clang-tidy on all source files # If --all is given, run clang-tidy on all source files
clang_tidy_all clang_tidy_all
else elif [[ -n "${ONLY_CHANGED}" ]]; then
# Otherwise, run clang-tidy only on changed C/C++ files # Otherwise, run clang-tidy only on changed C/C++ files
clang_tidy_changed clang_tidy_changed
elif [[ "${#FILES[@]}" -gt 0 ]]; then
# If --files is given, run clang-tidy only on the provided files
clang_tidy_files "${FILES[@]}"
fi fi
fi fi
fi
else else
echo "run-clang-tidy not found. Skipping clang-tidy checks." echo "run-clang-tidy not found. Skipping clang-tidy checks."
echo "To install clang-tidy tools, you may need to install clang-tidy and run-clang-tidy." echo "To install clang-tidy tools, you may need to install clang-tidy and run-clang-tidy."
......
# Format and lint requirements # Format and lint requirements
pre-commit pre-commit
clang-format==15.0.7 clang-format==21.1.2
clang-tidy==18.1.8 clang-tidy==21.1.1
codespell[toml]==2.4.1 codespell[toml]==2.4.1
ruff==0.14.0 ruff==0.14.1
yapf==0.43.0 yapf==0.43.0
...@@ -136,7 +136,7 @@ Array<IterSplitExpr> DivideUnusedIterators(const Array<PrimExpr> &exprs, ...@@ -136,7 +136,7 @@ Array<IterSplitExpr> DivideUnusedIterators(const Array<PrimExpr> &exprs,
for (const IterVar &iter : input_iters) { for (const IterVar &iter : input_iters) {
IterMark iv_mark; IterMark iv_mark;
for (const IterMark &mark : collector.visited_) { for (const IterMark &mark : collector.visited_) {
if (mark->source.as<Var>()->same_as(iter->var)) { if (mark->source.as<Var>()->same_as(iter->var)) { // NOLINT(*)
iv_mark = mark; iv_mark = mark;
break; break;
} }
......
...@@ -27,9 +27,7 @@ static inline std::pair<bool, TCGEN5MMAMeta> ...@@ -27,9 +27,7 @@ static inline std::pair<bool, TCGEN5MMAMeta>
GetTCGEN5MMAMeta(int M, int N, int K, DataType ab_dtype, DataType c_dtype) { GetTCGEN5MMAMeta(int M, int N, int K, DataType ab_dtype, DataType c_dtype) {
// TODO (lei) Currently not all shapes / dtypes are supported for TCGEN5MMA. // TODO (lei) Currently not all shapes / dtypes are supported for TCGEN5MMA.
#define FAIL \ #define FAIL \
return { \ return { false, TCGEN5MMAMeta{0, 0, 0} }
false, TCGEN5MMAMeta { 0, 0, 0 } \
}
#define SUCCESS(atom_m, atom_n, atom_k) \ #define SUCCESS(atom_m, atom_n, atom_k) \
return { \ return { \
true, TCGEN5MMAMeta { atom_m, atom_n, atom_k } \ true, TCGEN5MMAMeta { atom_m, atom_n, atom_k } \
......
...@@ -42,7 +42,7 @@ class ParallelOpNode; ...@@ -42,7 +42,7 @@ class ParallelOpNode;
class ParallelLoopNestVisitor : public StmtExprVisitor { class ParallelLoopNestVisitor : public StmtExprVisitor {
private: private:
ParallelLoopNestVisitor(ParallelOpNode *op) : p(op){}; ParallelLoopNestVisitor(ParallelOpNode *op) : p(op) {};
void VisitStmt_(const ForNode *op) override; void VisitStmt_(const ForNode *op) override;
void VisitStmt_(const BufferStoreNode *op) override; void VisitStmt_(const BufferStoreNode *op) override;
void VisitExpr_(const BufferLoadNode *op) override; void VisitExpr_(const BufferLoadNode *op) override;
......
...@@ -20,7 +20,7 @@ template <typename T> static std::string ArrayToStr(const T *ptr, size_t n) { ...@@ -20,7 +20,7 @@ template <typename T> static std::string ArrayToStr(const T *ptr, size_t n) {
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
if (i > 0) if (i > 0)
ss << ", "; ss << ", ";
ss << ptr[i]; ss << ptr[i]; // NOLINT(clang-analyzer-security.ArrayBound)
} }
ss << "]"; ss << "]";
return ss.str(); return ss.str();
......
...@@ -1749,8 +1749,8 @@ void CodeGenTileLangCUDA::VisitExpr_(const CallNode *op, std::ostream &os) { ...@@ -1749,8 +1749,8 @@ void CodeGenTileLangCUDA::VisitExpr_(const CallNode *op, std::ostream &os) {
os << "}\n"; os << "}\n";
} else { } else {
os << "for (int local_id = 0; local_id < 8; ++local_id) {\n"; os << "for (int local_id = 0; local_id < 8; ++local_id) {\n";
os << dst << "[" + this->PrintExpr(dst_ind) + "]" os << dst << "[" + this->PrintExpr(dst_ind) + "]" << " = " << src << "["
<< " = " << src << "[" << src_offset << " + local_id];\n"; << src_offset << " + local_id];\n";
os << "}\n"; os << "}\n";
} }
......
...@@ -218,7 +218,7 @@ CodeGenTileLangWebGPU::AddFunction(const PrimFunc &f, bool skip_readonly_decl) { ...@@ -218,7 +218,7 @@ CodeGenTileLangWebGPU::AddFunction(const PrimFunc &f, bool skip_readonly_decl) {
this->decl_stream << "\nstruct " << type_pod_args << " {\n"; this->decl_stream << "\nstruct " << type_pod_args << " {\n";
for (size_t i = 0; i < pod_args.size(); ++i) { for (size_t i = 0; i < pod_args.size(); ++i) {
Var v = pod_args[i]; const Var &v = pod_args[i];
ICHECK(!v.dtype().is_handle()); ICHECK(!v.dtype().is_handle());
std::string vid = AllocVarID(v.get()); std::string vid = AllocVarID(v.get());
......
...@@ -5023,12 +5023,12 @@ typedef struct CUgraphNodeParams_st { ...@@ -5023,12 +5023,12 @@ typedef struct CUgraphNodeParams_st {
/** /**
* Device that represents the CPU * Device that represents the CPU
*/ */
#define CU_DEVICE_CPU ((CUdevice)-1) #define CU_DEVICE_CPU ((CUdevice) - 1)
   
/** /**
* Device that represents an invalid device * Device that represents an invalid device
*/ */
#define CU_DEVICE_INVALID ((CUdevice)-2) #define CU_DEVICE_INVALID ((CUdevice) - 2)
   
/** /**
* Bitmasks for ::CU_DEVICE_ATTRIBUTE_GPU_DIRECT_RDMA_FLUSH_WRITES_OPTIONS * Bitmasks for ::CU_DEVICE_ATTRIBUTE_GPU_DIRECT_RDMA_FLUSH_WRITES_OPTIONS
...@@ -1192,8 +1192,8 @@ unsigned int float2half_impl(T value, ...) { ...@@ -1192,8 +1192,8 @@ unsigned int float2half_impl(T value, ...) {
template <std::float_round_style R, typename T> template <std::float_round_style R, typename T>
unsigned int float2half(T value) { unsigned int float2half(T value) {
return float2half_impl<R>( return float2half_impl<R>(
value, bool_type < std::numeric_limits<T>::is_iec559 && value, bool_type<std::numeric_limits<T>::is_iec559 &&
sizeof(typename bits<T>::type) == sizeof(T) > ()); sizeof(typename bits<T>::type) == sizeof(T)>());
} }
/// Convert integer to half-precision floating-point. /// Convert integer to half-precision floating-point.
...@@ -1665,9 +1665,10 @@ template <typename T> T half2float_impl(unsigned int value, T, ...) { ...@@ -1665,9 +1665,10 @@ template <typename T> T half2float_impl(unsigned int value, T, ...) {
/// \param value half-precision value to convert /// \param value half-precision value to convert
/// \return floating-point value /// \return floating-point value
template <typename T> T half2float(unsigned int value) { template <typename T> T half2float(unsigned int value) {
return half2float_impl(value, T(), return half2float_impl(
bool_type < std::numeric_limits<T>::is_iec559 && value, T(),
sizeof(typename bits<T>::type) == sizeof(T) > ()); bool_type<std::numeric_limits<T>::is_iec559 &&
sizeof(typename bits<T>::type) == sizeof(T)>());
} }
/// Convert half-precision floating-point to integer. /// Convert half-precision floating-point to integer.
......
...@@ -106,8 +106,8 @@ TL_DEVICE void AtomicAdd(T1 &ref, T2 val, ...@@ -106,8 +106,8 @@ TL_DEVICE void AtomicAdd(T1 &ref, T2 val,
using NT1 = typename normalize_atomic_type<T1>::type; using NT1 = typename normalize_atomic_type<T1>::type;
T1 *address = &ref; T1 *address = &ref;
if constexpr ((std::is_same_v<NT1, half> || if constexpr ((std::is_same_v<NT1, half> ||
std::is_same_v<NT1, __nv_bfloat16>)&&memory_order == std::is_same_v<NT1, __nv_bfloat16>) &&
int(cuda::memory_order_relaxed)) { memory_order == int(cuda::memory_order_relaxed)) {
atomicAdd(reinterpret_cast<NT1 *>(address), static_cast<NT1>(val)); atomicAdd(reinterpret_cast<NT1 *>(address), static_cast<NT1>(val));
} else { } else {
cuda::atomic_ref<NT1, cuda::thread_scope_device> aref(*address); cuda::atomic_ref<NT1, cuda::thread_scope_device> aref(*address);
...@@ -121,8 +121,8 @@ TL_DEVICE T1 AtomicAddRet(T1 &ref, T2 val, ...@@ -121,8 +121,8 @@ TL_DEVICE T1 AtomicAddRet(T1 &ref, T2 val,
using NT1 = typename normalize_atomic_type<T1>::type; using NT1 = typename normalize_atomic_type<T1>::type;
T1 *address = &ref; T1 *address = &ref;
if constexpr ((std::is_same_v<NT1, half> || if constexpr ((std::is_same_v<NT1, half> ||
std::is_same_v<NT1, __nv_bfloat16>)&&memory_order == std::is_same_v<NT1, __nv_bfloat16>) &&
int(cuda::memory_order_relaxed)) { memory_order == int(cuda::memory_order_relaxed)) {
return static_cast<T1>( return static_cast<T1>(
atomicAdd(reinterpret_cast<NT1 *>(address), static_cast<NT1>(val))); atomicAdd(reinterpret_cast<NT1 *>(address), static_cast<NT1>(val)));
} else { } else {
......
...@@ -244,8 +244,8 @@ union GmmaDescriptor { ...@@ -244,8 +244,8 @@ union GmmaDescriptor {
uint16_t stride_byte_offset_ : 14, : 2; // 14 bits [0,14), 2 bits unused uint16_t stride_byte_offset_ : 14, : 2; // 14 bits [0,14), 2 bits unused
// base_offset, bit [49,52) // base_offset, bit [49,52)
// Valid only for SWIZZLE_128B and SWIZZLE_64B // Valid only for SWIZZLE_128B and SWIZZLE_64B
uint8_t : 1, uint8_t : 1, base_offset_ : 3,
base_offset_ : 3, : 4; // 1 bit unused, 3 bits [1,4), 4 bits unused : 4; // 1 bit unused, 3 bits [1,4), 4 bits unused
// layout type, bit [62,64) // layout type, bit [62,64)
// SWIZZLE_NONE = 0, SWIZZLE_32B = 3, SWIZZLE_64B = 2, SWIZZLE_128B = 1 // SWIZZLE_NONE = 0, SWIZZLE_32B = 3, SWIZZLE_64B = 2, SWIZZLE_128B = 1
uint8_t : 6, layout_type_ : 2; // 6 bits unused, 2 bits [6,8) uint8_t : 6, layout_type_ : 2; // 6 bits unused, 2 bits [6,8)
......
...@@ -86,14 +86,14 @@ private: ...@@ -86,14 +86,14 @@ private:
class RegionVisitor : public ExprVisitor { class RegionVisitor : public ExprVisitor {
public: public:
RegionVisitor(){}; RegionVisitor() {};
void VisitExpr_(const VarNode *var) { seen_.insert(var); } void VisitExpr_(const VarNode *var) { seen_.insert(var); }
std::unordered_set<const VarNode *> seen_; std::unordered_set<const VarNode *> seen_;
}; };
class BlockIdxVisitor : public StmtVisitor { class BlockIdxVisitor : public StmtVisitor {
public: public:
BlockIdxVisitor(){}; BlockIdxVisitor() {};
void VisitStmt_(const AttrStmtNode *attr) final { void VisitStmt_(const AttrStmtNode *attr) final {
if (attr->attr_key == attr::thread_extent) { if (attr->attr_key == attr::thread_extent) {
IterVar iv = Downcast<IterVar>(attr->node); IterVar iv = Downcast<IterVar>(attr->node);
......
...@@ -99,7 +99,7 @@ public: ...@@ -99,7 +99,7 @@ public:
private: private:
ParallelLoopFuser(arith::Analyzer *analyzer) ParallelLoopFuser(arith::Analyzer *analyzer)
: IRMutatorWithAnalyzer(analyzer){}; : IRMutatorWithAnalyzer(analyzer) {};
Stmt VisitStmt_(const ForNode *op) final { Stmt VisitStmt_(const ForNode *op) final {
// Gather consecutive parallel loops // Gather consecutive parallel loops
......
...@@ -131,13 +131,13 @@ public: ...@@ -131,13 +131,13 @@ public:
ICHECK(dst_layout_opt.has_value()) ICHECK(dst_layout_opt.has_value())
<< "Failed to cast layout to Fragment for buffer " << buffer << "Failed to cast layout to Fragment for buffer " << buffer
<< ", layout type is " << layout->GetTypeKey(); << ", layout type is " << layout->GetTypeKey();
auto dst_layout = dst_layout_opt.value(); const auto &dst_layout = dst_layout_opt.value();
auto src_layout_opt = layout_map[buffer].as<Fragment>(); auto src_layout_opt = layout_map[buffer].as<Fragment>();
ICHECK(src_layout_opt.has_value()) ICHECK(src_layout_opt.has_value())
<< "Failed to cast layout_map[buffer] to Fragment for buffer " << "Failed to cast layout_map[buffer] to Fragment for buffer "
<< buffer << ", layout type is " << buffer << ", layout type is "
<< layout_map[buffer]->GetTypeKey(); << layout_map[buffer]->GetTypeKey();
auto src_layout = src_layout_opt.value(); const auto &src_layout = src_layout_opt.value();
ICHECK(dst_layout->InputDim() == src_layout->InputDim()); ICHECK(dst_layout->InputDim() == src_layout->InputDim());
Array<PrimExpr> indices; Array<PrimExpr> indices;
indices.reserve(dst_layout->InputDim()); indices.reserve(dst_layout->InputDim());
...@@ -398,7 +398,7 @@ private: ...@@ -398,7 +398,7 @@ private:
<< call->args[1]->GetTypeKey(); << call->args[1]->GetTypeKey();
return std::nullopt; return std::nullopt;
} }
auto var = var_opt.value(); const auto &var = var_opt.value();
return buffer_data_to_buffer_[var]; return buffer_data_to_buffer_[var];
} else if (call->op.same_as(RegionOp::Get())) { } else if (call->op.same_as(RegionOp::Get())) {
return call->args[0].as<BufferLoadNode>()->buffer; return call->args[0].as<BufferLoadNode>()->buffer;
...@@ -636,7 +636,7 @@ private: ...@@ -636,7 +636,7 @@ private:
LayoutInferencer(const LayoutInferenceResult &result, LayoutInferencer(const LayoutInferenceResult &result,
bool skip_thread_partition, arith::Analyzer *analyzer) bool skip_thread_partition, arith::Analyzer *analyzer)
: arith::IRMutatorWithAnalyzer(analyzer), result_(result), : arith::IRMutatorWithAnalyzer(analyzer), result_(result),
skip_thread_partition_(skip_thread_partition){}; skip_thread_partition_(skip_thread_partition) {};
using arith::IRMutatorWithAnalyzer::IRMutatorWithAnalyzer; using arith::IRMutatorWithAnalyzer::IRMutatorWithAnalyzer;
......
...@@ -209,7 +209,7 @@ private: ...@@ -209,7 +209,7 @@ private:
auto opt_buffer = var_to_buffer_.Get(reducer_var); auto opt_buffer = var_to_buffer_.Get(reducer_var);
ICHECK(opt_buffer); ICHECK(opt_buffer);
auto buffer = opt_buffer.value(); const auto &buffer = opt_buffer.value();
Fragment f; Fragment f;
if (info->rep == ReducerRepType::ALL) { if (info->rep == ReducerRepType::ALL) {
f = Fragment(buffer->shape, {}, ReplicationPlaceholder(), f = Fragment(buffer->shape, {}, ReplicationPlaceholder(),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment