Skip to content
Open
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: 8 additions & 0 deletions paddle/fluid/framework/ir/auto_mixed_precision_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "paddle/phi/backends/device_manager.h"
#endif

PHI_DECLARE_bool(enable_pir_in_executor);

namespace paddle {
namespace framework {
namespace ir {
Expand All @@ -40,6 +42,9 @@ bool PhiKernelSupportPrecision(
phi::DataType data_type,
phi::DataLayout layout = phi::DataLayout::ALL_LAYOUT) {
const auto& kernels = phi::KernelFactory::Instance().kernels();
// for (auto [k, v] : kernels) {
// LOG(INFO) << "kernel name " << k << std::endl;
// }
if (kernels.count(op_type) == 0) {
return false;
}
Expand Down Expand Up @@ -270,6 +275,9 @@ void AutoMixedPrecisionPass::Init(Graph* graph) const {
}

void AutoMixedPrecisionPass::ApplyImpl(Graph* graph) const {
if (FLAGS_enable_pir_in_executor) {
return;
}
PADDLE_ENFORCE_NOT_NULL(graph,
platform::errors::PreconditionNotMet(
"During the auto_mixed_precision_pass, the graph "
Expand Down
19 changes: 16 additions & 3 deletions paddle/fluid/inference/api/analysis_predictor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
#endif

#include "paddle/fluid/ir_adaptor/translator/translate.h"
#include "paddle/fluid/pir/transforms/auto_mixed_precision_pass.h"
#include "paddle/fluid/pir/transforms/constant_folding_pass.h"
#include "paddle/fluid/pir/transforms/dead_code_elimination_pass.h"
#include "paddle/fluid/pir/transforms/fusion/conv2d_add_act_fuse_pass.h"
Expand Down Expand Up @@ -811,6 +812,20 @@ bool AnalysisPredictor::PrepareExecutor() {
gpu_pm.AddPass(::pir::CreateMatmulScaleFusePass());
//----------------------------------------------------------------------------------------------//

//----------------------------------------------------------------------------------------------//
// Functional pass
// Do auto mixed precision pass first, so do not need to handle
// shadowoutput.
auto auto_mixed_precision_pass = ::pir::CreateAutoMixedPrecisionPass();
auto_mixed_precision_pass->SetNotOwned(pir::kPlaceAttr, &place_);
phi::DataType data_type =
ConvertPrecision(config_.mixed_precision_mode_);
auto_mixed_precision_pass->SetNotOwned("__mixed_precision_mode__",
&data_type);
gpu_pm.AddPass(std::move(auto_mixed_precision_pass));
gpu_pm.AddPass(::pir::CreateIdentityOpCleanPass());
//----------------------------------------------------------------------------------------------//

//----------------------------------------------------------------------------------------------//
// Basic pass required by the framework
auto params_sync_among_devices_pass =
Expand All @@ -831,9 +846,7 @@ bool AnalysisPredictor::PrepareExecutor() {
if (!config_.glog_info_disabled()) {
gpu_pm.EnablePrintStatistics();
}
if (config_.ir_debug_) {
gpu_pm.EnableIRPrinting();
}
gpu_pm.EnableIRPrinting();
gpu_pm.Run(pir_program_.get());
} else {
::pir::PassManager cpu_pm(::pir::IrContext::Instance(), 2);
Expand Down
Loading