Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion paddle/phi/kernels/onednn/conv_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ void ConvKernel(const Context& dev_ctx,
dev_ctx.GetDnnAttr("mkldnn_data_type")) ==
"bfloat16"
: false;
bool is_onednn_BFLOAT16 =
dev_ctx.HasDnnAttr("onednn_data_type")
? PADDLE_GET_CONST(std::string,
dev_ctx.GetDnnAttr("onednn_data_type")) ==
"bfloat16"
: is_BFLOAT16;
bool force_fp32_output =
dev_ctx.HasDnnAttr("force_fp32_output")
? PADDLE_GET_CONST(bool, dev_ctx.GetDnnAttr("force_fp32_output"))
Expand All @@ -59,7 +65,7 @@ void ConvKernel(const Context& dev_ctx,
groups,
data_format,
is_test,
is_BFLOAT16,
is_onednn_BFLOAT16,
"",
false,
force_fp32_output,
Expand Down
24 changes: 21 additions & 3 deletions paddle/phi/kernels/onednn/conv_transpose_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,13 @@ class ConvTransposeOneDNNHandlerT
dev_ctx.GetDnnAttr("mkldnn_data_type")) ==
"bfloat16"
: false;
if (is_BFLOAT16 || std::is_same<T_out, dtype::bfloat16>::value) {
const bool is_onednn_BFLOAT16 =
dev_ctx.HasDnnAttr("onednn_data_type")
? PADDLE_GET_CONST(std::string,
dev_ctx.GetDnnAttr("onednn_data_type")) ==
"bfloat16"
: is_BFLOAT16;
if (is_onednn_BFLOAT16 || std::is_same<T_out, dtype::bfloat16>::value) {
data_type = dnnl::memory::data_type::bf16;
}

Expand Down Expand Up @@ -494,11 +500,17 @@ void Conv2dTransposeKernel(const Context& dev_ctx,
dev_ctx.GetDnnAttr("mkldnn_data_type")) ==
"bfloat16"
: false;
const bool is_onednn_BFLOAT16 =
dev_ctx.HasDnnAttr("onednn_data_type")
? PADDLE_GET_CONST(std::string,
dev_ctx.GetDnnAttr("onednn_data_type")) ==
"bfloat16"
: is_BFLOAT16;
const bool force_fp32_output =
dev_ctx.HasDnnAttr("force_fp32_output")
? PADDLE_GET_CONST(bool, dev_ctx.GetDnnAttr("force_fp32_output"))
: false;
const bool use_bfloat16 = (!force_fp32_output && is_BFLOAT16);
const bool use_bfloat16 = (!force_fp32_output && is_onednn_BFLOAT16);

if (use_bfloat16) {
Execute<T, dtype::bfloat16>(dev_ctx,
Expand Down Expand Up @@ -545,11 +557,17 @@ void Conv2dTransposeBiasKernel(const Context& dev_ctx,
dev_ctx.GetDnnAttr("mkldnn_data_type")) ==
"bfloat16"
: false;
const bool is_one_BFLOAT16 =
dev_ctx.HasDnnAttr("onednn_data_type")
? PADDLE_GET_CONST(std::string,
dev_ctx.GetDnnAttr("onednn_data_type")) ==
"bfloat16"
: is_BFLOAT16;
const bool force_fp32_output =
dev_ctx.HasDnnAttr("force_fp32_output")
? PADDLE_GET_CONST(bool, dev_ctx.GetDnnAttr("force_fp32_output"))
: false;
const bool use_bfloat16 = (!force_fp32_output && is_BFLOAT16);
const bool use_bfloat16 = (!force_fp32_output && is_one_BFLOAT16);

if (use_bfloat16) {
Execute<T, dtype::bfloat16>(dev_ctx,
Expand Down