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
clang-analyzer-*,
cppcoreguidelines-pro-type-static-cast-downcast,
......@@ -47,7 +56,3 @@ Checks: >
-clang-analyzer-deadcode.DeadStores,
-clang-analyzer-optin.cplusplus.VirtualCall,
-clang-diagnostic-tautological-constant-compare,
WarningsAsErrors: '*'
HeaderFilterRegex: '^(?!.*(3rdparty|build)).*$'
\ No newline at end of file
......@@ -287,21 +287,39 @@ jobs:
echo "Clearing uv cache at ${UV_CACHE_DIR} due to failure."
uv cache clean
- name: Run format check
id: format-check
- name: Run clang-tidy
id: clang-tidy
if: runner.os == 'Linux'
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
(
cd build
cmake .. ${CLANG_TIDY_CMAKE_OPTIONS} # no quotes here
)
cmake -S . -B cmake-build --fresh ${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
bash format.sh || rc="$?"
rm -rf build
if [[ "${rc}" -ne 0 ]]; then
echo "::error::Format check failed. Please run 'bash format.sh' locally to fix the issues."
exit 1
"${CLANG_TIDY[@]}" -clang-tidy-binary="$(command -v clang-tidy)" \
-p="cmake-build" ${CXX_FILES} || rc="$?"
rm -rf cmake-build run-clang-tidy.py
if (( rc != 0 )); then
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
- name: Enable core dump generation (Linux / GitHub-hosted runners)
......
......@@ -97,3 +97,7 @@ tilelang/jit/adapter/cython/.cycache
# claude
**/.claude
# CMake
cmake-build/
cmake-build-*/
......@@ -32,7 +32,7 @@ repos:
args: [--ignore-case]
files: ^docs/spelling_wordlist\.txt$
- 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:
- id: clang-format
exclude: |
......@@ -41,7 +41,7 @@ repos:
^.+\.json$
)
- 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:
- id: ruff-check
args: [--fix, --exit-non-zero-on-fix]
......
#!/usr/bin/env bash
# Usage:
# # Do work and commit your work.
#
# # Format files that differ from origin/main.
# 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.
......@@ -14,303 +15,149 @@
# Cause the script to exit if a single command fails
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
builtin cd "$(dirname "${BASH_SOURCE:-$0}")"
ROOT="$(git rev-parse --show-toplevel)"
builtin cd "$ROOT" || exit 1
# If yapf/ruff/codespell is not installed, install according to the requirements
if ! (yapf --version &>/dev/null && ruff --version &>/dev/null && codespell --version &>/dev/null); then
pip install -r requirements-lint.txt
fi
YAPF_VERSION=$(yapf --version | awk '{print $2}')
RUFF_VERSION=$(ruff --version | awk '{print $2}')
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
ALL_FILES=''
ONLY_CHANGED=''
FILES=()
if (($# == 0)); then
if [[ -n "$(git status --porcelain)" ]]; then
echo 'Detected uncommitted changes. Please commit or stash them before running format.sh.' >&2
exit 1
fi
}
tool_version_check "yapf" $YAPF_VERSION "$(grep yapf requirements-lint.txt | cut -d'=' -f3)"
tool_version_check "ruff" $RUFF_VERSION "$(grep "ruff==" requirements-lint.txt | cut -d'=' -f3)"
tool_version_check "codespell" "$CODESPELL_VERSION" "$(grep codespell requirements-lint.txt | cut -d'=' -f3)"
echo 'tile-lang yapf: Check Start'
YAPF_FLAGS=(
'--recursive'
'--parallel'
)
YAPF_EXCLUDES=(
'--exclude' 'build/**'
'--exclude' '3rdparty/**'
)
# Format specified files
format() {
yapf --in-place "${YAPF_FLAGS[@]}" "$@"
}
ONLY_CHANGED='true'
else
while (($# > 0)); do
case $1 in
--files)
shift
while (($# > 0)); do
FILES+=("$1")
shift
done
;;
--all)
ALL_FILES='true'
shift
;;
*)
echo "Unknown argument: '$1'" >&2
exit 1
;;
esac
done
fi
# Format files that differ from main branch. Ignores dirs that are not slated
# for autoformat yet.
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.
MERGE_BASE=""
get_merge_base() {
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
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
# Fall back to origin/main if available
BASE_BRANCH="origin/main"
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)"
MERGE_BASE="$(git merge-base "${BASE_BRANCH}" HEAD)"
else
# Last resort, use local main
BASE_BRANCH="main"
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)"
fi
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[@]}"
MERGE_BASE="$(git merge-base "${BASE_BRANCH}" HEAD)"
fi
echo "${MERGE_BASE}"
}
# Format all files
format_all() {
yapf --in-place "${YAPF_FLAGS[@]}" "${YAPF_EXCLUDES[@]}" .
}
## This flag formats individual files. --files *must* be the first command line
## arg to use this option.
if [[ "$1" == '--files' ]]; then
format "${@:2}"
# If `--all` is passed, then any further arguments are ignored and the
# entire python directory is formatted.
elif [[ "$1" == '--all' ]]; then
format_all
else
# Format only the files that changed in last commit.
format_changed
if [[ -n "${ALL_FILES}" ]]; then
echo "Checking all files..." >&2
elif [[ -n "${ONLY_CHANGED}" ]]; then
MERGE_BASE="$(get_merge_base)"
echo "Checking changed files compared to merge base (${MERGE_BASE})..." >&2
elif [[ "${#FILES[@]}" -gt 0 ]]; then
echo "Checking specified files: ${FILES[*]}..." >&2
fi
echo 'tile-lang yapf: Done'
echo 'tile-lang codespell: Check Start'
# check spelling of specified files
spell_check() {
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
# If pre-commit is not installed, install it.
if ! python3 -m pre_commit --version &>/dev/null; then
python3 -m pip install pre-commit
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
# for autolint yet.
lint_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 \
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
if [[ ! -f "${ROOT}/.git/hooks/pre-commit" ]]; then
echo "Installing and initializing pre-commit hooks..."
python3 -m pre_commit install --install-hooks
fi
echo 'tile-lang ruff: Done'
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 {} +
}
echo 'tile-lang pre-commit: Check Start'
# 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 ! git diff --diff-filter=ACM --quiet --exit-code "$MERGEBASE" -- '*.c' '*.cc' '*.cpp' '*.h' '*.hpp' &>/dev/null; then
git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.c' '*.cc' '*.cpp' '*.h' '*.hpp' | xargs clang-format -i
fi
}
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."
if [[ -n "${ALL_FILES}" ]]; then
python3 -m pre_commit run --all-files
elif [[ -n "${ONLY_CHANGED}" ]]; then
python3 -m pre_commit run --from-ref "${MERGE_BASE}" --to-ref HEAD
elif [[ "${#FILES[@]}" -gt 0 ]]; then
python3 -m pre_commit run --files "${FILES[@]}"
fi
echo 'tile-lang clang-format: Done'
echo 'tile-lang pre-commit: Done'
echo 'tile-lang clang-tidy: Check Start'
# 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
if ! command -v clang-tidy &>/dev/null; then
echo "clang-tidy not found. Skipping clang-tidy checks."
else
# Get clang-tidy version
CLANG_TIDY_VERSION=$(clang-tidy --version | head -n1 | awk '{print $4}')
echo "Using clang-tidy version: $CLANG_TIDY_VERSION"
# Check if build directory exists
if [ ! -d "build" ]; then
echo "Build directory not found. Skipping clang-tidy checks."
else
# Run clang-tidy on specified files
clang_tidy_files() {
run-clang-tidy -j 64 "$@" -p build
}
# Run clang-tidy on all C/C++ source files
clang_tidy_all() {
run-clang-tidy -j 64 src/*.cc -p build
}
# Run clang-tidy on changed C/C++ files relative to main
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
CHANGED_FILES=$(git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.c' '*.cc' '*.cpp' '*.h' '*.hpp' 2>/dev/null || true)
if [ -n "$CHANGED_FILES" ]; then
echo "Running clang-tidy on changed files:"
echo "$CHANGED_FILES"
# Convert newline-separated files to space-separated and run clang-tidy once
CHANGED_FILES_SPACE=$(echo "$CHANGED_FILES" | tr '\n' ' ')
run-clang-tidy -j 64 $CHANGED_FILES_SPACE -p build -fix
else
echo "No C/C++ files changed. Skipping clang-tidy."
fi
}
if [[ ! -x "$(command -v clang-tidy)" ]]; then
python3 -m pip install --upgrade --requirements "${ROOT}/requirements-lint.txt"
fi
# Get clang-tidy version
CLANG_TIDY_VERSION="$(clang-tidy --version | head -n1 | awk '{print $4}')"
echo "Using clang-tidy version: ${CLANG_TIDY_VERSION}"
if [[ "$1" == '--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
clang_tidy_all
# Check if build directory exists
if [[ ! -d "${ROOT}/build" ]]; then
echo "Build directory not found. Skipping clang-tidy checks."
else
# Run clang-tidy on specified files
clang_tidy_files() {
run-clang-tidy -j 64 "$@" -p build
}
# Run clang-tidy on all C/C++ source files
clang_tidy_all() {
run-clang-tidy -j 64 src/*.cc -p build
}
# Run clang-tidy on changed C/C++ files relative to main
clang_tidy_changed() {
# Get changed C/C++ files
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
echo "Running clang-tidy on changed files:"
echo "${CHANGED_FILES}"
# Convert newline-separated files to space-separated and run clang-tidy once
CHANGED_FILES_SPACE="$(echo "${CHANGED_FILES}" | tr '\n' ' ')"
run-clang-tidy -j 64 ${CHANGED_FILES_SPACE} -p build -fix
else
# Otherwise, run clang-tidy only on changed C/C++ files
clang_tidy_changed
echo "No C/C++ files changed. Skipping clang-tidy."
fi
}
if [[ -n "${ALL_FILES}" ]]; then
# If --all is given, run clang-tidy on all source files
clang_tidy_all
elif [[ -n "${ONLY_CHANGED}" ]]; then
# Otherwise, run clang-tidy only on changed C/C++ files
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
else
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."
......
# Format and lint requirements
pre-commit
clang-format==15.0.7
clang-tidy==18.1.8
clang-format==21.1.2
clang-tidy==21.1.1
codespell[toml]==2.4.1
ruff==0.14.0
ruff==0.14.1
yapf==0.43.0
......@@ -136,7 +136,7 @@ Array<IterSplitExpr> DivideUnusedIterators(const Array<PrimExpr> &exprs,
for (const IterVar &iter : input_iters) {
IterMark iv_mark;
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;
break;
}
......
......@@ -27,9 +27,7 @@ static inline std::pair<bool, TCGEN5MMAMeta>
GetTCGEN5MMAMeta(int M, int N, int K, DataType ab_dtype, DataType c_dtype) {
// TODO (lei) Currently not all shapes / dtypes are supported for TCGEN5MMA.
#define FAIL \
return { \
false, TCGEN5MMAMeta { 0, 0, 0 } \
}
return { false, TCGEN5MMAMeta{0, 0, 0} }
#define SUCCESS(atom_m, atom_n, atom_k) \
return { \
true, TCGEN5MMAMeta { atom_m, atom_n, atom_k } \
......
......@@ -42,7 +42,7 @@ class ParallelOpNode;
class ParallelLoopNestVisitor : public StmtExprVisitor {
private:
ParallelLoopNestVisitor(ParallelOpNode *op) : p(op){};
ParallelLoopNestVisitor(ParallelOpNode *op) : p(op) {};
void VisitStmt_(const ForNode *op) override;
void VisitStmt_(const BufferStoreNode *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) {
for (size_t i = 0; i < n; i++) {
if (i > 0)
ss << ", ";
ss << ptr[i];
ss << ptr[i]; // NOLINT(clang-analyzer-security.ArrayBound)
}
ss << "]";
return ss.str();
......
......@@ -1749,8 +1749,8 @@ void CodeGenTileLangCUDA::VisitExpr_(const CallNode *op, std::ostream &os) {
os << "}\n";
} else {
os << "for (int local_id = 0; local_id < 8; ++local_id) {\n";
os << dst << "[" + this->PrintExpr(dst_ind) + "]"
<< " = " << src << "[" << src_offset << " + local_id];\n";
os << dst << "[" + this->PrintExpr(dst_ind) + "]" << " = " << src << "["
<< src_offset << " + local_id];\n";
os << "}\n";
}
......
......@@ -218,7 +218,7 @@ CodeGenTileLangWebGPU::AddFunction(const PrimFunc &f, bool skip_readonly_decl) {
this->decl_stream << "\nstruct " << type_pod_args << " {\n";
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());
std::string vid = AllocVarID(v.get());
......
......@@ -5023,12 +5023,12 @@ typedef struct CUgraphNodeParams_st {
/**
* Device that represents the CPU
*/
#define CU_DEVICE_CPU ((CUdevice)-1)
#define CU_DEVICE_CPU ((CUdevice) - 1)
 
/**
* 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
......@@ -1192,8 +1192,8 @@ unsigned int float2half_impl(T value, ...) {
template <std::float_round_style R, typename T>
unsigned int float2half(T value) {
return float2half_impl<R>(
value, bool_type < std::numeric_limits<T>::is_iec559 &&
sizeof(typename bits<T>::type) == sizeof(T) > ());
value, bool_type<std::numeric_limits<T>::is_iec559 &&
sizeof(typename bits<T>::type) == sizeof(T)>());
}
/// Convert integer to half-precision floating-point.
......@@ -1665,9 +1665,10 @@ template <typename T> T half2float_impl(unsigned int value, T, ...) {
/// \param value half-precision value to convert
/// \return floating-point value
template <typename T> T half2float(unsigned int value) {
return half2float_impl(value, T(),
bool_type < std::numeric_limits<T>::is_iec559 &&
sizeof(typename bits<T>::type) == sizeof(T) > ());
return half2float_impl(
value, T(),
bool_type<std::numeric_limits<T>::is_iec559 &&
sizeof(typename bits<T>::type) == sizeof(T)>());
}
/// Convert half-precision floating-point to integer.
......
......@@ -106,8 +106,8 @@ TL_DEVICE void AtomicAdd(T1 &ref, T2 val,
using NT1 = typename normalize_atomic_type<T1>::type;
T1 *address = &ref;
if constexpr ((std::is_same_v<NT1, half> ||
std::is_same_v<NT1, __nv_bfloat16>)&&memory_order ==
int(cuda::memory_order_relaxed)) {
std::is_same_v<NT1, __nv_bfloat16>) &&
memory_order == int(cuda::memory_order_relaxed)) {
atomicAdd(reinterpret_cast<NT1 *>(address), static_cast<NT1>(val));
} else {
cuda::atomic_ref<NT1, cuda::thread_scope_device> aref(*address);
......@@ -121,8 +121,8 @@ TL_DEVICE T1 AtomicAddRet(T1 &ref, T2 val,
using NT1 = typename normalize_atomic_type<T1>::type;
T1 *address = &ref;
if constexpr ((std::is_same_v<NT1, half> ||
std::is_same_v<NT1, __nv_bfloat16>)&&memory_order ==
int(cuda::memory_order_relaxed)) {
std::is_same_v<NT1, __nv_bfloat16>) &&
memory_order == int(cuda::memory_order_relaxed)) {
return static_cast<T1>(
atomicAdd(reinterpret_cast<NT1 *>(address), static_cast<NT1>(val)));
} else {
......
......@@ -244,8 +244,8 @@ union GmmaDescriptor {
uint16_t stride_byte_offset_ : 14, : 2; // 14 bits [0,14), 2 bits unused
// base_offset, bit [49,52)
// Valid only for SWIZZLE_128B and SWIZZLE_64B
uint8_t : 1,
base_offset_ : 3, : 4; // 1 bit unused, 3 bits [1,4), 4 bits unused
uint8_t : 1, base_offset_ : 3,
: 4; // 1 bit unused, 3 bits [1,4), 4 bits unused
// layout type, bit [62,64)
// 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)
......
......@@ -86,14 +86,14 @@ private:
class RegionVisitor : public ExprVisitor {
public:
RegionVisitor(){};
RegionVisitor() {};
void VisitExpr_(const VarNode *var) { seen_.insert(var); }
std::unordered_set<const VarNode *> seen_;
};
class BlockIdxVisitor : public StmtVisitor {
public:
BlockIdxVisitor(){};
BlockIdxVisitor() {};
void VisitStmt_(const AttrStmtNode *attr) final {
if (attr->attr_key == attr::thread_extent) {
IterVar iv = Downcast<IterVar>(attr->node);
......
......@@ -99,7 +99,7 @@ public:
private:
ParallelLoopFuser(arith::Analyzer *analyzer)
: IRMutatorWithAnalyzer(analyzer){};
: IRMutatorWithAnalyzer(analyzer) {};
Stmt VisitStmt_(const ForNode *op) final {
// Gather consecutive parallel loops
......
......@@ -131,13 +131,13 @@ public:
ICHECK(dst_layout_opt.has_value())
<< "Failed to cast layout to Fragment for buffer " << buffer
<< ", 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>();
ICHECK(src_layout_opt.has_value())
<< "Failed to cast layout_map[buffer] to Fragment for buffer "
<< buffer << ", layout type is "
<< 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());
Array<PrimExpr> indices;
indices.reserve(dst_layout->InputDim());
......@@ -398,7 +398,7 @@ private:
<< call->args[1]->GetTypeKey();
return std::nullopt;
}
auto var = var_opt.value();
const auto &var = var_opt.value();
return buffer_data_to_buffer_[var];
} else if (call->op.same_as(RegionOp::Get())) {
return call->args[0].as<BufferLoadNode>()->buffer;
......@@ -636,7 +636,7 @@ private:
LayoutInferencer(const LayoutInferenceResult &result,
bool skip_thread_partition, arith::Analyzer *analyzer)
: arith::IRMutatorWithAnalyzer(analyzer), result_(result),
skip_thread_partition_(skip_thread_partition){};
skip_thread_partition_(skip_thread_partition) {};
using arith::IRMutatorWithAnalyzer::IRMutatorWithAnalyzer;
......
......@@ -209,7 +209,7 @@ private:
auto opt_buffer = var_to_buffer_.Get(reducer_var);
ICHECK(opt_buffer);
auto buffer = opt_buffer.value();
const auto &buffer = opt_buffer.value();
Fragment f;
if (info->rep == ReducerRepType::ALL) {
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