Added NCC style for frontends sources (#16200)
* Ability to provide several source dirs for ncc-style checks * Fixed include headers; added NCC to TF common * Fixed NCC for frontends * Fixed NCC for frontends * Extra fixes * Fixest push --f * Clang-format * Apply comments * Add an option to specify required clang-format version * Update src/frontends/tensorflow/src/decoder_proto.cpp * Update src/frontends/tensorflow/src/decoder_proto.cpp
This commit is contained in:
@@ -3,23 +3,23 @@
|
||||
#
|
||||
|
||||
if(ENABLE_CLANG_FORMAT)
|
||||
set(clang_format_required_version 9)
|
||||
set(CLANG_FORMAT_FILENAME clang-format-${clang_format_required_version} clang-format)
|
||||
set(CLANG_FORMAT_REQUIRED_VERSION 9 CACHE STRING "Clang-format version to use")
|
||||
set(CLANG_FORMAT_FILENAME clang-format-${CLANG_FORMAT_REQUIRED_VERSION} clang-format)
|
||||
find_host_program(CLANG_FORMAT NAMES ${CLANG_FORMAT_FILENAME} PATHS ENV PATH)
|
||||
if(CLANG_FORMAT)
|
||||
execute_process(COMMAND ${CLANG_FORMAT} ${CMAKE_CURRENT_SOURCE_DIR} ARGS --version OUTPUT_VARIABLE CLANG_VERSION)
|
||||
if(NOT CLANG_VERSION)
|
||||
message(WARNING "Supported clang-format version is ${clang_format_required_version}!")
|
||||
message(WARNING "Supported clang-format version is ${CLANG_FORMAT_REQUIRED_VERSION}!")
|
||||
set(ENABLE_CLANG_FORMAT OFF)
|
||||
else()
|
||||
string(REGEX REPLACE "[^0-9]+([0-9]+)\\..*" "\\1" CLANG_FORMAT_MAJOR_VERSION ${CLANG_VERSION})
|
||||
if(NOT CLANG_FORMAT_MAJOR_VERSION EQUAL clang_format_required_version)
|
||||
if(NOT CLANG_FORMAT_MAJOR_VERSION EQUAL CLANG_FORMAT_REQUIRED_VERSION)
|
||||
message(WARNING "Supported clang-format version is 9! Provided version ${CLANG_FORMAT_MAJOR_VERSION}")
|
||||
set(ENABLE_CLANG_FORMAT OFF)
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
message(WARNING "Supported clang-format-${clang_format_required_version} is not found!")
|
||||
message(WARNING "Supported clang-format-${CLANG_FORMAT_REQUIRED_VERSION} is not found!")
|
||||
set(ENABLE_CLANG_FORMAT OFF)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -33,7 +33,7 @@ if (ENABLE_UB_SANITIZER)
|
||||
# https://github.com/KhronosGroup/OpenCL-CLHPP/issues/17
|
||||
# Mute -fsanitize=function Indirect call of a function through a function pointer of the wrong type.
|
||||
# Sample cases:
|
||||
# call to function GetAPIVersion through pointer to incorrect function type 'void *(*)()'
|
||||
# call to function get_api_version through pointer to incorrect function type 'void *(*)()'
|
||||
# Mute -fsanitize=alignment Use of a misaligned pointer or creation of a misaligned reference. Also sanitizes assume_aligned-like attributes.
|
||||
# Sample cases:
|
||||
# VPU_FixedMaxHeapTest.DefaultConstructor test case load of misaligned address 0x62000000187f for type 'const DataType', which requires 4 byte alignment
|
||||
|
||||
@@ -15,8 +15,8 @@ set(OV_FRONTEND_MAP_DEFINITION " FrontendsStaticRegistry registry = {")
|
||||
|
||||
foreach(frontend IN LISTS FRONTEND_NAMES)
|
||||
# common
|
||||
set(_OV_FRONTEND_DATA_FUNC "GetFrontEndData${frontend}")
|
||||
set(_OV_VERSION_FUNC "GetAPIVersion${frontend}")
|
||||
set(_OV_FRONTEND_DATA_FUNC "get_front_end_data_${frontend}")
|
||||
set(_OV_VERSION_FUNC "get_api_version_${frontend}")
|
||||
|
||||
# declarations
|
||||
set(OV_FRONTEND_DECLARATIONS "${OV_FRONTEND_DECLARATIONS}
|
||||
|
||||
@@ -190,21 +190,8 @@ macro(ov_add_frontend)
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
# override default function names
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE
|
||||
"-DGetFrontEndData=GetFrontEndData${OV_FRONTEND_NAME}"
|
||||
"-DGetAPIVersion=GetAPIVersion${OV_FRONTEND_NAME}")
|
||||
endif()
|
||||
|
||||
# enable LTO
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES
|
||||
INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
|
||||
|
||||
if(OV_FRONTEND_SKIP_NCC_STYLE)
|
||||
# frontend's CMakeLists.txt must define its own custom 'ov_ncc_naming_style' step
|
||||
else()
|
||||
ov_ncc_naming_style(FOR_TARGET ${TARGET_NAME}
|
||||
SOURCE_DIRECTORY "${frontend_root_dir}/include"
|
||||
ADDITIONAL_INCLUDE_DIRECTORIES
|
||||
$<TARGET_PROPERTY:frontend_common::static,INTERFACE_INCLUDE_DIRECTORIES>)
|
||||
"-Dget_front_end_data=get_front_end_data_${OV_FRONTEND_NAME}"
|
||||
"-Dget_api_version=get_api_version_${OV_FRONTEND_NAME}")
|
||||
endif()
|
||||
|
||||
target_include_directories(${TARGET_NAME}
|
||||
@@ -255,6 +242,21 @@ macro(ov_add_frontend)
|
||||
add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}
|
||||
EXCLUDE_PATTERNS ${PROTO_SRCS} ${PROTO_HDRS} ${proto_files} ${flatbuffers_schema_files})
|
||||
|
||||
# enable LTO
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES
|
||||
INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
|
||||
|
||||
if(OV_FRONTEND_SKIP_NCC_STYLE)
|
||||
# frontend's CMakeLists.txt must define its own custom 'ov_ncc_naming_style' step
|
||||
else()
|
||||
ov_ncc_naming_style(FOR_TARGET ${TARGET_NAME}
|
||||
SOURCE_DIRECTORIES "${frontend_root_dir}/include"
|
||||
"${frontend_root_dir}/src"
|
||||
ADDITIONAL_INCLUDE_DIRECTORIES
|
||||
$<TARGET_PROPERTY:${TARGET_NAME},INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:${TARGET_NAME},INCLUDE_DIRECTORIES>)
|
||||
endif()
|
||||
|
||||
add_dependencies(ov_frontends ${TARGET_NAME})
|
||||
|
||||
# must be called after all target_link_libraries
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
|
||||
namespace {
|
||||
|
||||
using GetFrontEndDataFunc = void*();
|
||||
using GetAPIVersionFunc = ov::frontend::FrontEndVersion();
|
||||
using get_front_end_data_func = void*();
|
||||
using get_api_version_func = ov::frontend::FrontEndVersion();
|
||||
|
||||
struct Value {
|
||||
GetFrontEndDataFunc* m_dataFunc;
|
||||
GetAPIVersionFunc* m_versionFunc;
|
||||
get_front_end_data_func* m_dataFunc;
|
||||
get_api_version_func* m_versionFunc;
|
||||
};
|
||||
|
||||
using FrontendsStaticRegistry = std::vector<Value>;
|
||||
|
||||
@@ -112,13 +112,13 @@ endif()
|
||||
|
||||
#
|
||||
# ov_ncc_naming_style(FOR_TARGET target_name
|
||||
# SOURCE_DIRECTORY dir
|
||||
# [SOURCE_DIRECTORIES dir1 dir2 ...]
|
||||
# [STYLE_FILE style_file.style]
|
||||
# [ADDITIONAL_INCLUDE_DIRECTORIES dir1 dir2 ..]
|
||||
# [DEFINITIONS def1 def2 ..])
|
||||
#
|
||||
# FOR_TARGET - name of the target
|
||||
# SOURCE_DIRECTORY - directory to check sources from
|
||||
# SOURCE_DIRECTORIES - directory to check sources from
|
||||
# STYLE_FILE - path to the specific style file
|
||||
# ADDITIONAL_INCLUDE_DIRECTORIES - additional include directories used in checked headers
|
||||
# DEFINITIONS - additional definitions passed to preprocessor stage
|
||||
@@ -129,9 +129,9 @@ function(ov_ncc_naming_style)
|
||||
endif()
|
||||
|
||||
cmake_parse_arguments(NCC_STYLE "FAIL"
|
||||
"FOR_TARGET;SOURCE_DIRECTORY;STYLE_FILE" "ADDITIONAL_INCLUDE_DIRECTORIES;DEFINITIONS" ${ARGN})
|
||||
"FOR_TARGET;STYLE_FILE" "SOURCE_DIRECTORIES;ADDITIONAL_INCLUDE_DIRECTORIES;DEFINITIONS" ${ARGN})
|
||||
|
||||
foreach(var FOR_TARGET SOURCE_DIRECTORY)
|
||||
foreach(var FOR_TARGET SOURCE_DIRECTORIES)
|
||||
if(NOT DEFINED NCC_STYLE_${var})
|
||||
message(FATAL_ERROR "${var} is not defined in ov_ncc_naming_style function")
|
||||
endif()
|
||||
@@ -141,18 +141,18 @@ function(ov_ncc_naming_style)
|
||||
set(NCC_STYLE_STYLE_FILE ${ncc_style_dir}/openvino.style)
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE sources
|
||||
RELATIVE "${NCC_STYLE_SOURCE_DIRECTORY}"
|
||||
"${NCC_STYLE_SOURCE_DIRECTORY}/*.hpp"
|
||||
"${NCC_STYLE_SOURCE_DIRECTORY}/*.cpp")
|
||||
foreach(source_dir IN LISTS NCC_STYLE_SOURCE_DIRECTORIES)
|
||||
file(GLOB_RECURSE local_sources "${source_dir}/*.hpp" "${source_dir}/*.cpp")
|
||||
list(APPEND sources ${local_sources})
|
||||
endforeach()
|
||||
|
||||
list(APPEND NCC_STYLE_ADDITIONAL_INCLUDE_DIRECTORIES "${NCC_STYLE_SOURCE_DIRECTORY}")
|
||||
# without it sources with same name from different directories will map to same .ncc_style target
|
||||
file(RELATIVE_PATH source_dir_rel ${CMAKE_SOURCE_DIR} ${NCC_STYLE_SOURCE_DIRECTORY})
|
||||
list(APPEND NCC_STYLE_ADDITIONAL_INCLUDE_DIRECTORIES ${NCC_STYLE_SOURCE_DIRECTORIES})
|
||||
|
||||
foreach(source IN LISTS sources)
|
||||
set(output_file "${ncc_style_bin_dir}/${source_dir_rel}/${source}.ncc_style")
|
||||
set(full_source_path "${NCC_STYLE_SOURCE_DIRECTORY}/${source}")
|
||||
foreach(source_file IN LISTS sources)
|
||||
get_filename_component(source_dir "${source_file}" DIRECTORY)
|
||||
file(RELATIVE_PATH source_dir_rel "${CMAKE_SOURCE_DIR}" "${source_dir}")
|
||||
get_filename_component(source_name "${source_file}" NAME)
|
||||
set(output_file "${ncc_style_bin_dir}/${source_dir_rel}/${source_name}.ncc_style")
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
@@ -161,7 +161,7 @@ function(ov_ncc_naming_style)
|
||||
"${CMAKE_COMMAND}"
|
||||
-D "PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}"
|
||||
-D "NCC_PY_SCRIPT=${ncc_script_py}"
|
||||
-D "INPUT_FILE=${full_source_path}"
|
||||
-D "INPUT_FILE=${source_file}"
|
||||
-D "OUTPUT_FILE=${output_file}"
|
||||
-D "DEFINITIONS=${NCC_STYLE_DEFINITIONS}"
|
||||
-D "CLANG_LIB_PATH=${libclang_location}"
|
||||
@@ -170,12 +170,12 @@ function(ov_ncc_naming_style)
|
||||
-D "EXPECTED_FAIL=${NCC_STYLE_FAIL}"
|
||||
-P "${ncc_style_dir}/ncc_run.cmake"
|
||||
DEPENDS
|
||||
"${full_source_path}"
|
||||
"${source_file}"
|
||||
"${ncc_style_dir}/openvino.style"
|
||||
"${ncc_script_py}"
|
||||
"${ncc_style_dir}/ncc_run.cmake"
|
||||
COMMENT
|
||||
"[ncc naming style] ${source}"
|
||||
"[ncc naming style] ${source_dir_rel}/${source_name}"
|
||||
VERBATIM)
|
||||
list(APPEND output_files ${output_file})
|
||||
endforeach()
|
||||
@@ -191,6 +191,6 @@ endfunction()
|
||||
|
||||
if(TARGET ncc_all)
|
||||
ov_ncc_naming_style(FOR_TARGET ncc_all
|
||||
SOURCE_DIRECTORY "${ncc_style_dir}/self_check"
|
||||
SOURCE_DIRECTORIES "${ncc_style_dir}/self_check"
|
||||
FAIL)
|
||||
endif()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# custom OpenVINO values
|
||||
CppMethod: '^(operator\W+|[a-z_\d]+|signaling_NaN|quiet_NaN)$'
|
||||
ClassName: '^([A-Z][\w]+|b?float16|numeric_limits|ngraph_error|stopwatch|unsupported_op)$'
|
||||
StructName: '^([A-Z][\w]+|element_type_traits|hash|oi_pair)$'
|
||||
StructName: '^([A-Z][\w]+|element_type_traits|hash|oi_pair|stat)$'
|
||||
FunctionName: '^(operator\W+|[a-z_\d]+)|PrintTo$'
|
||||
Namespace: '^([a-z\d_]*|InferenceEngine)$'
|
||||
NamespaceAlias: '^([a-z\d_]+|InferenceEngine)$'
|
||||
@@ -27,7 +27,7 @@ CxxDynamicCastExpression: '^.*$'
|
||||
# not needed values
|
||||
ClassTemplatePartialSpecialization: '^.*$'
|
||||
ConversionFunction: '^.*$'
|
||||
UsingDirective: 'XXXX'
|
||||
UsingDirective: '^.*$'
|
||||
ClassAccessSpecifier: '^.*$' # looks like can be fixed
|
||||
TypeReference: '^.*$' # looks like can be fixed
|
||||
CxxBaseSpecifier: '^.*$' # looks like can be fixed
|
||||
|
||||
Reference in New Issue
Block a user