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

【code format check upgrade】 step2:cmake-format #43057

Merged
merged 2 commits into from
Jun 4, 2022
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
125 changes: 125 additions & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# -----------------------------
# Options affecting formatting.
# -----------------------------
with section("format"):

# How wide to allow formatted cmake files
line_width = 80

# ------------------------------------------------
# Options affecting comment reflow and formatting.
# ------------------------------------------------
with section("markup"):
# enable comment markup parsing and reflow
enable_markup = False

# If comment markup is enabled, don't reflow the first comment block in each
# listfile. Use this to preserve formatting of your copyright/license
# statements.
first_comment_is_literal = True

# ----------------------------------
# Options affecting listfile parsing
# ----------------------------------
with section("parse"):
# Additional FLAGS and KWARGS for custom commands
additional_commands = {
"cc_library": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"nv_library": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"hip_library": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"xpu_library": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"hip_library": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"hip_library": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"go_library": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"copy": {
"kwargs": {
"SRCS": '*',
"DSTS": '*',
}
},
"cc_test": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"nv_test": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"hip_test": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"xpu_test": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"go_test": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"py_test": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
}
}
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,13 @@ repos:
(?x)^(
paddle/utils/.*
)$
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
# exclude paddle/fluid/operators/CMakeLists.txt, see the comment
# https://github.com/PaddlePaddle/Paddle/pull/43057#pullrequestreview-993471860
exclude: |
(?x)^(
paddle/fluid/operators/CMakeLists.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请问这个exclude是有什么考虑么?后面会移走么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该文件格式化之后inference流水线报错,原因为tools/remove_grad_op_and_kernel.py需要对该文件进行修改,格式化后读取该文件出错。
报错截图:
image

tools/remove_grad_op_and_kernel.py代码截图:
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

明白了,remove_grad_op_and_kernel.py 是推理用来裁剪反向Op的,可以后续看下如何格式化

)$
45 changes: 22 additions & 23 deletions cmake/FindGperftools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,46 @@
# GPERFTOOLS_LIBRARIES The Gperftools libraries (tcmalloc & profiler)
# GPERFTOOLS_INCLUDE_DIR The location of Gperftools headers

find_library(GPERFTOOLS_TCMALLOC
find_library(
GPERFTOOLS_TCMALLOC
NAMES tcmalloc
HINTS ${Gperftools_ROOT_DIR}/lib)

find_library(GPERFTOOLS_PROFILER

find_library(
GPERFTOOLS_PROFILER
NAMES profiler
HINTS ${Gperftools_ROOT_DIR}/lib)

find_library(GPERFTOOLS_TCMALLOC_AND_PROFILER
find_library(
GPERFTOOLS_TCMALLOC_AND_PROFILER
NAMES tcmalloc_and_profiler
HINTS ${Gperftools_ROOT_DIR}/lib)

find_path(GPERFTOOLS_INCLUDE_DIR
find_path(
GPERFTOOLS_INCLUDE_DIR
NAMES gperftools/heap-profiler.h
HINTS ${Gperftools_ROOT_DIR}/include)

set(GPERFTOOLS_LIBRARIES ${GPERFTOOLS_TCMALLOC_AND_PROFILER})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
Gperftools
DEFAULT_MSG
GPERFTOOLS_LIBRARIES
GPERFTOOLS_INCLUDE_DIR)
find_package_handle_standard_args(Gperftools DEFAULT_MSG GPERFTOOLS_LIBRARIES
GPERFTOOLS_INCLUDE_DIR)

mark_as_advanced(
Gperftools_ROOT_DIR
GPERFTOOLS_TCMALLOC
GPERFTOOLS_PROFILER
GPERFTOOLS_TCMALLOC_AND_PROFILER
GPERFTOOLS_LIBRARIES
GPERFTOOLS_INCLUDE_DIR)
Gperftools_ROOT_DIR GPERFTOOLS_TCMALLOC GPERFTOOLS_PROFILER
GPERFTOOLS_TCMALLOC_AND_PROFILER GPERFTOOLS_LIBRARIES GPERFTOOLS_INCLUDE_DIR)

# create IMPORTED targets
if (Gperftools_FOUND AND NOT TARGET gperftools::tcmalloc)
if(Gperftools_FOUND AND NOT TARGET gperftools::tcmalloc)
add_library(gperftools::tcmalloc UNKNOWN IMPORTED)
set_target_properties(gperftools::tcmalloc PROPERTIES
IMPORTED_LOCATION ${GPERFTOOLS_TCMALLOC}
INTERFACE_INCLUDE_DIRECTORIES "${GPERFTOOLS_INCLUDE_DIR}")
set_target_properties(
gperftools::tcmalloc
PROPERTIES IMPORTED_LOCATION ${GPERFTOOLS_TCMALLOC}
INTERFACE_INCLUDE_DIRECTORIES "${GPERFTOOLS_INCLUDE_DIR}")
add_library(gperftools::profiler UNKNOWN IMPORTED)
set_target_properties(gperftools::profiler PROPERTIES
IMPORTED_LOCATION ${GPERFTOOLS_PROFILER}
INTERFACE_INCLUDE_DIRECTORIES "${GPERFTOOLS_INCLUDE_DIR}")
set_target_properties(
gperftools::profiler
PROPERTIES IMPORTED_LOCATION ${GPERFTOOLS_PROFILER}
INTERFACE_INCLUDE_DIRECTORIES "${GPERFTOOLS_INCLUDE_DIR}")
endif()
13 changes: 8 additions & 5 deletions cmake/FindNumPy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,27 @@ if(NOT PYTHON_EXECUTABLE)
endif()
endif()

if (PYTHON_EXECUTABLE)
if(PYTHON_EXECUTABLE)
# write a python script that finds the numpy path
file(WRITE ${PROJECT_BINARY_DIR}/FindNumpyPath.py
"try: import numpy; print(numpy.get_include())\nexcept:pass\n")
"try: import numpy; print(numpy.get_include())\nexcept:pass\n")

# execute the find script
exec_program("${PYTHON_EXECUTABLE}" ${PROJECT_BINARY_DIR}
exec_program(
"${PYTHON_EXECUTABLE}" ${PROJECT_BINARY_DIR}
ARGS "FindNumpyPath.py"
OUTPUT_VARIABLE NUMPY_PATH)
elseif(_numpy_out)
message(STATUS "Python executable not found.")
endif(PYTHON_EXECUTABLE)

find_path(PYTHON_NUMPY_INCLUDE_DIR numpy/arrayobject.h
HINTS "${NUMPY_PATH}" "${PYTHON_INCLUDE_PATH}")
HINTS "${NUMPY_PATH}" "${PYTHON_INCLUDE_PATH}")

if(PYTHON_NUMPY_INCLUDE_DIR)
set(PYTHON_NUMPY_FOUND 1 CACHE INTERNAL "Python numpy found")
set(PYTHON_NUMPY_FOUND
1
CACHE INTERNAL "Python numpy found")
endif(PYTHON_NUMPY_INCLUDE_DIR)

include(FindPackageHandleStandardArgs)
Expand Down
Loading