diff --git a/.clang-format b/.clang-format index ed68e746..0b9508ff 100644 --- a/.clang-format +++ b/.clang-format @@ -18,7 +18,7 @@ IncludeCategories: - Regex: '^("|<)Python\.h' Priority: 50 CaseSensitive: false - - Regex: '^("|<)(frameobject|structmember)\.h' + - Regex: '^("|<)(frameobject|structmember|listobject)\.h' Priority: 50 SortPriority: 51 CaseSensitive: false diff --git a/.clang-tidy b/.clang-tidy index b0dfbca6..5a1cd5c7 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -2,30 +2,19 @@ Checks: ' bugprone-*, -bugprone-easily-swappable-parameters, --bugprone-reserved-identifier, clang-analyzer-*, clang-diagnostic-*, cppcoreguidelines-*, --cppcoreguidelines-macro-usage, --cppcoreguidelines-owning-memory, -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-pro-bounds-constant-array-index, -cppcoreguidelines-pro-bounds-pointer-arithmetic, --cppcoreguidelines-pro-type-reinterpret-cast, --cppcoreguidelines-pro-type-static-cast-downcast, --cppcoreguidelines-pro-type-union-access, --cppcoreguidelines-pro-type-vararg, --cppcoreguidelines-special-member-functions, --cppcoreguidelines-non-private-member-variables-in-classes, hicpp-exception-baseclass, hicpp-avoid-goto, google-* misc-unused-alias-decls, misc-unused-using-decls, modernize-*, --modernize-concat-nested-namespaces, -modernize-use-trailing-return-type, --modernize-use-nodiscard, performance-*, readability-*, -readability-identifier-length, @@ -34,7 +23,6 @@ readability-*, ' HeaderFilterRegex: '.*' AnalyzeTemporaryDtors: false -#WarningsAsErrors: '*' FormatStyle: file CheckOptions: - key: cppcoreguidelines-avoid-do-while.IgnoreMacros diff --git a/.clangd b/.clangd new file mode 100644 index 00000000..654de907 --- /dev/null +++ b/.clangd @@ -0,0 +1,5 @@ +CompileFlags: + Remove: -fabi* +Diagnostics: + UnusedIncludes: Strict + MissingIncludes: Strict diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 00000000..c8b0b212 --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,81 @@ +name: static checks on sco + +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + +env: + DEEPLINK_PATH: /mnt/cache/share/deeplinkci/github/${{ github.repository }} + ENV_SOURCE: /mnt/cache/share/platform/env/dipu_latest + PROXY_SOURCE: /mnt/cache/share/platform/env/proxy + CLANGD_EXEC: /mnt/cache/share/platform/dep/clang-17/bin/clangd + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + static-checks-on-sco: + name: static checks on sco + runs-on: tps-sco-ci + steps: + - name: setting up environment + run: | + set -euxo pipefail + set_env() { + echo "$1=$2" >> "${GITHUB_ENV}" + eval "$1=\"\$2\"" + } + set_env WORKSPACE "${DEEPLINK_PATH}/${{ github.run_number }}" + set_env CODE_SOURCE "${WORKSPACE}/source" + set_env CLANGD_TIDY_SOURCE "${WORKSPACE}/clangd-tidy" + set_env CLANGD_TIDY_LOG "${WORKSPACE}/clang-tidy.log" + - name: clean obsolete workspaces & prepare workspace + run: | + set -euxo pipefail + ls -la ${DEEPLINK_PATH} + rm -rf ${WORKSPACE} + find ${DEEPLINK_PATH} -maxdepth 1 -mmin +480 -type d -exec bash -c 'echo clean "$0" && rm -rf "$0"' {} \; + mkdir -p ${WORKSPACE} + - name: checkout code + run: | + set -euo pipefail + source ${PROXY_SOURCE} + set -x + rm -rf ${CODE_SOURCE} + if [ -n "${{ github.event.pull_request.head.repo.full_name }}" ] && [[ ! "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]]; then + git clone ${{ github.event.pull_request.head.repo.clone_url }} ${CODE_SOURCE} + cd ${CODE_SOURCE} && git checkout ${{ github.event.pull_request.head.sha }} + git remote add mainrepo https://github.com/${{ github.repository }}.git + git fetch mainrepo && git merge --no-edit mainrepo/${{ github.base_ref }} + else + git clone ${{ github.event.repository.clone_url }} ${CODE_SOURCE} && cd ${CODE_SOURCE} + if [ "${{ github.event_name }}" == "pull_request" ]; then + git checkout ${{ github.event.pull_request.head.sha }} && git merge --no-edit ${{ github.base_ref }} + else + git checkout ${{ github.sha }} + fi + fi + git submodule update --init --recursive + - name: checkout clangd-tidy + run: | + set -euo pipefail + source ${PROXY_SOURCE} + set -x + git -c advice.detachedHead=false clone --depth 1 -b v0.1.3 https://github.com/lljbash/clangd-tidy.git ${CLANGD_TIDY_SOURCE} + - name: build + run: | + set -euxo pipefail + srun --job-name=${GITHUB_JOB} bash -c "source ${ENV_SOURCE} && set -euxo pipefail && cd ${CODE_SOURCE} && pip install -e . -v -t install" + - name: clang-tidy + run: | + set -euxo pipefail + srun --job-name=${GITHUB_JOB} bash -c "source ${ENV_SOURCE} && set -euxo pipefail && cd ${CODE_SOURCE} && pwd && git ls-files csrc | xargs ${CLANGD_TIDY_SOURCE}/clangd-tidy --clangd-executable=${CLANGD_EXEC} --github --git-root=${CODE_SOURCE} -j4 -o ${CLANGD_TIDY_LOG}" || (cat ${CLANGD_TIDY_LOG} && false) + - name: cleanup + if: always() + run: | + set -euxo pipefail + rm -rf ${CODE_SOURCE}/build/.cache diff --git a/csrc/diopi_helper.h b/csrc/diopi_helper.h index eb45398e..9756a0b3 100644 --- a/csrc/diopi_helper.h +++ b/csrc/diopi_helper.h @@ -4,20 +4,25 @@ #define DIOPI_HELPER_H_WTUAZNIC #include +#include #include #include +#include #include #include +#include #include -#include + +#include +#include #include #include +#include #include -namespace dipu { -namespace dipu_ext { +namespace dipu::dipu_ext { namespace type_traits { @@ -121,7 +126,6 @@ void callDiopi(const DiopiFunc& diopi_func, Args&&... args) { callDiopiKeepContext(diopi_func, std::forward(args)...); } -} // namespace dipu_ext -} // namespace dipu +} // namespace dipu::dipu_ext #endif /* end of include guard: DIOPI_HELPER_H_WTUAZNIC */ diff --git a/csrc/extensions.cpp b/csrc/extensions.cpp index 7661c01e..8b4c6389 100644 --- a/csrc/extensions.cpp +++ b/csrc/extensions.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -14,7 +15,8 @@ #include #include // IWYU pragma: keep -#include +#include +#include #include @@ -23,8 +25,7 @@ #include "diopi_helper.h" #include "pybind_type_cast.h" -namespace dipu { -namespace dipu_ext { +namespace dipu::dipu_ext { namespace { @@ -297,5 +298,4 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { } } -} // namespace dipu_ext -} // namespace dipu +} // namespace dipu::dipu_ext diff --git a/csrc/pybind_type_cast.h b/csrc/pybind_type_cast.h index 94701d14..6d128981 100644 --- a/csrc/pybind_type_cast.h +++ b/csrc/pybind_type_cast.h @@ -5,24 +5,23 @@ #include -#include +#include #include -#include -#include -#include +#include +#include +#include +#include +#include -namespace dipu { -namespace dipu_ext { +namespace dipu::dipu_ext { using IntArray = std::vector; using OptionalIntArray = c10::optional; -} // namespace dipu_ext -} // namespace dipu +} // namespace dipu::dipu_ext -namespace pybind11 { -namespace detail { +namespace pybind11::detail { namespace py = pybind11; @@ -44,7 +43,6 @@ struct type_caster { } }; -} // namespace detail -} // namespace pybind11 +} // namespace pybind11::detail #endif /* end of include guard: PYBIND_TYPE_CAST_H_PXMGELYW */