Skip to content

Commit

Permalink
Merge pull request slyalin#72 from nosovmik/rebase_with_pdpd_release
Browse files Browse the repository at this point in the history
Align code with pdpd_release branch provided to CI/E2E tests development
  • Loading branch information
nosovmik authored May 31, 2021
2 parents baaff63 + 98b8684 commit 5a9767d
Show file tree
Hide file tree
Showing 65 changed files with 239 additions and 6,313 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ function(build_ngraph)
ngraph_set(NGRAPH_ONNX_IMPORT_ENABLE OFF)
endif()
ngraph_set(NGRAPH_INTERPRETER_ENABLE ON)
ngraph_set(NGRAPH_TF_FRONTEND_ENABLE OFF)
if(NOT (ANDROID OR WIN32 OR ARM OR AARCH64) )
ngraph_set(NGRAPH_PDPD_FRONTEND_ENABLE ON) #TODO: make it OFF by default
else()
Expand Down
20 changes: 11 additions & 9 deletions model-optimizer/mo/front_ng/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from mo.utils.error import Error


def fe_decodeNameWithPort (inputModel, node_name: str):
def fe_decodeNameWithPort(inputModel, node_name: str):
"""
Decode name with optional port specification w/o traversing all the nodes in the graph
:param inputModel: Input Model
Expand Down Expand Up @@ -39,15 +39,17 @@ def fe_decodeNameWithPort (inputModel, node_name: str):


def fe_input_user_data_repack(inputModel, input_user_shapes: [None, list, dict, np.ndarray],
freeze_placeholder: dict, input_user_data_types = dict()):
freeze_placeholder: dict, input_user_data_types=dict()):
"""
Restructures user input cutting request. Splits ports out of node names. Transforms node names to node ids.
Restructures user input cutting request. Splits ports out of node names.
Transforms node names to node ids.
:param graph: graph to operate on
:param input_user_shapes: data structure representing user input cutting request. It may be:
# None value if user did not provide neither --input nor --input_shape keys
# list instance which contains input layer names with or without ports if user provided only --input key
# dict instance which contains input layer names with or without ports as keys and shapes as values if user
provided both --input and --input_shape
# list instance which contains input layer names with or without ports if user provided
only --input key
# dict instance which contains input layer names with or without ports as keys and shapes as
values if user provided both --input and --input_shape
# np.ndarray if user provided only --input_shape key
:param freeze_placeholder: dictionary with placeholder names as keys and freezing value as values
:param input_user_data_types: dictionary with input nodes and its data types
Expand Down Expand Up @@ -136,16 +138,16 @@ def fe_output_user_data_repack(inputModel, outputs: list):


def fe_user_data_repack(inputModel, input_user_shapes: [None, list, dict, np.array],
input_user_data_types: dict, outputs: list, freeze_placeholder: dict):
input_user_data_types: dict, outputs: list, freeze_placeholder: dict):
"""
:param inputModel: Input Model to operate on
:param input_user_shapes: data structure representing user input cutting request
:param outputs: list of node names to treat as outputs
:param freeze_placeholder: dictionary with placeholder names as keys and freezing value as values
:return: restructured input, output and freeze placeholder dictionaries or None values
"""
_input_shapes, _freeze_placeholder = fe_input_user_data_repack(inputModel, input_user_shapes, freeze_placeholder,
input_user_data_types=input_user_data_types)
_input_shapes, _freeze_placeholder = fe_input_user_data_repack(
inputModel, input_user_shapes, freeze_placeholder, input_user_data_types=input_user_data_types)
_outputs = fe_output_user_data_repack(inputModel, outputs)

print('---------- Inputs/outpus/freezePlaceholder -----------')
Expand Down
2 changes: 1 addition & 1 deletion model-optimizer/mo/front_ng/frontendmanager_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def create_fem():
fem = None
try:
from ngraph.frontend import FrontEndManager # pylint: disable=no-name-in-module,import-error
from ngraph.frontend import FrontEndManager # pylint: disable=no-name-in-module,import-error
fem = FrontEndManager()
except Exception:
print("nGraph FrontEndManager is not initialized")
Expand Down
2 changes: 1 addition & 1 deletion model-optimizer/mo/front_ng/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def compare_nodes(old, new):
for i in range(oldPartShape.rank.get_length()):
# Assume batch size is always 1-st dimension in shape
# Keep other dimensions unchanged
newshape.append(Dimension(argv.batch) if i is 0 else oldPartShape.get_dimension(i))
newshape.append(Dimension(argv.batch) if i == 0 else oldPartShape.get_dimension(i))
oldshape_converted.append(oldPartShape.get_dimension(i))

validate_batch_in_shape(oldshape_converted, joinedName)
Expand Down
2 changes: 1 addition & 1 deletion model-optimizer/mo/front_ng/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def ngraph_emit_ir(nGraphFunction, argv: argparse.Namespace):
output_dir = argv.output_dir if argv.output_dir != '.' else os.getcwd()

from ngraph import function_to_cnn # pylint: disable=no-name-in-module,import-error
from ngraph import function_to_cnn # pylint: disable=no-name-in-module,import-error
network = function_to_cnn(nGraphFunction)

orig_model_name = os.path.normpath(os.path.join(output_dir, argv.model_name))
Expand Down
25 changes: 12 additions & 13 deletions ngraph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ option(NGRAPH_INTERPRETER_ENABLE "Control the building of the INTERPRETER backen
option(NGRAPH_DEBUG_ENABLE "Enable output for NGRAPH_DEBUG statements" OFF)
option(NGRAPH_ONNX_IMPORT_ENABLE "Enable ONNX importer" OFF)
option(NGRAPH_ONNX_EDITOR_ENABLE "Enable ONNX Editor" OFF)
option(NGRAPH_TF_FRONTEND_ENABLE "Enable TensorFlow FrontEnd" OFF)
option(NGRAPH_PDPD_FRONTEND_ENABLE "Enable PaddlePaddle FrontEnd" OFF)
option(NGRAPH_LIB_VERSIONING_ENABLE "Enable shared library versioning" OFF)
option(NGRAPH_PYTHON_BUILD_ENABLE "Enable build nGraph python package wheel" OFF)
Expand All @@ -99,7 +98,7 @@ option(NGRAPH_THREAD_SANITIZER_ENABLE "Compiles and links with Thread Sanitizer"
option(NGRAPH_UB_SANITIZER_ENABLE "Compiles and links with Undefined Behavior Sanitizer" OFF)
option(NGRAPH_USE_PROTOBUF_LITE "Compiles and links with protobuf-lite" OFF)

if (NGRAPH_ONNX_IMPORT_ENABLE OR NGRAPH_TF_FRONTEND_ENABLE OR NGRAPH_PDPD_FRONTEND_ENABLE)
if (NGRAPH_ONNX_IMPORT_ENABLE OR NGRAPH_PDPD_FRONTEND_ENABLE)
option(NGRAPH_USE_SYSTEM_PROTOBUF "Use system provided Protobuf shared object" OFF)
endif()
if(NGRAPH_ONNX_EDITOR_ENABLE AND NOT NGRAPH_ONNX_IMPORT_ENABLE)
Expand All @@ -114,7 +113,6 @@ message(STATUS "NGRAPH_INTERPRETER_ENABLE: ${NGRAPH_INTERPRETER_ENABL
message(STATUS "NGRAPH_LIB_VERSIONING_ENABLE: ${NGRAPH_LIB_VERSIONING_ENABLE}")
message(STATUS "NGRAPH_ONNX_IMPORT_ENABLE: ${NGRAPH_ONNX_IMPORT_ENABLE}")
message(STATUS "NGRAPH_ONNX_EDITOR_ENABLE: ${NGRAPH_ONNX_EDITOR_ENABLE}")
message(STATUS "NGRAPH_TF_FRONTEND_ENABLE: ${NGRAPH_TF_FRONTEND_ENABLE}")
message(STATUS "NGRAPH_PDPD_FRONTEND_ENABLE: ${NGRAPH_PDPD_FRONTEND_ENABLE}")
message(STATUS "NGRAPH_PYTHON_BUILD_ENABLE: ${NGRAPH_PYTHON_BUILD_ENABLE}")
message(STATUS "NGRAPH_THREAD_SANITIZER_ENABLE: ${NGRAPH_THREAD_SANITIZER_ENABLE}")
Expand Down Expand Up @@ -295,19 +293,15 @@ if (NGRAPH_EXPORT_TARGETS_ENABLE)
COMPONENT ngraph_dev)
endif()

set(USE_PROTOBUF OFF)
if (NGRAPH_ONNX_IMPORT_ENABLE OR NGRAPH_TF_FRONTEND_ENABLE OR NGRAPH_PDPD_FRONTEND_ENABLE)
set(USE_PROTOBUF ON)
set(USE_STATIC_PROTOBUF OFF)
if (NGRAPH_PDPD_FRONTEND_ENABLE) # add more frontends here
set(USE_STATIC_PROTOBUF ON)
endif()

if (USE_PROTOBUF)
message("Add PROTOBUF dependency")
set(BEFORE_ONNX_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF) # TODO: it was ON for ONNX_IMPORT, but should be fixed

if (NGRAPH_ONNX_IMPORT_ENABLE OR USE_STATIC_PROTOBUF)
if (MSVC)
# When we build dll libraries. These flags make sure protobuf build with /MD, not /MT.
# These two options can't be mixed, because they requires link two incompatible runtime.
# When we build dll libraries. These flags make sure onnx and protobuf build with /MD, not /MT.
# These two options can't be mixed, because they requires link two imcompatiable runtime.
set(protobuf_WITH_ZLIB OFF CACHE BOOL "" FORCE)

if(NOT DEFINED ONNX_USE_MSVC_STATIC_RUNTIME)
Expand All @@ -318,6 +312,10 @@ if (USE_PROTOBUF)
endif()
endif()

set(BEFORE_ONNX_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS ON)
set(BUILD_STANDALONE_STATIC OFF)

if (NOT NGRAPH_USE_SYSTEM_PROTOBUF)
include(cmake/external_protobuf.cmake)
else()
Expand All @@ -336,6 +334,7 @@ if (USE_PROTOBUF)
unset(BEFORE_ONNX_BUILD_SHARED_LIBS)
endif()


add_subdirectory(frontend)

if(NGRAPH_UNIT_TEST_ENABLE)
Expand Down
52 changes: 35 additions & 17 deletions ngraph/cmake/external_protobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,45 @@ if(PROTOC_VERSION VERSION_LESS "3.9" AND NGRAPH_USE_PROTOBUF_LITE)
message(FATAL_ERROR "Minimum supported version of protobuf-lite library is 3.9.0")
else()
if(PROTOC_VERSION VERSION_GREATER_EQUAL "3.0")
FetchContent_Declare(
ext_protobuf
GIT_REPOSITORY ${NGRAPH_PROTOBUF_GIT_REPO_URL}
GIT_TAG ${NGRAPH_PROTOBUF_GIT_TAG}
GIT_SHALLOW TRUE
)

FetchContent_GetProperties(ext_protobuf)
if(NOT ext_protobuf_POPULATED)
FetchContent_Populate(ext_protobuf)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build tests")
set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build with zlib support")
add_subdirectory(${ext_protobuf_SOURCE_DIR}/cmake ${ext_protobuf_BINARY_DIR} EXCLUDE_FROM_ALL)
if (NOT BUILD_STANDALONE_STATIC)
FetchContent_Declare(
ext_protobuf
GIT_REPOSITORY ${NGRAPH_PROTOBUF_GIT_REPO_URL}
GIT_TAG ${NGRAPH_PROTOBUF_GIT_TAG}
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(ext_protobuf)
if(NOT ext_protobuf_POPULATED)
FetchContent_Populate(ext_protobuf)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build tests")
set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build with zlib support")
add_subdirectory(${ext_protobuf_SOURCE_DIR}/cmake ${ext_protobuf_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
endif()
if (USE_STATIC_PROTOBUF)
FetchContent_Declare(
ext_protobuf_static
GIT_REPOSITORY ${NGRAPH_PROTOBUF_GIT_REPO_URL}
GIT_TAG ${NGRAPH_PROTOBUF_GIT_TAG}
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(ext_protobuf_static)
if(NOT ext_protobuf_static_POPULATED AND BUILD_STANDALONE_STATIC)
FetchContent_Populate(ext_protobuf_static)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build tests")
set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build with zlib support")
add_subdirectory(${ext_protobuf_static_SOURCE_DIR}/cmake ${ext_protobuf_static_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
endif()
else()
message(FATAL_ERROR "Minimum supported version of protobuf library is 3.0.0")
endif()

set(Protobuf_INCLUDE_DIRS ${ext_protobuf_SOURCE_DIR}/src)
if (BUILD_STANDALONE_STATIC)
set(Protobuf_INCLUDE_DIRS ${ext_protobuf_static_SOURCE_DIR}/src)
else()
set(Protobuf_INCLUDE_DIRS ${ext_protobuf_SOURCE_DIR}/src)
endif()
if(NGRAPH_USE_PROTOBUF_LITE)
set(Protobuf_LIBRARIES libprotobuf-lite)
else()
Expand Down Expand Up @@ -117,6 +137,7 @@ endif()
# Now make sure we restore the original flags
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE "${PUSH_CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE}")

message("NGRAPH_INSTALL_LIB = ${NGRAPH_INSTALL_LIB}")
install(TARGETS ${Protobuf_LIBRARIES}
RUNTIME DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
ARCHIVE DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
Expand All @@ -125,9 +146,6 @@ if (NGRAPH_EXPORT_TARGETS_ENABLE)
export(TARGETS ${Protobuf_LIBRARIES} NAMESPACE ngraph:: APPEND FILE "${NGRAPH_TARGETS_FILE}")
endif()

message(${ext_protobuf_BINARY_DIR})
#include("${ext_protobuf_BINARY_DIR}/lib/cmake/protobuf/protobuf-module.cmake")

#TODO: ---Find out the way to reuse these function from Protobuf modules ---

function(protobuf_generate)
Expand Down
47 changes: 47 additions & 0 deletions ngraph/frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,53 @@
# SPDX-License-Identifier: Apache-2.0
#

message(${CMAKE_CURRENT_SOURCE_DIR}/cmake_static_protobuf)
message(BINARY ${CMAKE_CURRENT_BINARY_DIR})

## DEBUG - print all variables
# get_cmake_property(_variableNames VARIABLES)
# set(ALL_VARS "")
# foreach (_variableName ${_variableNames})
# set(ALL_VARS ${ALL_VARS} -D${_variableName}=${${_variableName}}\ )
# endforeach()
# message(---------------------ALL VARS: ${ALL_VARS}-------)

# There seems no suitable other way to identify exact output binary name
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(PROTOBUF_STATIC_LIB_OUTPUT ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libprotobufd.a)
else(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(PROTOBUF_STATIC_LIB_OUTPUT ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libprotobuf.a)
endif()

message("Static protobuf lib: ${PROTOBUF_STATIC_LIB_OUTPUT}")
add_custom_command(
OUTPUT
${PROTOBUF_STATIC_LIB_OUTPUT}
COMMAND ${CMAKE_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/cmake_static_protobuf
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=${CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY}
-DCMAKE_PDB_OUTPUT_DIRECTORY=${CMAKE_PDB_OUTPUT_DIRECTORY}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET}
-DNGRAPH_INSTALL_LIB=${NGRAPH_INSTALL_LIB}
${NGRAPH_FORWARD_CMAKE_ARGS}
COMMAND ${CMAKE_COMMAND} --build . --target libprotobuf
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Build Protobuf Static Library"
# TODO: add DEPENDS
)

# Import targets

add_custom_target(libprotobuf_static
DEPENDS
${PROTOBUF_STATIC_LIB_OUTPUT}
)


add_subdirectory(frontend_manager)

if (NGRAPH_PDPD_FRONTEND_ENABLE)
Expand Down
23 changes: 23 additions & 0 deletions ngraph/frontend/cmake_static_protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (C) 2018-2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#

cmake_minimum_required(VERSION 3.13)

project(libprotobuf_static)

# DEBUG - print all defined variables
# get_cmake_property(_variableNames VARIABLES)
# set(ALL_VARS "")
# foreach (_variableName ${_variableNames})
# set(ALL_VARS ${ALL_VARS} -D${_variableName}=${${_variableName}}\n )
# endforeach()
# message("---------------------${ALL_VARS}-------")

message("Add PROTOBUF dependency - static")

set(BUILD_SHARED_LIBS OFF)
set(BUILD_STANDALONE_STATIC ON)
set(USE_STATIC_PROTOBUF ON)

include(../../cmake/external_protobuf.cmake)
7 changes: 4 additions & 3 deletions ngraph/frontend/paddlepaddle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ include_directories(${Protobuf_INCLUDE_DIRS} ${paddlepaddle_ngraph_frontend_INCL
add_library(paddlepaddle_ngraph_frontend SHARED ${LIBRARY_SRC} ${LIBRARY_HEADERS} ${LIBRARY_PUBLIC_HEADERS} ${PROTO_SRCS} ${PROTO_HDRS})
add_library(ngraph::paddlepaddle_ngraph_frontend ALIAS paddlepaddle_ngraph_frontend)

# TODO: fix relative include directory by moving
add_dependencies(paddlepaddle_ngraph_frontend libprotobuf_static)

target_include_directories(paddlepaddle_ngraph_frontend
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/../frontend_manager/include
${FRONTEND_INCLUDE_PATH}
${CMAKE_CURRENT_BINARY_DIR})

if(COMMAND ie_add_vs_version_file)
ie_add_vs_version_file(NAME paddlepaddle_ngraph_frontend
FILEDESCRIPTION "FrontEnd to load and convert PaddlePaddle file format")
endif()

target_link_libraries(paddlepaddle_ngraph_frontend PRIVATE ${Protobuf_LIBRARIES} PUBLIC ngraph PRIVATE ngraph::builder)
target_link_libraries(paddlepaddle_ngraph_frontend PRIVATE ${PROTOBUF_STATIC_LIB_OUTPUT} PUBLIC ngraph PRIVATE ngraph::builder)
target_link_libraries(paddlepaddle_ngraph_frontend PRIVATE frontend_manager)

add_clang_format_target(paddlepaddle_ngraph_frontend_clang FOR_TARGETS paddlepaddle_ngraph_frontend
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
//*****************************************************************************
// Copyright 2017-2021 Intel Corporation
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
// 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.
//*****************************************************************************

#pragma once

Expand Down
16 changes: 2 additions & 14 deletions ngraph/frontend/paddlepaddle/src/decoder.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
//*****************************************************************************
// Copyright 2017-2021 Intel Corporation
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
// 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.
//*****************************************************************************

#pragma once

Expand Down
16 changes: 2 additions & 14 deletions ngraph/frontend/paddlepaddle/src/node_context.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
//*****************************************************************************
// Copyright 2017-2021 Intel Corporation
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
// 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.
//*****************************************************************************

#pragma once
#include <paddlepaddle_frontend/exceptions.hpp>
Expand Down
Loading

0 comments on commit 5a9767d

Please sign in to comment.