From 8fa407183f1e038a687e1cc9c41655b9122365b5 Mon Sep 17 00:00:00 2001 From: chentianyu03 Date: Wed, 4 Aug 2021 11:37:01 +0000 Subject: [PATCH 1/8] add any.hpp to utils and replace boost::any with self defined paddle::any --- .../extension/include/ext_op_meta_info.h | 136 +++++----- paddle/fluid/framework/custom_operator.cc | 5 +- paddle/fluid/framework/ir/graph.h | 7 +- paddle/fluid/framework/ir/node.h | 10 +- paddle/fluid/framework/ir/pass.h | 11 +- paddle/fluid/inference/tensorrt/engine.h | 7 +- paddle/fluid/utils/any.hpp | 232 ++++++++++++++++++ 7 files changed, 323 insertions(+), 85 deletions(-) create mode 100644 paddle/fluid/utils/any.hpp diff --git a/paddle/fluid/extension/include/ext_op_meta_info.h b/paddle/fluid/extension/include/ext_op_meta_info.h index c400164c7543da..f04f7c23d51499 100644 --- a/paddle/fluid/extension/include/ext_op_meta_info.h +++ b/paddle/fluid/extension/include/ext_op_meta_info.h @@ -19,7 +19,7 @@ limitations under the License. */ #include #include -#include +#include "paddle/fluid/utils/any.hpp" #include "ext_dll_decl.h" // NOLINT #include "ext_exception.h" // NOLINT @@ -83,7 +83,7 @@ inline std::string Vec(const std::string& t_name) { using KernelFunc = std::vector (*)(const std::vector& inputs, const std::vector>& vec_inputs, - const std::vector& attrs); + const std::vector& attrs); #define PD_SPECIALIZE_ComputeCallHelper(attr_type) \ template \ @@ -92,14 +92,14 @@ using KernelFunc = typename... PreviousArgs> \ static Return Compute(const std::vector& inputs, \ const std::vector>& vec_inputs, \ - const std::vector& attrs, \ + const std::vector& attrs, \ const PreviousArgs&... pargs) { \ try { \ - attr_type arg = boost::any_cast(attrs[attr_idx]); \ + attr_type arg = paddle::any_cast(attrs[attr_idx]); \ return ComputeCallHelper::template Compute< \ in_idx, vec_in_idx, attr_idx + 1>(inputs, vec_inputs, attrs, \ pargs..., arg); \ - } catch (boost::bad_any_cast&) { \ + } catch (paddle::bad_any_cast&) { \ PD_THROW( \ "Attribute cast error in custom operator. Expected " #attr_type \ " value."); \ @@ -117,7 +117,7 @@ template struct KernelFuncImpl { static Return Compute(const std::vector& inputs, const std::vector>& vec_inputs, - const std::vector& attrs) { + const std::vector& attrs) { return ComputeCallHelper>::template Compute<0, 0, 0>( inputs, vec_inputs, attrs); } @@ -132,7 +132,7 @@ struct KernelFuncImpl { typename... PreviousArgs> static Return Compute(const std::vector& inputs, const std::vector>& vec_inputs, - const std::vector& attrs, + const std::vector& attrs, const PreviousArgs&... pargs) { const Tensor& arg = inputs[in_idx]; return ComputeCallHelper::template Compute { typename... PreviousArgs> static Return Compute(const std::vector& inputs, const std::vector>& vec_inputs, - const std::vector& attrs, + const std::vector& attrs, const PreviousArgs&... pargs) { const std::vector& arg = vec_inputs[vec_in_idx]; return ComputeCallHelper::template Compute< @@ -189,7 +189,7 @@ struct KernelFuncImpl { template static Return Compute(const std::vector& inputs, const std::vector>& vec_inputs, - const std::vector& attrs, + const std::vector& attrs, const Args&... args) { return impl_fn(args...); } @@ -205,67 +205,67 @@ struct KernelFuncImpl { using InferShapeFunc = std::vector> (*)( const std::vector>& input_shapes, const std::vector>>& vec_input_shapes, - const std::vector& attrs); - -#define PD_SPECIALIZE_InferShapeCallHelper_FOR_SHAPE(input_type) \ - template \ - struct InferShapeCallHelper { \ - template \ - static Return InferShape( \ - const std::vector>& input_shapes, \ - const std::vector>>& \ - vec_input_shapes, \ - const std::vector& attrs, const PreviousArgs&... pargs) { \ - input_type arg = input_shapes[in_idx]; \ - return InferShapeCallHelper::template InferShape< \ - in_idx + 1, vec_in_idx, attr_idx>(input_shapes, vec_input_shapes, \ - attrs, pargs..., arg); \ - } \ + const std::vector& attrs); + +#define PD_SPECIALIZE_InferShapeCallHelper_FOR_SHAPE(input_type) \ + template \ + struct InferShapeCallHelper { \ + template \ + static Return InferShape( \ + const std::vector>& input_shapes, \ + const std::vector>>& \ + vec_input_shapes, \ + const std::vector& attrs, const PreviousArgs&... pargs) { \ + input_type arg = input_shapes[in_idx]; \ + return InferShapeCallHelper::template InferShape< \ + in_idx + 1, vec_in_idx, attr_idx>(input_shapes, vec_input_shapes, \ + attrs, pargs..., arg); \ + } \ } -#define PD_SPECIALIZE_InferShapeCallHelper_FOR_SHAPES(input_type) \ - template \ - struct InferShapeCallHelper { \ - template \ - static Return InferShape( \ - const std::vector>& input_shapes, \ - const std::vector>>& \ - vec_input_shapes, \ - const std::vector& attrs, const PreviousArgs&... pargs) { \ - input_type arg = vec_input_shapes[vec_in_idx]; \ - return InferShapeCallHelper::template InferShape< \ - in_idx, vec_in_idx + 1, attr_idx>(input_shapes, vec_input_shapes, \ - attrs, pargs..., arg); \ - } \ +#define PD_SPECIALIZE_InferShapeCallHelper_FOR_SHAPES(input_type) \ + template \ + struct InferShapeCallHelper { \ + template \ + static Return InferShape( \ + const std::vector>& input_shapes, \ + const std::vector>>& \ + vec_input_shapes, \ + const std::vector& attrs, const PreviousArgs&... pargs) { \ + input_type arg = vec_input_shapes[vec_in_idx]; \ + return InferShapeCallHelper::template InferShape< \ + in_idx, vec_in_idx + 1, attr_idx>(input_shapes, vec_input_shapes, \ + attrs, pargs..., arg); \ + } \ } -#define PD_SPECIALIZE_InferShapeCallHelper_FOR_ATTR(attr_type) \ - template \ - struct InferShapeCallHelper { \ - template \ - static Return InferShape( \ - const std::vector>& input_shapes, \ - const std::vector>>& \ - vec_input_shapes, \ - const std::vector& attrs, const PreviousArgs&... pargs) { \ - try { \ - attr_type arg = boost::any_cast(attrs[attr_idx]); \ - return InferShapeCallHelper::template InferShape< \ - in_idx, vec_in_idx, attr_idx + 1>(input_shapes, vec_input_shapes, \ - attrs, pargs..., arg); \ - } catch (boost::bad_any_cast&) { \ - PD_THROW( \ - "Attribute cast error in custom operator InferShapeFn. " \ - "Expected " #attr_type \ - " value. InferShapeFn's attribute list must be exactly same as " \ - "Forward " \ - "KernelFn's attribute list except std::vector " \ - "attribute."); \ - } \ - } \ +#define PD_SPECIALIZE_InferShapeCallHelper_FOR_ATTR(attr_type) \ + template \ + struct InferShapeCallHelper { \ + template \ + static Return InferShape( \ + const std::vector>& input_shapes, \ + const std::vector>>& \ + vec_input_shapes, \ + const std::vector& attrs, const PreviousArgs&... pargs) { \ + try { \ + attr_type arg = paddle::any_cast(attrs[attr_idx]); \ + return InferShapeCallHelper::template InferShape< \ + in_idx, vec_in_idx, attr_idx + 1>(input_shapes, vec_input_shapes, \ + attrs, pargs..., arg); \ + } catch (paddle::bad_any_cast&) { \ + PD_THROW( \ + "Attribute cast error in custom operator InferShapeFn. " \ + "Expected " #attr_type \ + " value. InferShapeFn's attribute list must be exactly same as " \ + "Forward " \ + "KernelFn's attribute list except std::vector " \ + "attribute."); \ + } \ + } \ } template @@ -276,7 +276,7 @@ struct InferShapeFuncImpl { static Return InferShape( const std::vector>& input_shapes, const std::vector>>& vec_input_shapes, - const std::vector& attrs) { + const std::vector& attrs) { return InferShapeCallHelper>::template InferShape< 0, 0, 0>(input_shapes, vec_input_shapes, attrs); } @@ -314,7 +314,7 @@ struct InferShapeFuncImpl { static Return InferShape( const std::vector>& input_shapes, const std::vector>>& vec_input_shapes, - const std::vector& attrs, const Args&... args) { + const std::vector& attrs, const Args&... args) { return impl_fn(args...); } }; diff --git a/paddle/fluid/framework/custom_operator.cc b/paddle/fluid/framework/custom_operator.cc index b1c5ff86d19790..e036ee8e019927 100644 --- a/paddle/fluid/framework/custom_operator.cc +++ b/paddle/fluid/framework/custom_operator.cc @@ -34,6 +34,7 @@ limitations under the License. */ #include "paddle/fluid/framework/tensor.h" #include "paddle/fluid/platform/dynload/dynamic_loader.h" #include "paddle/fluid/string/string_helper.h" +#include "paddle/fluid/utils/any.hpp" namespace paddle { namespace framework { @@ -149,7 +150,7 @@ static void RunKernelFunc(const framework::ExecutionContext& ctx, } } - std::vector custom_attrs; + std::vector custom_attrs; for (auto& attr_str : attrs) { auto attr_name_and_type = detail::ParseAttrStr(attr_str); auto attr_name = attr_name_and_type[0]; @@ -605,7 +606,7 @@ void RegisterOperatorWithMetaInfo( } } - std::vector custom_attrs; + std::vector custom_attrs; for (auto& attr_str : op_attrs) { auto attr_name_and_type = detail::ParseAttrStr(attr_str); auto attr_name = attr_name_and_type[0]; diff --git a/paddle/fluid/framework/ir/graph.h b/paddle/fluid/framework/ir/graph.h index 50c5671cb91a49..44503a292e3127 100644 --- a/paddle/fluid/framework/ir/graph.h +++ b/paddle/fluid/framework/ir/graph.h @@ -25,6 +25,7 @@ limitations under the License. */ #include "paddle/fluid/framework/program_desc.h" #include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/variant.h" +#include "paddle/fluid/utils/any.hpp" DECLARE_bool(convert_all_blocks); @@ -147,8 +148,8 @@ class Graph { platform::errors::PreconditionNotMet( "%s attribute not registered for current graph.", attr_name)); try { - return *boost::any_cast(attrs_.at(attr_name)); - } catch (boost::bad_any_cast &) { + return *paddle::any_cast(attrs_.at(attr_name)); + } catch (paddle::bad_any_cast &) { PADDLE_THROW(platform::errors::InvalidArgument( "Invalid attribute type of %s, expected: %s, received: %s.", attr_name, platform::demangle(typeid(AttrType *).name()), // NOLINT @@ -426,7 +427,7 @@ class Graph { const Graph *main_graph_; // not owned. std::vector> sub_graphs_; - std::map attrs_; + std::map attrs_; std::map> attr_dels_; std::map> nodes_; std::unordered_set node_set_; diff --git a/paddle/fluid/framework/ir/node.h b/paddle/fluid/framework/ir/node.h index d0568f39ef6a45..188309da823033 100644 --- a/paddle/fluid/framework/ir/node.h +++ b/paddle/fluid/framework/ir/node.h @@ -14,16 +14,18 @@ limitations under the License. */ #pragma once +#include #include #include +#include #include #include #include +#include #include "paddle/fluid/framework/op_desc.h" #include "paddle/fluid/framework/var_desc.h" #include "paddle/fluid/platform/macros.h" - namespace paddle { namespace framework { class OpDesc; @@ -104,8 +106,8 @@ class Node { template T& Wrapper() { try { - return *boost::any_cast(wrapper_); - } catch (boost::bad_any_cast&) { + return *paddle::any_cast(wrapper_); + } catch (paddle::bad_any_cast&) { PADDLE_THROW(platform::errors::InvalidArgument( "Invalid wrapper type error, expected %s, actual %s.", typeid(T).name(), wrapper_type_.name())); @@ -277,7 +279,7 @@ class Node { Node() = delete; - boost::any wrapper_; + paddle::any wrapper_; std::function wrapper_deleter_; std::type_index wrapper_type_ = std::type_index(typeid(void)); diff --git a/paddle/fluid/framework/ir/pass.h b/paddle/fluid/framework/ir/pass.h index 8fb96bec9cbd56..4423f1db77c849 100644 --- a/paddle/fluid/framework/ir/pass.h +++ b/paddle/fluid/framework/ir/pass.h @@ -26,6 +26,7 @@ limitations under the License. */ #include "paddle/fluid/framework/ir/node.h" #include "paddle/fluid/framework/program_desc.h" #include "paddle/fluid/platform/variant.h" +#include "paddle/fluid/utils/any.hpp" namespace paddle { namespace framework { @@ -73,8 +74,8 @@ class Pass { platform::errors::InvalidArgument( "Attribute %s not registered for pass.", attr_name)); try { - return *boost::any_cast(attrs_.at(attr_name)); - } catch (boost::bad_any_cast &) { + return *paddle::any_cast(attrs_.at(attr_name)); + } catch (paddle::bad_any_cast &) { auto TypeToString = [](const std::type_info &info) -> std::string { if (std::type_index(info) == std::type_index(typeid(bool *))) { return "bool"; @@ -166,7 +167,7 @@ class Pass { // Pass doesn't take ownership. PassRegistrar should delete default_attrs void RegisterDefaultPassAttrs( - std::map default_attr_values) { + std::map default_attr_values) { for (auto const &attr_name : default_attr_values) { default_pass_attrs_.insert(attr_name.first); } @@ -180,7 +181,7 @@ class Pass { std::unordered_set required_pass_attrs_; std::unordered_set default_pass_attrs_; std::unordered_set required_graph_attrs_; - std::map attrs_; + std::map attrs_; std::map> attr_dels_; }; @@ -290,7 +291,7 @@ struct PassRegistrar : public Registrar { private: std::unordered_set required_pass_attrs_; std::unordered_set required_graph_attrs_; - std::map default_attr_values_; + std::map default_attr_values_; std::map> default_attr_dels_; }; diff --git a/paddle/fluid/inference/tensorrt/engine.h b/paddle/fluid/inference/tensorrt/engine.h index 38c453bde6d2db..049f1aee27c7a1 100644 --- a/paddle/fluid/inference/tensorrt/engine.h +++ b/paddle/fluid/inference/tensorrt/engine.h @@ -32,6 +32,7 @@ limitations under the License. */ #include "paddle/fluid/inference/tensorrt/plugin/trt_plugin.h" #include "paddle/fluid/inference/tensorrt/trt_int8_calibrator.h" #include "paddle/fluid/inference/utils/singleton.h" +#include "paddle/fluid/utils/any.hpp" namespace paddle { namespace framework { @@ -425,8 +426,8 @@ class TensorRTEngine { platform::errors::InvalidArgument( "Attribute %s not found in trt engine.", attr_name)); try { - return *boost::any_cast(attrs_.at(attr_name)); - } catch (boost::bad_any_cast&) { + return *paddle::any_cast(attrs_.at(attr_name)); + } catch (paddle::bad_any_cast&) { auto TypeToString = [](const std::type_info& info) -> std::string { if (std::type_index(info) == std::type_index(typeid(bool*))) { return "bool"; @@ -504,7 +505,7 @@ class TensorRTEngine { infer_ptr ihost_memory_; std::unordered_map quant_dynamic_range_; - std::unordered_map attrs_; + std::unordered_map attrs_; std::unordered_map> attr_dels_; // For dynamic shape diff --git a/paddle/fluid/utils/any.hpp b/paddle/fluid/utils/any.hpp new file mode 100644 index 00000000000000..ec803647c11f7e --- /dev/null +++ b/paddle/fluid/utils/any.hpp @@ -0,0 +1,232 @@ +//This file copy from boost/any.hpp and boost version: 1.41.0 +//Modified the following points: +//1. modify namespace from boost::any to paddle::any +//2. remove the depending boost header files +//3. remove/modify some macro + +// See http://www.boost.org/libs/any for Documentation. + +#ifndef PADDLE_ANY_INCLUDED +#define PADDLE_ANY_INCLUDED + +// what: variant type boost::any +// who: contributed by Kevlin Henney, +// with features contributed and bugs found by +// Ed Brey, Mark Rodgers, Peter Dimov, and James Curran +// when: July 2001 +// where: tested with BCC 5.5, MSVC 6.0, and g++ 2.95 + +#include +#include +#include + +// See boost/python/type_id.hpp +// TODO: add BOOST_TYPEID_COMPARE_BY_NAME to config.hpp +# if (defined(__GNUC__) && __GNUC__ >= 3) \ + || defined(_AIX) \ + || ( defined(__sgi) && defined(__host_mips)) \ + || (defined(__hpux) && defined(__HP_aCC)) \ + || (defined(linux) && defined(__INTEL_COMPILER) && defined(__ICC)) +# define BOOST_AUX_ANY_TYPE_ID_NAME +#include +# endif + +namespace paddle +{ + class any + { + public: // structors + + any() + : content(0) + { + } + + template + any(const ValueType & value) + : content(new holder(value)) + { + } + + any(const any & other) + : content(other.content ? other.content->clone() : 0) + { + } + + ~any() + { + delete content; + } + + public: // modifiers + + any & swap(any & rhs) + { + std::swap(content, rhs.content); + return *this; + } + + template + any & operator=(const ValueType & rhs) + { + any(rhs).swap(*this); + return *this; + } + + any & operator=(any rhs) + { + rhs.swap(*this); + return *this; + } + + public: // queries + + bool empty() const + { + return !content; + } + + const std::type_info & type() const + { + return content ? content->type() : typeid(void); + } + + public: // types (public so any_cast can be non-friend) + + class placeholder + { + public: // structors + + virtual ~placeholder() + { + } + + public: // queries + + virtual const std::type_info & type() const = 0; + + virtual placeholder * clone() const = 0; + + }; + + template + class holder : public placeholder + { + public: // structors + + holder(const ValueType & value) + : held(value) + { + } + + public: // queries + + virtual const std::type_info & type() const + { + return typeid(ValueType); + } + + virtual placeholder * clone() const + { + return new holder(held); + } + + public: // representation + + ValueType held; + + private: // intentionally left unimplemented + holder & operator=(const holder &); + }; + + public: // representation (public so any_cast can be non-friend) + + placeholder * content; + + }; + + class bad_any_cast : public std::bad_cast + { + public: + virtual const char * what() const throw() + { + return "paddle::bad_any_cast: " + "failed conversion using paddle::any_cast"; + } + }; + + template + ValueType * any_cast(any * operand) + { + return operand && +#ifdef BOOST_AUX_ANY_TYPE_ID_NAME + std::strcmp(operand->type().name(), typeid(ValueType).name()) == 0 +#else + operand->type() == typeid(ValueType) +#endif + ? &static_cast *>(operand->content)->held + : 0; + } + + template + inline const ValueType * any_cast(const any * operand) + { + return any_cast(const_cast(operand)); + } + + template + ValueType any_cast(any & operand) + { + typedef typename std::remove_reference::type nonref; + + // If 'nonref' is still reference type, it means the user has not + // specialized 'remove_reference'. + + // Please use BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION macro + // to generate specialization of remove_reference for your class + // See type traits library documentation for details + static_assert(!std::is_reference::value, "!std::is_reference::value"); + + nonref * result = any_cast(&operand); + if(!result) + throw bad_any_cast(); + return *result; + } + + template + inline ValueType any_cast(const any & operand) + { + typedef typename std::remove_reference::type nonref; + + // The comment in the above version of 'any_cast' explains when this + // assert is fired and what to do. + static_assert(!std::is_reference::value, "!std::is_reference::value"); + + return any_cast(const_cast(operand)); + } + + // Note: The "unsafe" versions of any_cast are not part of the + // public interface and may be removed at any time. They are + // required where we know what type is stored in the any and can't + // use typeid() comparison, e.g., when our types may travel across + // different shared libraries. + template + inline ValueType * unsafe_any_cast(any * operand) + { + return &static_cast *>(operand->content)->held; + } + + template + inline const ValueType * unsafe_any_cast(const any * operand) + { + return unsafe_any_cast(const_cast(operand)); + } +} + +// Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved. +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#endif From 889e1441dd94aa1abaaceb30ba8a656e00f138d3 Mon Sep 17 00:00:00 2001 From: chentianyu03 Date: Thu, 5 Aug 2021 07:35:36 +0000 Subject: [PATCH 2/8] add copy any.hpp to custom op depends --- cmake/inference_lib.cmake | 3 +++ python/setup.py.in | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/inference_lib.cmake b/cmake/inference_lib.cmake index 3dcf0b74f7940f..6482d6e2a5ffaf 100644 --- a/cmake/inference_lib.cmake +++ b/cmake/inference_lib.cmake @@ -205,6 +205,9 @@ copy(inference_lib_dist copy(inference_lib_dist SRCS ${PADDLE_SOURCE_DIR}/paddle/fluid/platform/float16.h DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/) +copy(inference_lib_dist + SRCS ${PADDLE_SOURCE_DIR}/paddle/fluid/utils/any.hpp + DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/) # CAPI inference library for only inference set(PADDLE_INFERENCE_C_INSTALL_DIR "${CMAKE_BINARY_DIR}/paddle_inference_c_install_dir" CACHE STRING diff --git a/python/setup.py.in b/python/setup.py.in index 0db6c0c27d743d..91b8a15094f29f 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -397,7 +397,8 @@ headers = ( # For paddle uew custom op, only copy data type headers from `paddle/fluid/platform` # to `extension/incude`, ['@PADDLE_SOURCE_DIR@/paddle/fluid/platform/complex.h'] + - ['@PADDLE_SOURCE_DIR@/paddle/fluid/platform/float16.h']) + ['@PADDLE_SOURCE_DIR@/paddle/fluid/platform/float16.h'] + + ['@PADDLE_SOURCE_DIR@/paddle/fluid/utils/any.hpp']) if '${WITH_MKLDNN}' == 'ON': headers += list(find_files('*', '${MKLDNN_INSTALL_DIR}/include')) # mkldnn From 8078b17f5afe10daf1c545ed71464f1c144d42b4 Mon Sep 17 00:00:00 2001 From: chentianyu03 Date: Fri, 6 Aug 2021 05:06:51 +0000 Subject: [PATCH 3/8] modify any.hpp include path --- CMakeLists.txt | 1 + paddle/fluid/extension/include/ext_op_meta_info.h | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f6ed9de30efe4..886b75b2f6348b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -342,6 +342,7 @@ include(coveralls) # set code coverage include(configure) # add paddle env configuration include_directories("${PADDLE_SOURCE_DIR}") +include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/utils) if(WITH_NV_JETSON) set(WITH_ARM ON CACHE STRING "Set WITH_ARM=ON when compiling WITH_NV_JETSON=ON." FORCE) diff --git a/paddle/fluid/extension/include/ext_op_meta_info.h b/paddle/fluid/extension/include/ext_op_meta_info.h index f04f7c23d51499..07f184d2b92ce7 100644 --- a/paddle/fluid/extension/include/ext_op_meta_info.h +++ b/paddle/fluid/extension/include/ext_op_meta_info.h @@ -19,8 +19,7 @@ limitations under the License. */ #include #include -#include "paddle/fluid/utils/any.hpp" - +#include "any.hpp" #include "ext_dll_decl.h" // NOLINT #include "ext_exception.h" // NOLINT #include "ext_tensor.h" // NOLINT From ba9fc3225732d8150309ea0e798fa7e3d71eb464 Mon Sep 17 00:00:00 2001 From: chentianyu03 Date: Fri, 6 Aug 2021 06:46:50 +0000 Subject: [PATCH 4/8] remove boost from setup.py.in --- CMakeLists.txt | 2 ++ paddle/fluid/framework/ir/node.h | 4 +--- python/setup.py.in | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 886b75b2f6348b..43e988417a5f60 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -342,6 +342,8 @@ include(coveralls) # set code coverage include(configure) # add paddle env configuration include_directories("${PADDLE_SOURCE_DIR}") +# Adapt to custom op mechanism: Include the header files related to the data type +# to avoid exposing the path of the underlying fil include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/utils) if(WITH_NV_JETSON) diff --git a/paddle/fluid/framework/ir/node.h b/paddle/fluid/framework/ir/node.h index 188309da823033..74634eec3b527c 100644 --- a/paddle/fluid/framework/ir/node.h +++ b/paddle/fluid/framework/ir/node.h @@ -14,18 +14,16 @@ limitations under the License. */ #pragma once -#include #include #include -#include #include #include #include -#include #include "paddle/fluid/framework/op_desc.h" #include "paddle/fluid/framework/var_desc.h" #include "paddle/fluid/platform/macros.h" +#include "paddle/fluid/utils/any.hpp" namespace paddle { namespace framework { class OpDesc; diff --git a/python/setup.py.in b/python/setup.py.in index 91b8a15094f29f..750ed83c9b5d6e 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -393,7 +393,6 @@ def find_files(pattern, root, recursive=False): headers = ( list(find_files('*.h', '@PADDLE_SOURCE_DIR@/paddle')) + list(find_files('*.h', '@PADDLE_SOURCE_DIR@/paddle/fluid/extension/include')) + # extension - list(find_files('*', '${BOOST_INCLUDE_DIR}/boost', True)) + # boost # For paddle uew custom op, only copy data type headers from `paddle/fluid/platform` # to `extension/incude`, ['@PADDLE_SOURCE_DIR@/paddle/fluid/platform/complex.h'] + @@ -450,7 +449,7 @@ class InstallHeaders(Command): else: # third_party install_dir = re.sub('${THIRD_PARTY_PATH}', 'third_party', header) - patterns = ['boost/src/extern_boost', 'install/mkldnn/include'] + patterns = ['install/mkldnn/include'] for pattern in patterns: install_dir = re.sub(pattern, '', install_dir) install_dir = os.path.join(self.install_dir, os.path.dirname(install_dir)) From 762670c1d48b0b69448da5c11207a01389776410 Mon Sep 17 00:00:00 2001 From: chentianyu03 Date: Fri, 6 Aug 2021 09:47:22 +0000 Subject: [PATCH 5/8] add copy any.hpp to custom op depends --- CMakeLists.txt | 3 --- paddle/fluid/framework/CMakeLists.txt | 1 + paddle/fluid/inference/CMakeLists.txt | 1 + paddle/fluid/pybind/CMakeLists.txt | 1 + 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43e988417a5f60..4f6ed9de30efe4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -342,9 +342,6 @@ include(coveralls) # set code coverage include(configure) # add paddle env configuration include_directories("${PADDLE_SOURCE_DIR}") -# Adapt to custom op mechanism: Include the header files related to the data type -# to avoid exposing the path of the underlying fil -include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/utils) if(WITH_NV_JETSON) set(WITH_ARM ON CACHE STRING "Set WITH_ARM=ON when compiling WITH_NV_JETSON=ON." FORCE) diff --git a/paddle/fluid/framework/CMakeLists.txt b/paddle/fluid/framework/CMakeLists.txt index 1e4d813c6d3bd7..b5ce0b369771a6 100644 --- a/paddle/fluid/framework/CMakeLists.txt +++ b/paddle/fluid/framework/CMakeLists.txt @@ -406,6 +406,7 @@ configure_file(commit.h.in commit.h) # to avoid exposing the path of the underlying file include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/platform) include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/extension/include) +include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/utils) if(WITH_ROCM) hip_library(custom_tensor SRCS ../extension/src/ext_tensor.cc DEPS lod_tensor memory enforce) diff --git a/paddle/fluid/inference/CMakeLists.txt b/paddle/fluid/inference/CMakeLists.txt index c002c7a10cb7b3..1928c228a99b36 100644 --- a/paddle/fluid/inference/CMakeLists.txt +++ b/paddle/fluid/inference/CMakeLists.txt @@ -39,6 +39,7 @@ get_property(fluid_modules GLOBAL PROPERTY FLUID_MODULES) # Adapt to custom op mechanism: Include the header files related to the data type # to avoid exposing the path of the underlying file include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/platform) +include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/utils) add_subdirectory(api) diff --git a/paddle/fluid/pybind/CMakeLists.txt b/paddle/fluid/pybind/CMakeLists.txt index f362808a4b9528..165b55dc1fbd53 100644 --- a/paddle/fluid/pybind/CMakeLists.txt +++ b/paddle/fluid/pybind/CMakeLists.txt @@ -1,6 +1,7 @@ # Adapt to custom op mechanism: Include the header files related to the data type # to avoid exposing the path of the underlying file include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/platform) +include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/utils) set(PYBIND_DEPS pybind python proto_desc memory executor fleet_wrapper box_wrapper prune feed_fetch_method pass pass_builder parallel_executor profiler layer tracer engine scope_pool From d3a9d58978f114b3211718c09c8f2cfca81934b9 Mon Sep 17 00:00:00 2001 From: chentianyu03 Date: Mon, 9 Aug 2021 07:22:05 +0000 Subject: [PATCH 6/8] move any.hpp to paddle/utils/ dirs --- cmake/inference_lib.cmake | 2 +- paddle/fluid/extension/include/ext_op_meta_info.h | 2 +- paddle/fluid/framework/CMakeLists.txt | 2 +- paddle/fluid/framework/custom_operator.cc | 2 +- paddle/fluid/framework/ir/graph.h | 2 +- paddle/fluid/framework/ir/node.h | 2 +- paddle/fluid/framework/ir/pass.h | 2 +- paddle/fluid/inference/CMakeLists.txt | 2 +- paddle/fluid/inference/tensorrt/engine.h | 2 +- paddle/fluid/pybind/CMakeLists.txt | 2 +- paddle/{fluid/utils/any.hpp => utils/any.h} | 0 python/setup.py.in | 2 +- 12 files changed, 11 insertions(+), 11 deletions(-) rename paddle/{fluid/utils/any.hpp => utils/any.h} (100%) diff --git a/cmake/inference_lib.cmake b/cmake/inference_lib.cmake index 6482d6e2a5ffaf..669875d81dfecc 100644 --- a/cmake/inference_lib.cmake +++ b/cmake/inference_lib.cmake @@ -206,7 +206,7 @@ copy(inference_lib_dist SRCS ${PADDLE_SOURCE_DIR}/paddle/fluid/platform/float16.h DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/) copy(inference_lib_dist - SRCS ${PADDLE_SOURCE_DIR}/paddle/fluid/utils/any.hpp + SRCS ${PADDLE_SOURCE_DIR}/paddle/utils/any.h DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/) # CAPI inference library for only inference diff --git a/paddle/fluid/extension/include/ext_op_meta_info.h b/paddle/fluid/extension/include/ext_op_meta_info.h index 07f184d2b92ce7..6f2528030e603d 100644 --- a/paddle/fluid/extension/include/ext_op_meta_info.h +++ b/paddle/fluid/extension/include/ext_op_meta_info.h @@ -19,7 +19,7 @@ limitations under the License. */ #include #include -#include "any.hpp" +#include "any.h" #include "ext_dll_decl.h" // NOLINT #include "ext_exception.h" // NOLINT #include "ext_tensor.h" // NOLINT diff --git a/paddle/fluid/framework/CMakeLists.txt b/paddle/fluid/framework/CMakeLists.txt index b5ce0b369771a6..22c1ae90461f57 100644 --- a/paddle/fluid/framework/CMakeLists.txt +++ b/paddle/fluid/framework/CMakeLists.txt @@ -406,7 +406,7 @@ configure_file(commit.h.in commit.h) # to avoid exposing the path of the underlying file include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/platform) include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/extension/include) -include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/utils) +include_directories(${PADDLE_SOURCE_DIR}/paddle/utils) if(WITH_ROCM) hip_library(custom_tensor SRCS ../extension/src/ext_tensor.cc DEPS lod_tensor memory enforce) diff --git a/paddle/fluid/framework/custom_operator.cc b/paddle/fluid/framework/custom_operator.cc index e036ee8e019927..7fef165f373969 100644 --- a/paddle/fluid/framework/custom_operator.cc +++ b/paddle/fluid/framework/custom_operator.cc @@ -34,7 +34,7 @@ limitations under the License. */ #include "paddle/fluid/framework/tensor.h" #include "paddle/fluid/platform/dynload/dynamic_loader.h" #include "paddle/fluid/string/string_helper.h" -#include "paddle/fluid/utils/any.hpp" +#include "paddle/utils/any.h" namespace paddle { namespace framework { diff --git a/paddle/fluid/framework/ir/graph.h b/paddle/fluid/framework/ir/graph.h index 44503a292e3127..21e743e3587d80 100644 --- a/paddle/fluid/framework/ir/graph.h +++ b/paddle/fluid/framework/ir/graph.h @@ -25,7 +25,7 @@ limitations under the License. */ #include "paddle/fluid/framework/program_desc.h" #include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/variant.h" -#include "paddle/fluid/utils/any.hpp" +#include "paddle/utils/any.h" DECLARE_bool(convert_all_blocks); diff --git a/paddle/fluid/framework/ir/node.h b/paddle/fluid/framework/ir/node.h index 74634eec3b527c..54bd4376c6e5cb 100644 --- a/paddle/fluid/framework/ir/node.h +++ b/paddle/fluid/framework/ir/node.h @@ -23,7 +23,7 @@ limitations under the License. */ #include "paddle/fluid/framework/op_desc.h" #include "paddle/fluid/framework/var_desc.h" #include "paddle/fluid/platform/macros.h" -#include "paddle/fluid/utils/any.hpp" +#include "paddle/utils/any.h" namespace paddle { namespace framework { class OpDesc; diff --git a/paddle/fluid/framework/ir/pass.h b/paddle/fluid/framework/ir/pass.h index 4423f1db77c849..fecdfc404e6dca 100644 --- a/paddle/fluid/framework/ir/pass.h +++ b/paddle/fluid/framework/ir/pass.h @@ -26,7 +26,7 @@ limitations under the License. */ #include "paddle/fluid/framework/ir/node.h" #include "paddle/fluid/framework/program_desc.h" #include "paddle/fluid/platform/variant.h" -#include "paddle/fluid/utils/any.hpp" +#include "paddle/utils/any.h" namespace paddle { namespace framework { diff --git a/paddle/fluid/inference/CMakeLists.txt b/paddle/fluid/inference/CMakeLists.txt index 1928c228a99b36..6567c41ee1fedc 100644 --- a/paddle/fluid/inference/CMakeLists.txt +++ b/paddle/fluid/inference/CMakeLists.txt @@ -39,7 +39,7 @@ get_property(fluid_modules GLOBAL PROPERTY FLUID_MODULES) # Adapt to custom op mechanism: Include the header files related to the data type # to avoid exposing the path of the underlying file include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/platform) -include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/utils) +include_directories(${PADDLE_SOURCE_DIR}/paddle/utils) add_subdirectory(api) diff --git a/paddle/fluid/inference/tensorrt/engine.h b/paddle/fluid/inference/tensorrt/engine.h index 049f1aee27c7a1..3604a47a7eb90b 100644 --- a/paddle/fluid/inference/tensorrt/engine.h +++ b/paddle/fluid/inference/tensorrt/engine.h @@ -32,7 +32,7 @@ limitations under the License. */ #include "paddle/fluid/inference/tensorrt/plugin/trt_plugin.h" #include "paddle/fluid/inference/tensorrt/trt_int8_calibrator.h" #include "paddle/fluid/inference/utils/singleton.h" -#include "paddle/fluid/utils/any.hpp" +#include "paddle/utils/any.h" namespace paddle { namespace framework { diff --git a/paddle/fluid/pybind/CMakeLists.txt b/paddle/fluid/pybind/CMakeLists.txt index 165b55dc1fbd53..b4ce0861c6ed01 100644 --- a/paddle/fluid/pybind/CMakeLists.txt +++ b/paddle/fluid/pybind/CMakeLists.txt @@ -1,7 +1,7 @@ # Adapt to custom op mechanism: Include the header files related to the data type # to avoid exposing the path of the underlying file include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/platform) -include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/utils) +include_directories(${PADDLE_SOURCE_DIR}/paddle/utils) set(PYBIND_DEPS pybind python proto_desc memory executor fleet_wrapper box_wrapper prune feed_fetch_method pass pass_builder parallel_executor profiler layer tracer engine scope_pool diff --git a/paddle/fluid/utils/any.hpp b/paddle/utils/any.h similarity index 100% rename from paddle/fluid/utils/any.hpp rename to paddle/utils/any.h diff --git a/python/setup.py.in b/python/setup.py.in index 750ed83c9b5d6e..16feed9127c6f0 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -397,7 +397,7 @@ headers = ( # to `extension/incude`, ['@PADDLE_SOURCE_DIR@/paddle/fluid/platform/complex.h'] + ['@PADDLE_SOURCE_DIR@/paddle/fluid/platform/float16.h'] + - ['@PADDLE_SOURCE_DIR@/paddle/fluid/utils/any.hpp']) + ['@PADDLE_SOURCE_DIR@/paddle/utils/any.h']) if '${WITH_MKLDNN}' == 'ON': headers += list(find_files('*', '${MKLDNN_INSTALL_DIR}/include')) # mkldnn From 7bb52e4fba6f8d19972f2b6b59822a74e8f1e4b1 Mon Sep 17 00:00:00 2001 From: chentianyu03 Date: Mon, 9 Aug 2021 09:30:48 +0000 Subject: [PATCH 7/8] move any.h to extension/include direction --- python/setup.py.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/setup.py.in b/python/setup.py.in index 16feed9127c6f0..2670dcb031d2ad 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -444,7 +444,7 @@ class InstallHeaders(Command): elif 'third_party' not in header: # paddle headers install_dir = re.sub('@PADDLE_SOURCE_DIR@/', '', header) - if 'fluid' in install_dir: + if 'fluid' or 'utils' in install_dir: install_dir = "paddle/extension/include/" else: # third_party From 01e516cafd292874e7113f0f3e2a164a45f3c938 Mon Sep 17 00:00:00 2001 From: chentianyu03 Date: Mon, 9 Aug 2021 13:08:43 +0000 Subject: [PATCH 8/8] copy utils to right directions --- python/setup.py.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/setup.py.in b/python/setup.py.in index 2670dcb031d2ad..116b32c92e30c3 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -444,7 +444,7 @@ class InstallHeaders(Command): elif 'third_party' not in header: # paddle headers install_dir = re.sub('@PADDLE_SOURCE_DIR@/', '', header) - if 'fluid' or 'utils' in install_dir: + if 'fluid' in install_dir or 'utils' in install_dir: install_dir = "paddle/extension/include/" else: # third_party