Skip to content

Commit

Permalink
build: add static check workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
lljbash committed Feb 4, 2024
1 parent 1daed20 commit 290254f
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 35 deletions.
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
72 changes: 72 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: static checks on sco

on:
workflow_dispatch:
push:
branches:
- main
pull_request:

env:
ENV_SOURCE: /mnt/cache/share/platform/env/dipu_latest
PROXY_SOURCE: /mnt/cache/share/platform/env/proxy
WORKSPACE: /mnt/cache/share/deeplinkci/github/${{ github.repository }}/${{ github.run_number }}
CODE_SOURCE: source
CLANGD_TIDY_SOURCE: clangd-tidy
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:
checkout-code:
name: checkout code
runs-on: tps-sco-ci
steps:
- name: prepare workspace
run: |
set -euxo pipefail
mkdir -p ${WORKSPACE} && cd ${WORKSPACE} && pwd
- name: checkout code
run: |
set -euo pipefail
source ${PROXY_SOURCE}
set -x
cd ${WORKSPACE} && pwd
[[ ! -d ${CODE_SOURCE} ]] || 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
cd ${WORKSPACE}/${CODE_SOURCE} && pwd
git -c advice.detachedHead=false clone --depth 1 -b v0.1.3 https://github.com/lljbash/clangd-tidy.git ${CLANGD_TIDY_SOURCE}
build-and-tidy:
name: build and tidy
runs-on: tps-sco-ci
needs: [checkout-code]
steps:
- name: build
run: |
set -euxo pipefail
srun --job-name=${GITHUB_JOB} bash -c "source ${ENV_SOURCE} && cd ${WORKSPACE}/${CODE_SOURCE} && pwd && pip install -e . -v -t install"
- name: clang-tidy
run: |
set -euxo pipefail
srun --job-name=${GITHUB_JOB} bash -c "source ${ENV_SOURCE} && cd ${WORKSPACE}/${CODE_SOURCE} && pwd && git ls-files csrc | xargs ${CLANGD_TIDY_SOURCE}/clangd-tidy --clangd-executable=${CLANGD_EXEC} --github --git-root=${WORKSPACE}/${CODE_SOURCE} -j4 -o clang-tidy.log" || (cat ${WORKSPACE}/${CODE_SOURCE}/clang-tidy.log && false)
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 */

0 comments on commit 290254f

Please sign in to comment.