Skip to content

Commit 4ff8213

Browse files
committed
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into add_no_need_output_to_gc_check_list
2 parents 950755b + 1289292 commit 4ff8213

File tree

15 files changed

+385
-99
lines changed

15 files changed

+385
-99
lines changed

cmake/inference_lib.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ copy(inference_lib_dist
205205
copy(inference_lib_dist
206206
SRCS ${PADDLE_SOURCE_DIR}/paddle/fluid/platform/float16.h
207207
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/)
208+
copy(inference_lib_dist
209+
SRCS ${PADDLE_SOURCE_DIR}/paddle/utils/any.h
210+
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/)
208211

209212
# CAPI inference library for only inference
210213
set(PADDLE_INFERENCE_C_INSTALL_DIR "${CMAKE_BINARY_DIR}/paddle_inference_c_install_dir" CACHE STRING

paddle/fluid/extension/include/ext_op_meta_info.h

Lines changed: 68 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ limitations under the License. */
1919
#include <unordered_map>
2020
#include <vector>
2121

22-
#include <boost/any.hpp>
23-
22+
#include "any.h"
2423
#include "ext_dll_decl.h" // NOLINT
2524
#include "ext_exception.h" // NOLINT
2625
#include "ext_tensor.h" // NOLINT
@@ -83,7 +82,7 @@ inline std::string Vec(const std::string& t_name) {
8382
using KernelFunc =
8483
std::vector<Tensor> (*)(const std::vector<Tensor>& inputs,
8584
const std::vector<std::vector<Tensor>>& vec_inputs,
86-
const std::vector<boost::any>& attrs);
85+
const std::vector<paddle::any>& attrs);
8786

8887
#define PD_SPECIALIZE_ComputeCallHelper(attr_type) \
8988
template <typename... Tail> \
@@ -92,14 +91,14 @@ using KernelFunc =
9291
typename... PreviousArgs> \
9392
static Return Compute(const std::vector<Tensor>& inputs, \
9493
const std::vector<std::vector<Tensor>>& vec_inputs, \
95-
const std::vector<boost::any>& attrs, \
94+
const std::vector<paddle::any>& attrs, \
9695
const PreviousArgs&... pargs) { \
9796
try { \
98-
attr_type arg = boost::any_cast<attr_type>(attrs[attr_idx]); \
97+
attr_type arg = paddle::any_cast<attr_type>(attrs[attr_idx]); \
9998
return ComputeCallHelper<Tail...>::template Compute< \
10099
in_idx, vec_in_idx, attr_idx + 1>(inputs, vec_inputs, attrs, \
101100
pargs..., arg); \
102-
} catch (boost::bad_any_cast&) { \
101+
} catch (paddle::bad_any_cast&) { \
103102
PD_THROW( \
104103
"Attribute cast error in custom operator. Expected " #attr_type \
105104
" value."); \
@@ -117,7 +116,7 @@ template <typename Return, typename... Args, Return (*impl_fn)(Args...)>
117116
struct KernelFuncImpl<Return (*)(Args...), impl_fn> {
118117
static Return Compute(const std::vector<Tensor>& inputs,
119118
const std::vector<std::vector<Tensor>>& vec_inputs,
120-
const std::vector<boost::any>& attrs) {
119+
const std::vector<paddle::any>& attrs) {
121120
return ComputeCallHelper<Args..., TypeTag<int>>::template Compute<0, 0, 0>(
122121
inputs, vec_inputs, attrs);
123122
}
@@ -132,7 +131,7 @@ struct KernelFuncImpl<Return (*)(Args...), impl_fn> {
132131
typename... PreviousArgs>
133132
static Return Compute(const std::vector<Tensor>& inputs,
134133
const std::vector<std::vector<Tensor>>& vec_inputs,
135-
const std::vector<boost::any>& attrs,
134+
const std::vector<paddle::any>& attrs,
136135
const PreviousArgs&... pargs) {
137136
const Tensor& arg = inputs[in_idx];
138137
return ComputeCallHelper<Tail...>::template Compute<in_idx + 1,
@@ -147,7 +146,7 @@ struct KernelFuncImpl<Return (*)(Args...), impl_fn> {
147146
typename... PreviousArgs>
148147
static Return Compute(const std::vector<Tensor>& inputs,
149148
const std::vector<std::vector<Tensor>>& vec_inputs,
150-
const std::vector<boost::any>& attrs,
149+
const std::vector<paddle::any>& attrs,
151150
const PreviousArgs&... pargs) {
152151
const std::vector<Tensor>& arg = vec_inputs[vec_in_idx];
153152
return ComputeCallHelper<Tail...>::template Compute<
@@ -189,7 +188,7 @@ struct KernelFuncImpl<Return (*)(Args...), impl_fn> {
189188
template <int in_idx, int vec_in_idx, int attr_idx>
190189
static Return Compute(const std::vector<Tensor>& inputs,
191190
const std::vector<std::vector<Tensor>>& vec_inputs,
192-
const std::vector<boost::any>& attrs,
191+
const std::vector<paddle::any>& attrs,
193192
const Args&... args) {
194193
return impl_fn(args...);
195194
}
@@ -205,67 +204,67 @@ struct KernelFuncImpl<Return (*)(Args...), impl_fn> {
205204
using InferShapeFunc = std::vector<std::vector<int64_t>> (*)(
206205
const std::vector<std::vector<int64_t>>& input_shapes,
207206
const std::vector<std::vector<std::vector<int64_t>>>& vec_input_shapes,
208-
const std::vector<boost::any>& attrs);
209-
210-
#define PD_SPECIALIZE_InferShapeCallHelper_FOR_SHAPE(input_type) \
211-
template <typename... Tail> \
212-
struct InferShapeCallHelper<input_type, Tail...> { \
213-
template <int in_idx, int vec_in_idx, int attr_idx, \
214-
typename... PreviousArgs> \
215-
static Return InferShape( \
216-
const std::vector<std::vector<int64_t>>& input_shapes, \
217-
const std::vector<std::vector<std::vector<int64_t>>>& \
218-
vec_input_shapes, \
219-
const std::vector<boost::any>& attrs, const PreviousArgs&... pargs) { \
220-
input_type arg = input_shapes[in_idx]; \
221-
return InferShapeCallHelper<Tail...>::template InferShape< \
222-
in_idx + 1, vec_in_idx, attr_idx>(input_shapes, vec_input_shapes, \
223-
attrs, pargs..., arg); \
224-
} \
207+
const std::vector<paddle::any>& attrs);
208+
209+
#define PD_SPECIALIZE_InferShapeCallHelper_FOR_SHAPE(input_type) \
210+
template <typename... Tail> \
211+
struct InferShapeCallHelper<input_type, Tail...> { \
212+
template <int in_idx, int vec_in_idx, int attr_idx, \
213+
typename... PreviousArgs> \
214+
static Return InferShape( \
215+
const std::vector<std::vector<int64_t>>& input_shapes, \
216+
const std::vector<std::vector<std::vector<int64_t>>>& \
217+
vec_input_shapes, \
218+
const std::vector<paddle::any>& attrs, const PreviousArgs&... pargs) { \
219+
input_type arg = input_shapes[in_idx]; \
220+
return InferShapeCallHelper<Tail...>::template InferShape< \
221+
in_idx + 1, vec_in_idx, attr_idx>(input_shapes, vec_input_shapes, \
222+
attrs, pargs..., arg); \
223+
} \
225224
}
226225

227-
#define PD_SPECIALIZE_InferShapeCallHelper_FOR_SHAPES(input_type) \
228-
template <typename... Tail> \
229-
struct InferShapeCallHelper<input_type, Tail...> { \
230-
template <int in_idx, int vec_in_idx, int attr_idx, \
231-
typename... PreviousArgs> \
232-
static Return InferShape( \
233-
const std::vector<std::vector<int64_t>>& input_shapes, \
234-
const std::vector<std::vector<std::vector<int64_t>>>& \
235-
vec_input_shapes, \
236-
const std::vector<boost::any>& attrs, const PreviousArgs&... pargs) { \
237-
input_type arg = vec_input_shapes[vec_in_idx]; \
238-
return InferShapeCallHelper<Tail...>::template InferShape< \
239-
in_idx, vec_in_idx + 1, attr_idx>(input_shapes, vec_input_shapes, \
240-
attrs, pargs..., arg); \
241-
} \
226+
#define PD_SPECIALIZE_InferShapeCallHelper_FOR_SHAPES(input_type) \
227+
template <typename... Tail> \
228+
struct InferShapeCallHelper<input_type, Tail...> { \
229+
template <int in_idx, int vec_in_idx, int attr_idx, \
230+
typename... PreviousArgs> \
231+
static Return InferShape( \
232+
const std::vector<std::vector<int64_t>>& input_shapes, \
233+
const std::vector<std::vector<std::vector<int64_t>>>& \
234+
vec_input_shapes, \
235+
const std::vector<paddle::any>& attrs, const PreviousArgs&... pargs) { \
236+
input_type arg = vec_input_shapes[vec_in_idx]; \
237+
return InferShapeCallHelper<Tail...>::template InferShape< \
238+
in_idx, vec_in_idx + 1, attr_idx>(input_shapes, vec_input_shapes, \
239+
attrs, pargs..., arg); \
240+
} \
242241
}
243242

244-
#define PD_SPECIALIZE_InferShapeCallHelper_FOR_ATTR(attr_type) \
245-
template <typename... Tail> \
246-
struct InferShapeCallHelper<attr_type, Tail...> { \
247-
template <int in_idx, int vec_in_idx, int attr_idx, \
248-
typename... PreviousArgs> \
249-
static Return InferShape( \
250-
const std::vector<std::vector<int64_t>>& input_shapes, \
251-
const std::vector<std::vector<std::vector<int64_t>>>& \
252-
vec_input_shapes, \
253-
const std::vector<boost::any>& attrs, const PreviousArgs&... pargs) { \
254-
try { \
255-
attr_type arg = boost::any_cast<attr_type>(attrs[attr_idx]); \
256-
return InferShapeCallHelper<Tail...>::template InferShape< \
257-
in_idx, vec_in_idx, attr_idx + 1>(input_shapes, vec_input_shapes, \
258-
attrs, pargs..., arg); \
259-
} catch (boost::bad_any_cast&) { \
260-
PD_THROW( \
261-
"Attribute cast error in custom operator InferShapeFn. " \
262-
"Expected " #attr_type \
263-
" value. InferShapeFn's attribute list must be exactly same as " \
264-
"Forward " \
265-
"KernelFn's attribute list except std::vector<int64_t> " \
266-
"attribute."); \
267-
} \
268-
} \
243+
#define PD_SPECIALIZE_InferShapeCallHelper_FOR_ATTR(attr_type) \
244+
template <typename... Tail> \
245+
struct InferShapeCallHelper<attr_type, Tail...> { \
246+
template <int in_idx, int vec_in_idx, int attr_idx, \
247+
typename... PreviousArgs> \
248+
static Return InferShape( \
249+
const std::vector<std::vector<int64_t>>& input_shapes, \
250+
const std::vector<std::vector<std::vector<int64_t>>>& \
251+
vec_input_shapes, \
252+
const std::vector<paddle::any>& attrs, const PreviousArgs&... pargs) { \
253+
try { \
254+
attr_type arg = paddle::any_cast<attr_type>(attrs[attr_idx]); \
255+
return InferShapeCallHelper<Tail...>::template InferShape< \
256+
in_idx, vec_in_idx, attr_idx + 1>(input_shapes, vec_input_shapes, \
257+
attrs, pargs..., arg); \
258+
} catch (paddle::bad_any_cast&) { \
259+
PD_THROW( \
260+
"Attribute cast error in custom operator InferShapeFn. " \
261+
"Expected " #attr_type \
262+
" value. InferShapeFn's attribute list must be exactly same as " \
263+
"Forward " \
264+
"KernelFn's attribute list except std::vector<int64_t> " \
265+
"attribute."); \
266+
} \
267+
} \
269268
}
270269

271270
template <typename F, F f>
@@ -276,7 +275,7 @@ struct InferShapeFuncImpl<Return (*)(Args...), impl_fn> {
276275
static Return InferShape(
277276
const std::vector<std::vector<int64_t>>& input_shapes,
278277
const std::vector<std::vector<std::vector<int64_t>>>& vec_input_shapes,
279-
const std::vector<boost::any>& attrs) {
278+
const std::vector<paddle::any>& attrs) {
280279
return InferShapeCallHelper<Args..., TypeTag<int>>::template InferShape<
281280
0, 0, 0>(input_shapes, vec_input_shapes, attrs);
282281
}
@@ -314,7 +313,7 @@ struct InferShapeFuncImpl<Return (*)(Args...), impl_fn> {
314313
static Return InferShape(
315314
const std::vector<std::vector<int64_t>>& input_shapes,
316315
const std::vector<std::vector<std::vector<int64_t>>>& vec_input_shapes,
317-
const std::vector<boost::any>& attrs, const Args&... args) {
316+
const std::vector<paddle::any>& attrs, const Args&... args) {
318317
return impl_fn(args...);
319318
}
320319
};

paddle/fluid/framework/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ configure_file(commit.h.in commit.h)
411411
# to avoid exposing the path of the underlying file
412412
include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/platform)
413413
include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/extension/include)
414+
include_directories(${PADDLE_SOURCE_DIR}/paddle/utils)
414415

415416
if(WITH_ROCM)
416417
hip_library(custom_tensor SRCS ../extension/src/ext_tensor.cc DEPS lod_tensor memory enforce)

paddle/fluid/framework/custom_operator.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ limitations under the License. */
3434
#include "paddle/fluid/framework/tensor.h"
3535
#include "paddle/fluid/platform/dynload/dynamic_loader.h"
3636
#include "paddle/fluid/string/string_helper.h"
37+
#include "paddle/utils/any.h"
3738

3839
namespace paddle {
3940
namespace framework {
@@ -149,7 +150,7 @@ static void RunKernelFunc(const framework::ExecutionContext& ctx,
149150
}
150151
}
151152

152-
std::vector<boost::any> custom_attrs;
153+
std::vector<paddle::any> custom_attrs;
153154
for (auto& attr_str : attrs) {
154155
auto attr_name_and_type = detail::ParseAttrStr(attr_str);
155156
auto attr_name = attr_name_and_type[0];
@@ -605,7 +606,7 @@ void RegisterOperatorWithMetaInfo(
605606
}
606607
}
607608

608-
std::vector<boost::any> custom_attrs;
609+
std::vector<paddle::any> custom_attrs;
609610
for (auto& attr_str : op_attrs) {
610611
auto attr_name_and_type = detail::ParseAttrStr(attr_str);
611612
auto attr_name = attr_name_and_type[0];

paddle/fluid/framework/ir/graph.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ limitations under the License. */
2525
#include "paddle/fluid/framework/program_desc.h"
2626
#include "paddle/fluid/platform/enforce.h"
2727
#include "paddle/fluid/platform/variant.h"
28+
#include "paddle/utils/any.h"
2829

2930
DECLARE_bool(convert_all_blocks);
3031

@@ -147,8 +148,8 @@ class Graph {
147148
platform::errors::PreconditionNotMet(
148149
"%s attribute not registered for current graph.", attr_name));
149150
try {
150-
return *boost::any_cast<AttrType *>(attrs_.at(attr_name));
151-
} catch (boost::bad_any_cast &) {
151+
return *paddle::any_cast<AttrType *>(attrs_.at(attr_name));
152+
} catch (paddle::bad_any_cast &) {
152153
PADDLE_THROW(platform::errors::InvalidArgument(
153154
"Invalid attribute type of %s, expected: %s, received: %s.",
154155
attr_name, platform::demangle(typeid(AttrType *).name()), // NOLINT
@@ -426,7 +427,7 @@ class Graph {
426427
const Graph *main_graph_; // not owned.
427428
std::vector<std::unique_ptr<Graph>> sub_graphs_;
428429

429-
std::map<std::string, boost::any> attrs_;
430+
std::map<std::string, paddle::any> attrs_;
430431
std::map<std::string, std::function<void(void)>> attr_dels_;
431432
std::map<ir::Node *, std::unique_ptr<ir::Node>> nodes_;
432433
std::unordered_set<ir::Node *> node_set_;

paddle/fluid/framework/ir/node.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ limitations under the License. */
2323
#include "paddle/fluid/framework/op_desc.h"
2424
#include "paddle/fluid/framework/var_desc.h"
2525
#include "paddle/fluid/platform/macros.h"
26-
26+
#include "paddle/utils/any.h"
2727
namespace paddle {
2828
namespace framework {
2929
class OpDesc;
@@ -104,8 +104,8 @@ class Node {
104104
template <typename T>
105105
T& Wrapper() {
106106
try {
107-
return *boost::any_cast<T*>(wrapper_);
108-
} catch (boost::bad_any_cast&) {
107+
return *paddle::any_cast<T*>(wrapper_);
108+
} catch (paddle::bad_any_cast&) {
109109
PADDLE_THROW(platform::errors::InvalidArgument(
110110
"Invalid wrapper type error, expected %s, actual %s.",
111111
typeid(T).name(), wrapper_type_.name()));
@@ -277,7 +277,7 @@ class Node {
277277

278278
Node() = delete;
279279

280-
boost::any wrapper_;
280+
paddle::any wrapper_;
281281
std::function<void(void)> wrapper_deleter_;
282282
std::type_index wrapper_type_ = std::type_index(typeid(void));
283283

0 commit comments

Comments
 (0)