Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add static check workflow #45

Merged
merged 2 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -34,7 +23,6 @@ readability-*,
'
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
#WarningsAsErrors: '*'
FormatStyle: file
CheckOptions:
- key: cppcoreguidelines-avoid-do-while.IgnoreMacros
Expand Down
5 changes: 5 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CompileFlags:
Remove: -fabi*
Diagnostics:
UnusedIncludes: Strict
MissingIncludes: Strict
81 changes: 81 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 9 additions & 5 deletions csrc/diopi_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@
#define DIOPI_HELPER_H_WTUAZNIC

#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>

#include <ATen/core/ATen_fwd.h>
#include <ATen/core/Generator.h>
#include <ATen/core/TensorBody.h>
#include <c10/core/DeviceType.h>
#include <c10/util/Optional.h>
#include <c10/util/OptionalArrayRef.h>

#include <diopi/diopirt.h>
#include <diopi/functions.h>

#include <csrc_dipu/base/basedef.h>
#include <csrc_dipu/diopirt/diopirt_impl.h>
#include <csrc_dipu/runtime/core/DIPUStream.h>
#include <csrc_dipu/runtime/device/basedef.h>

namespace dipu {
namespace dipu_ext {
namespace dipu::dipu_ext {

namespace type_traits {

Expand Down Expand Up @@ -121,7 +126,6 @@ void callDiopi(const DiopiFunc& diopi_func, Args&&... args) {
callDiopiKeepContext(diopi_func, std::forward<Args>(args)...);
}

} // namespace dipu_ext
} // namespace dipu
} // namespace dipu::dipu_ext

#endif /* end of include guard: DIOPI_HELPER_H_WTUAZNIC */
10 changes: 5 additions & 5 deletions csrc/extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstdint>
#include <tuple>
#include <utility>
#include <vector>

#include <ATen/core/ATen_fwd.h>
Expand All @@ -14,7 +15,8 @@
#include <c10/util/OptionalArrayRef.h>
#include <torch/csrc/utils/pybind.h> // IWYU pragma: keep

#include <pybind11/pybind11.h>
#include <pybind11/cast.h>
#include <pybind11/detail/common.h>

#include <diopi/functions_ext.h>

Expand All @@ -23,8 +25,7 @@
#include "diopi_helper.h"
#include "pybind_type_cast.h"

namespace dipu {
namespace dipu_ext {
namespace dipu::dipu_ext {

namespace {

Expand Down Expand Up @@ -297,5 +298,4 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
}
}

} // namespace dipu_ext
} // namespace dipu
} // namespace dipu::dipu_ext
22 changes: 10 additions & 12 deletions csrc/pybind_type_cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@

#include <vector>

#include <c10/util/ArrayRef.h>
#include <ATen/core/ATen_fwd.h>
#include <c10/util/Optional.h>
#include <c10/util/OptionalArrayRef.h>
#include <torch/types.h>

#include <pybind11/pybind11.h>
#include <Python.h>
#include <listobject.h>
#include <pybind11/cast.h>
#include <pybind11/detail/descr.h>
#include <pybind11/pytypes.h>

namespace dipu {
namespace dipu_ext {
namespace dipu::dipu_ext {

using IntArray = std::vector<at::IntArrayRef::value_type>;
using OptionalIntArray = c10::optional<IntArray>;

} // namespace dipu_ext
} // namespace dipu
} // namespace dipu::dipu_ext

namespace pybind11 {
namespace detail {
namespace pybind11::detail {

namespace py = pybind11;

Expand All @@ -44,7 +43,6 @@ struct type_caster<at::OptionalIntArrayRef> {
}
};

} // namespace detail
} // namespace pybind11
} // namespace pybind11::detail

#endif /* end of include guard: PYBIND_TYPE_CAST_H_PXMGELYW */