Create a separate component for graph optimization. (#421)

* Create a project for graph optimizer.

Move optimizer related code to the folder optimizer.

* Fix build failures.

* rebase and fix build failures.

* fix build failure.

* fix build failure with cuda path.

* fix python build failure.

* Move two transformers(memcpy and insert_cast) from framework to optimizer.

* rebase.

* SessionState should not depend on optimizer.
This commit is contained in:
Weixing Zhang 2019-02-04 15:45:12 -08:00 committed by GitHub
parent 737700f94f
commit 696ab8a194
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 78 additions and 61 deletions

View file

@ -513,6 +513,7 @@ include(onnxruntime_framework.cmake)
include(onnxruntime_util.cmake)
#The next file will define 'onnxruntime_libs' cmake var
include(onnxruntime_providers.cmake)
include(onnxruntime_optimizer.cmake)
include(onnxruntime_session.cmake)
include(onnxruntime_mlas.cmake)

View file

@ -49,6 +49,7 @@ target_link_libraries(onnxruntime PRIVATE
${onnxruntime_libs}
${PROVIDERS_CUDA}
${PROVIDERS_MKLDNN}
onnxruntime_optimizer
onnxruntime_providers
onnxruntime_util
${onnxruntime_tvm_libs}

View file

@ -0,0 +1,16 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
file(GLOB onnxruntime_optimizer_srcs
"${ONNXRUNTIME_ROOT}/core/optimizer/*.h"
"${ONNXRUNTIME_ROOT}/core/optimizer/*.cc"
)
source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_optimizer_srcs})
add_library(onnxruntime_optimizer ${onnxruntime_optimizer_srcs})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/optimizer DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core)
onnxruntime_add_include_to_target(onnxruntime_optimizer onnxruntime_common onnxruntime_framework gsl onnx onnx_proto protobuf::libprotobuf)
target_include_directories(onnxruntime_optimizer PRIVATE ${ONNXRUNTIME_ROOT})
add_dependencies(onnxruntime_optimizer ${onnxruntime_EXTERNAL_DEPENDENCIES})
set_target_properties(onnxruntime_optimizer PROPERTIES FOLDER "ONNXRuntime")

View file

@ -58,6 +58,7 @@ set(onnxruntime_pybind11_state_libs
${onnxruntime_libs}
${PROVIDERS_CUDA}
${PROVIDERS_MKLDNN}
onnxruntime_optimizer
onnxruntime_providers
onnxruntime_util
${onnxruntime_tvm_libs}

View file

@ -135,6 +135,7 @@ set(onnxruntime_test_ir_libs
set(onnxruntime_test_framework_libs
onnxruntime_test_utils_for_framework
onnxruntime_optimizer
onnxruntime_framework
onnxruntime_util
onnxruntime_graph
@ -175,6 +176,7 @@ set(ONNXRUNTIME_TEST_LIBS
${onnxruntime_libs}
${PROVIDERS_CUDA}
${PROVIDERS_MKLDNN}
onnxruntime_optimizer
onnxruntime_providers
onnxruntime_util
${onnxruntime_tvm_libs}

View file

@ -5,7 +5,7 @@
#include "core/common/common.h"
#include "core/graph/graph_viewer.h"
#include "core/graph/rewrite_rule.h"
#include "core/optimizer/rewrite_rule.h"
namespace onnxruntime {

View file

@ -10,11 +10,7 @@
#include "core/common/logging/logging.h"
#include "core/graph/graph_viewer.h"
#include "core/graph/graph_transformer.h"
#include "core/graph/graph_transformer_mgr.h"
#include "core/framework/graph_partitioner.h"
#include "core/framework/insert_cast_transformer.h"
#include "core/framework/ml_value.h"
#include "core/framework/ml_value_patterns_planner.h"
#include "core/framework/mlvalue_name_idx_map.h"
@ -22,7 +18,6 @@
#include "core/framework/session_state.h"
#include "core/framework/tensorutils.h"
#include "core/framework/tensorprotoutils.h"
#include "core/framework/transformer_memcpy.h"
#include "core/framework/utils.h"
namespace onnxruntime {

View file

@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "core/graph/initializer.h"
#include "core/graph/conv_activation_fusion.h"
#include "core/graph/graph_utils.h"
#include <deque>
#include "core/graph/graph_utils.h"
#include "core/optimizer/initializer.h"
#include "core/optimizer/conv_activation_fusion.h"
using namespace onnx;
using namespace ::onnxruntime::common;

View file

@ -3,7 +3,7 @@
#pragma once
#include "core/graph/graph_transformer.h"
#include "core/optimizer/graph_transformer.h"
namespace onnxruntime {

View file

@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "core/graph/initializer.h"
#include "core/graph/graph_utils.h"
#include "core/graph/conv_add_fusion.h"
#include "core/optimizer/initializer.h"
#include "core/optimizer/conv_add_fusion.h"
using namespace onnx;
using namespace ::onnxruntime::common;

View file

@ -3,7 +3,7 @@
#pragma once
#include "core/graph/graph_transformer.h"
#include "core/optimizer/graph_transformer.h"
namespace onnxruntime {

View file

@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "core/graph/initializer.h"
#include "core/graph/graph_utils.h"
#include "core/graph/conv_bn_fusion.h"
#include "core/optimizer/initializer.h"
#include "core/optimizer/conv_bn_fusion.h"
using namespace onnx;
using namespace ::onnxruntime::common;

View file

@ -3,7 +3,7 @@
#pragma once
#include "core/graph/graph_transformer.h"
#include "core/optimizer/graph_transformer.h"
namespace onnxruntime {

View file

@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "core/graph/initializer.h"
#include "core/graph/graph_utils.h"
#include "core/graph/conv_mul_fusion.h"
#include "core/optimizer/initializer.h"
#include "core/optimizer/conv_mul_fusion.h"
using namespace onnx;
using namespace ::onnxruntime::common;

View file

@ -2,7 +2,7 @@
// Licensed under the MIT License.
#pragma once
#include "core/graph/graph_transformer.h"
#include "core/optimizer/graph_transformer.h"
namespace onnxruntime {

View file

@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "core/graph/initializer.h"
#include "core/graph/gemm_activation_fusion.h"
#include "core/optimizer/initializer.h"
#include "core/optimizer/gemm_activation_fusion.h"
#include "core/graph/graph_utils.h"
#include <deque>

View file

@ -3,7 +3,7 @@
#pragma once
#include "core/graph/graph_transformer.h"
#include "core/optimizer/graph_transformer.h"
namespace onnxruntime {

View file

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "core/graph/graph_transformer.h"
#include "core/optimizer/graph_transformer.h"
using namespace ::onnxruntime::common;

View file

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "core/graph/graph_transformer_mgr.h"
#include "core/optimizer/graph_transformer_mgr.h"
using namespace onnxruntime;
using namespace ::onnxruntime::common;

View file

@ -3,7 +3,7 @@
#pragma once
#include "core/graph/graph_transformer.h"
#include "core/optimizer/graph_transformer.h"
namespace onnxruntime {
// Manages a list of graph transformers. It is initialized with a list of graph

View file

@ -1,8 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "core/graph/identity_elimination.h"
#include "core/common/logging/logging.h"
#include "core/graph/graph_viewer.h"
#include "core/graph/op.h"
#include "core/graph/graph_utils.h"
#include "core/optimizer/rewrite_rule.h"
#include "core/optimizer/identity_elimination.h"
namespace onnxruntime {

View file

@ -3,7 +3,7 @@
#pragma once
#include "core/graph/rewrite_rule.h"
#include "core/optimizer/rewrite_rule.h"
namespace onnxruntime {

View file

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "core/framework/insert_cast_transformer.h"
#include "core/optimizer/insert_cast_transformer.h"
#include "core/framework/data_types.h"
using namespace ONNX_NAMESPACE;

View file

@ -2,10 +2,10 @@
// Licensed under the MIT License.
#pragma once
#include "core/graph/graph_viewer.h"
#include "core/graph/graph_transformer.h"
#include "core/common/common.h"
#include "core/graph/graph_viewer.h"
#include "core/framework/op_kernel.h"
#include "core/optimizer/graph_transformer.h"
namespace onnxruntime {
class InsertCastTransformer : public onnxruntime::GraphTransformer {

View file

@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "core/graph/initializer.h"
#include "core/graph/matmul_add_fusion.h"
#include "core/optimizer/initializer.h"
#include "core/optimizer/matmul_add_fusion.h"
#include "core/graph/graph_utils.h"
#include <deque>

View file

@ -3,7 +3,7 @@
#pragma once
#include "core/graph/graph_transformer.h"
#include "core/optimizer/graph_transformer.h"
namespace onnxruntime {

View file

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "core/graph/slice_elimination.h"
#include "core/optimizer/slice_elimination.h"
#include "core/graph/graph.h"
#include "core/graph/graph_utils.h"
#include "core/graph/op.h"

View file

@ -3,7 +3,7 @@
#pragma once
#include "core/graph/rewrite_rule.h"
#include "core/optimizer/rewrite_rule.h"
namespace onnxruntime {

View file

@ -6,7 +6,7 @@
#include "core/common/common.h"
#include "core/framework/op_kernel.h"
#include "core/framework/kernel_registry_manager.h"
#include "core/graph/graph_transformer.h"
#include "core/optimizer/graph_transformer.h"
namespace onnxruntime {

View file

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "core/graph/unsqueeze_elimination.h"
#include "core/optimizer/unsqueeze_elimination.h"
using namespace onnx;
using namespace ::onnxruntime::common;

View file

@ -3,7 +3,7 @@
#pragma once
#include "core/graph/graph_transformer.h"
#include "core/optimizer/graph_transformer.h"
namespace onnxruntime {

View file

@ -5,7 +5,6 @@
#include "core/framework/allocatormgr.h"
#include "core/framework/execution_provider.h"
#include "core/graph/graph_transformer.h"
#include "core/graph/constants.h"
namespace onnxruntime {

View file

@ -3,7 +3,6 @@
#include "cuda_common.h"
#include "cuda_execution_provider.h"
#include "core/framework/transformer_memcpy.h"
#include "core/framework/memcpy.h"
#include "cuda_fence.h"
#include "cuda_allocator.h"

View file

@ -4,7 +4,7 @@
#pragma once
#include "cuda_pch.h"
#include "core/platform/ort_mutex.h"
#include "core/graph/graph_transformer.h"
#include "core/graph/constants.h"
#include "core/framework/allocatormgr.h"
#include "core/framework/execution_provider.h"
#include "shared_inc/cuda_utils.h"

View file

@ -4,7 +4,6 @@
#include "mkldnn_allocator.h"
#include "mkldnn_execution_provider.h"
#include "core/framework/allocator.h"
#include "core/framework/transformer_memcpy.h"
#include "core/framework/memcpy.h"
#include "core/framework/kernel_registry.h"
#include "mkldnn_fwd.h"

View file

@ -9,9 +9,9 @@
#include <memory.h>
#include "core/platform/ort_mutex.h"
#include "core/graph/constants.h"
#include "core/framework/allocatormgr.h"
#include "core/framework/execution_provider.h"
#include "core/graph/graph_transformer.h"
namespace mkldnn {
struct memory;

View file

@ -16,8 +16,6 @@
#include "core/common/logging/logging.h"
#include "core/common/task_thread_pool.h"
#include "core/graph/graph_viewer.h"
#include "core/graph/graph_transformer.h"
#include "core/graph/graph_transformer_mgr.h"
#include "core/graph/graph_utils.h"
#include "core/graph/model.h"
#include "core/framework/allocatormgr.h"
@ -25,7 +23,6 @@
#include "core/framework/environment.h"
#include "core/framework/execution_frame.h"
#include "core/framework/graph_partitioner.h"
#include "core/framework/insert_cast_transformer.h"
#include "core/framework/kernel_def_builder.h"
#include "core/framework/kernel_registry.h"
#include "core/framework/ml_value_patterns_planner.h"
@ -37,8 +34,11 @@
#include "core/framework/session_state_initializer.h"
#include "core/framework/tensorprotoutils.h"
#include "core/framework/tensorutils.h"
#include "core/framework/transformer_memcpy.h"
#include "core/framework/utils.h"
#include "core/optimizer/graph_transformer.h"
#include "core/optimizer/graph_transformer_mgr.h"
#include "core/optimizer/insert_cast_transformer.h"
#include "core/optimizer/transformer_memcpy.h"
#include "core/platform/notification.h"
#include "core/providers/cpu/cpu_execution_provider.h"
#include "core/session/CustomOpsLoader.h"

View file

@ -3,7 +3,7 @@
#include "core/framework/allocatormgr.h"
#include "core/framework/allocator.h"
#include "core/framework/insert_cast_transformer.h"
#include "core/optimizer/insert_cast_transformer.h"
#include "core/graph/model.h"
#include "gtest/gtest.h"
#include "test_utils.h"

View file

@ -2,8 +2,9 @@
// Licensed under the MIT License.
#include <iterator>
#include "core/framework/transformer_memcpy.h"
#include "core/framework/execution_providers.h"
#include "core/optimizer/transformer_memcpy.h"
#include "core/graph/model.h"
#include "gtest/gtest.h"
#include "test_utils.h"

View file

@ -4,19 +4,18 @@
#include "core/session/inference_session.h"
#include "core/graph/graph_viewer.h"
#include "core/graph/model.h"
#include "core/graph/graph_transformer.h"
#include "core/graph/graph_transformer_mgr.h"
#include "core/graph/identity_elimination.h"
#include "core/graph/slice_elimination.h"
#include "core/graph/unsqueeze_elimination.h"
#include "core/graph/conv_bn_fusion.h"
#include "core/graph/conv_mul_fusion.h"
#include "core/graph/conv_add_fusion.h"
#include "core/graph/conv_activation_fusion.h"
#include "core/graph/matmul_add_fusion.h"
#include "core/graph/gemm_activation_fusion.h"
#include "core/optimizer/graph_transformer.h"
#include "core/optimizer/graph_transformer_mgr.h"
#include "core/optimizer/identity_elimination.h"
#include "core/optimizer/slice_elimination.h"
#include "core/optimizer/unsqueeze_elimination.h"
#include "core/optimizer/conv_bn_fusion.h"
#include "core/optimizer/conv_mul_fusion.h"
#include "core/optimizer/conv_add_fusion.h"
#include "core/optimizer/conv_activation_fusion.h"
#include "core/optimizer/matmul_add_fusion.h"
#include "core/optimizer/gemm_activation_fusion.h"
#include "core/platform/env.h"
#include "test/capturing_sink.h"
#include "test/test_environment.h"
#include "gtest/gtest.h"