Skip to content

Commit f23cfd6

Browse files
authored
Merge branch 'develop' into eager_dygraph_codege_fix_ld_path
2 parents 5da5369 + dd3afc9 commit f23cfd6

File tree

134 files changed

+3546
-886
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+3546
-886
lines changed

cmake/inference_lib.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,16 @@ include_directories(${CMAKE_BINARY_DIR}/../paddle/fluid/framework/io)
218218

219219
# copy api headers for pten & custom op
220220
copy(inference_lib_dist
221-
SRCS ${PADDLE_SOURCE_DIR}/paddle/pten/api/ext/*
221+
SRCS ${PADDLE_SOURCE_DIR}/paddle/pten/api/ext/*.h
222222
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/api/ext/)
223223
copy(inference_lib_dist
224-
SRCS ${PADDLE_SOURCE_DIR}/paddle/pten/api/include/*
224+
SRCS ${PADDLE_SOURCE_DIR}/paddle/pten/api/include/*.h
225225
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/api/include/)
226226
copy(inference_lib_dist
227227
SRCS ${PADDLE_SOURCE_DIR}/paddle/pten/api/all.h
228228
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include/experimental/pten/api/)
229229
copy(inference_lib_dist
230-
SRCS ${PADDLE_SOURCE_DIR}/paddle/pten/common/*
230+
SRCS ${PADDLE_SOURCE_DIR}/paddle/pten/common/*.h
231231
${PADDLE_SOURCE_DIR}/paddle/fluid/platform/bfloat16.h
232232
${PADDLE_SOURCE_DIR}/paddle/fluid/platform/complex.h
233233
${PADDLE_SOURCE_DIR}/paddle/fluid/platform/float16.h

cmake/pten.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ string(FIND ${TARGET_PATH} "experimental" pos)
2020
if (pos GREATER 1)
2121
file(GLOB HEADERS "${TARGET_PATH}/*" "*.h")
2222
foreach(header ${HEADERS})
23-
string(FIND ${header} ".h" hpos)
24-
if (hpos GREATER 1)
23+
if (${header} MATCHES ".*.h$")
2524
file(READ ${header} HEADER_CONTENT)
2625
string(REPLACE "paddle/pten/" "paddle/include/experimental/pten/" HEADER_CONTENT "${HEADER_CONTENT}")
2726
string(REPLACE "paddle/utils/" "paddle/include/experimental/utils/" HEADER_CONTENT "${HEADER_CONTENT}")

cmake/third_party.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ endif (WIN32)
393393

394394
if (WITH_INFRT)
395395
include(external/llvm)
396-
list(APPEND third_party_deps external_llvm)
396+
list(APPEND third_party_deps ${llvm_libs})
397397
endif()
398398

399399
if (WITH_IPU)

paddle/fluid/framework/custom_operator.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ static void RunKernelFunc(const framework::ExecutionContext& ctx,
110110
const std::vector<std::string>& outputs,
111111
const std::vector<std::string>& attrs) {
112112
VLOG(1) << "Custom Operator: Start run KernelFunc.";
113-
std::vector<paddle::Tensor> custom_ins;
114-
std::vector<std::vector<paddle::Tensor>> custom_vec_ins;
113+
std::vector<paddle::experimental::Tensor> custom_ins;
114+
std::vector<std::vector<paddle::experimental::Tensor>> custom_vec_ins;
115115
for (auto& in_name : inputs) {
116116
VLOG(1) << "Custom Operator: input name - " << in_name;
117117
if (detail::IsDuplicableVar(in_name)) {
@@ -120,7 +120,7 @@ static void RunKernelFunc(const framework::ExecutionContext& ctx,
120120
PADDLE_ENFORCE_NE(vec_x.empty(), true,
121121
platform::errors::NotFound(
122122
"Input vector<tensor> (%s) is empty.", in_name));
123-
std::vector<paddle::Tensor> custom_vec_in;
123+
std::vector<paddle::experimental::Tensor> custom_vec_in;
124124
for (size_t i = 0; i < vec_x.size(); ++i) {
125125
auto* x = vec_x[i];
126126
PADDLE_ENFORCE_NOT_NULL(
@@ -132,7 +132,7 @@ static void RunKernelFunc(const framework::ExecutionContext& ctx,
132132
"The %d-th tensor in input vector<tensor> (%s) "
133133
"is not initialized.",
134134
i, in_name));
135-
paddle::Tensor custom_t;
135+
paddle::experimental::Tensor custom_t;
136136
custom_t.set_impl(std::move(experimental::MakePtenDenseTensor(*x)));
137137
custom_vec_in.emplace_back(custom_t);
138138
}
@@ -144,7 +144,7 @@ static void RunKernelFunc(const framework::ExecutionContext& ctx,
144144
PADDLE_ENFORCE_EQ(x->IsInitialized(), true,
145145
platform::errors::InvalidArgument(
146146
"Input tensor (%s) is not initialized.", in_name));
147-
paddle::Tensor custom_in;
147+
paddle::experimental::Tensor custom_in;
148148
custom_in.set_impl(std::move(experimental::MakePtenDenseTensor(*x)));
149149
custom_ins.emplace_back(custom_in);
150150
}
@@ -207,14 +207,14 @@ static void RunKernelFunc(const framework::ExecutionContext& ctx,
207207
"Tensors.",
208208
vec_true_outs.size(), outs.size()));
209209
for (size_t j = 0; j < vec_true_outs.size(); ++j) {
210-
experimental::MovesStorage(
210+
experimental::MovesSharedStorage(
211211
std::dynamic_pointer_cast<pten::DenseTensor>(outs.at(j).impl())
212212
.get(),
213213
vec_true_outs.at(j));
214214
}
215215
} else {
216216
auto* true_out = ctx.Output<Tensor>(out_name);
217-
experimental::MovesStorage(
217+
experimental::MovesSharedStorage(
218218
std::dynamic_pointer_cast<pten::DenseTensor>(outs.at(i).impl())
219219
.get(),
220220
true_out);

paddle/fluid/framework/ir/graph_pattern_detector.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,23 @@ PDNode *patterns::OrphanedBfloat16::operator()() {
24122412
return next_op;
24132413
}
24142414

2415+
PDNode *patterns::UnsupportedBfloat16::operator()() {
2416+
auto *prev_op = pattern->NewNode(prev_op_repr())->assert_is_op();
2417+
prev_op->assert_more([&](Node *node) {
2418+
return node->Op()->HasAttr("mkldnn_data_type") == false;
2419+
});
2420+
auto *prev_out = pattern->NewNode(prev_out_repr())->AsOutput();
2421+
2422+
auto *op = pattern->NewNode(op_repr())->assert_is_op();
2423+
op->assert_more([&](Node *node) {
2424+
return node->Op()->GetAttrIfExists<std::string>("mkldnn_data_type") ==
2425+
"bfloat16";
2426+
});
2427+
prev_op->LinksTo({prev_out});
2428+
op->LinksFrom({prev_out});
2429+
return op;
2430+
}
2431+
24152432
PDNode *patterns::LastBfloat16Ops::operator()() {
24162433
auto *op = pattern->NewNode(op_repr())->assert_is_op();
24172434
op->assert_more([&](Node *node) {

paddle/fluid/framework/ir/graph_pattern_detector.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,16 @@ struct OrphanedBfloat16 : public PatternBase {
14161416
PATTERN_DECL_NODE(next_op);
14171417
};
14181418

1419+
struct UnsupportedBfloat16 : public PatternBase {
1420+
UnsupportedBfloat16(PDPattern* pattern, const std::string& name_scope)
1421+
: PatternBase(pattern, name_scope, "unsupported_bfloat16") {}
1422+
PDNode* operator()();
1423+
1424+
PATTERN_DECL_NODE(prev_op);
1425+
PATTERN_DECL_NODE(prev_out);
1426+
PATTERN_DECL_NODE(op);
1427+
};
1428+
14191429
struct LastBfloat16Ops : public PatternBase {
14201430
LastBfloat16Ops(PDPattern* pattern, const std::string& name_scope)
14211431
: PatternBase(pattern, name_scope, "last_bfloat16_ops") {}

paddle/fluid/framework/ir/ipu/infer_shape_pass.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@
1313
// limitations under the License.
1414

1515
#include "paddle/fluid/framework/ir/ipu/infer_shape_pass.h"
16-
17-
#include "paddle/fluid/platform/device/ipu/ipu_backend.h"
18-
1916
#include "paddle/fluid/framework/ddim.h"
2017
#include "paddle/fluid/framework/ir/graph_helper.h"
2118
#include "paddle/fluid/framework/ir/pass_tester_helper.h"
2219
#include "paddle/fluid/framework/op_registry.h"
2320
#include "paddle/fluid/framework/variable_helper.h"
21+
#include "paddle/fluid/platform/device/ipu/ipu_backend.h"
2422

2523
namespace paddle {
2624
namespace framework {

paddle/fluid/framework/ir/mkldnn/conv_bias_mkldnn_fuse_pass.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,21 @@ Conv3DBiasFusePass::Conv3DBiasFusePass() {
147147
.IsType<std::vector<int>>()
148148
.End()
149149
.AddAttr("data_format")
150-
.IsStringIn({"NCHW", "NHWC"})
150+
.IsStringIn({"NDHWC", "NCDHW"})
151+
.End();
152+
153+
AddOpCompat(OpCompat("elementwise_add"))
154+
.AddInput("X")
155+
.IsTensor()
156+
.End()
157+
.AddInput("Y")
158+
.IsTensor()
159+
.End()
160+
.AddOutput("Out")
161+
.IsTensor()
162+
.End()
163+
.AddAttr("axis")
164+
.IsNumGE(1)
151165
.End();
152166
}
153167

paddle/fluid/framework/ir/mkldnn/conv_concat_relu_mkldnn_fuse_pass.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ConvConcatReLUFusePass::ConvConcatReLUFusePass() {
5959
.IsType<std::vector<int>>()
6060
.End()
6161
.AddAttr("data_format")
62-
.IsStringIn({"NCHW", "NHWC", "AnyLayout"})
62+
.IsStringIn({"NCHW"})
6363
.End();
6464

6565
AddOpCompat(OpCompat("concat"))

paddle/fluid/framework/ir/mkldnn/cpu_bfloat16_placement_pass.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,31 @@ void CPUBfloat16PlacementPass::RemoveOrphanedOperators(
7171
gpd(graph, handler);
7272
}
7373

74+
void CPUBfloat16PlacementPass::RemoveUnsupportedOperators(
75+
ir::Graph* graph, int* bfloat16_operators) const {
76+
// now quantize is supported FP32 only, so try to find
77+
// bfloat16 operator that input type is not FP32
78+
GraphPatternDetector gpd;
79+
patterns::UnsupportedBfloat16 unsupported_bfloat16_pattern{
80+
gpd.mutable_pattern(), "unsupported_bfloat16"};
81+
unsupported_bfloat16_pattern();
82+
auto handler = [&](const GraphPatternDetector::subgraph_t& subgraph,
83+
Graph* g) {
84+
GET_IR_NODE_FROM_SUBGRAPH(prev_out, prev_out, unsupported_bfloat16_pattern);
85+
GET_IR_NODE_FROM_SUBGRAPH(op, op, unsupported_bfloat16_pattern);
86+
if ((prev_out->Var()->GetDataType() != proto::VarType::FP32)) {
87+
op->Op()->SetAttr("mkldnn_data_type", std::string("float32"));
88+
bfloat16_operators--;
89+
}
90+
};
91+
gpd(graph, handler);
92+
}
93+
7494
void CPUBfloat16PlacementPass::ApplyImpl(ir::Graph* graph) const {
7595
int bfloat16_operators = 0;
7696
SetMkldnnDataType(graph, &bfloat16_operators);
7797
RemoveOrphanedOperators(graph, &bfloat16_operators);
98+
RemoveUnsupportedOperators(graph, &bfloat16_operators);
7899
PrettyLogDetail("--- marked %d operators to bfloat16 ",
79100
bfloat16_operators);
80101
}

0 commit comments

Comments
 (0)