|
|
|
@ -23,23 +23,9 @@
|
|
|
|
|
#include "paddle/fluid/platform/device_context.h"
|
|
|
|
|
#include "paddle/fluid/platform/enforce.h"
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_GPERFTOOLS
|
|
|
|
|
#include "gperftools/profiler.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
DEFINE_string(
|
|
|
|
|
tracer_profile_fname, "",
|
|
|
|
|
"Profiler filename for imperative tracer, which generated by gperftools."
|
|
|
|
|
"Only valid when compiled `WITH_PROFILER=ON`. Empty if disable.");
|
|
|
|
|
|
|
|
|
|
namespace paddle {
|
|
|
|
|
namespace imperative {
|
|
|
|
|
|
|
|
|
|
static std::once_flag gTracerProfileOnce;
|
|
|
|
|
#ifdef WITH_GPERFTOOLS
|
|
|
|
|
static bool gTracerProfilerStarted = false;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void CreateGradOp(const framework::OpDesc& op_desc,
|
|
|
|
|
const std::unordered_set<std::string>& no_grad_set,
|
|
|
|
|
const std::vector<framework::BlockDesc*>& grad_sub_block,
|
|
|
|
@ -146,17 +132,6 @@ framework::VariableNameMap CreateOutputVarNameMap(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Tracer::Tracer(framework::BlockDesc* root_block) : root_block_(root_block) {
|
|
|
|
|
if (!FLAGS_tracer_profile_fname.empty()) {
|
|
|
|
|
std::call_once(gTracerProfileOnce, [] {
|
|
|
|
|
#ifdef WITH_GPERFTOOLS
|
|
|
|
|
ProfilerStart(FLAGS_tracer_profile_fname.c_str());
|
|
|
|
|
gTracerProfilerStarted = true;
|
|
|
|
|
#else
|
|
|
|
|
LOG(WARNING) << "Paddle is not compiled with gperftools. "
|
|
|
|
|
"FLAGS_tracer_profile_fname will be ignored";
|
|
|
|
|
#endif
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::set<std::string> Tracer::Trace(OpBase* op, const VarBasePtrMap& inputs,
|
|
|
|
@ -164,12 +139,6 @@ std::set<std::string> Tracer::Trace(OpBase* op, const VarBasePtrMap& inputs,
|
|
|
|
|
framework::AttributeMap attrs_map,
|
|
|
|
|
const platform::Place expected_place,
|
|
|
|
|
const bool stop_gradient) {
|
|
|
|
|
#ifdef WITH_GPERFTOOLS
|
|
|
|
|
if (gTracerProfilerStarted) {
|
|
|
|
|
ProfilerFlush();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
framework::VariableValueMap invars_map;
|
|
|
|
|
framework::VariableValueMap outvars_map;
|
|
|
|
|
|
|
|
|
@ -184,7 +153,6 @@ std::set<std::string> Tracer::Trace(OpBase* op, const VarBasePtrMap& inputs,
|
|
|
|
|
inp->Name());
|
|
|
|
|
|
|
|
|
|
invars.emplace_back(inp->var_);
|
|
|
|
|
op->TrackPreOp(inp, it.first);
|
|
|
|
|
if (!stop_gradient) {
|
|
|
|
|
current_vars_map[inp->Name()] = inp;
|
|
|
|
|
}
|
|
|
|
@ -192,6 +160,7 @@ std::set<std::string> Tracer::Trace(OpBase* op, const VarBasePtrMap& inputs,
|
|
|
|
|
<< " inited: " << inp->var_->IsInitialized()
|
|
|
|
|
<< " stop_grad: " << inp->IsStopGradient();
|
|
|
|
|
}
|
|
|
|
|
op->TrackPreOp(it.first, it.second);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
op->output_vars_ = outputs;
|
|
|
|
@ -319,9 +288,7 @@ std::vector<VarBase*> Tracer::PyTrace(OpBase* op,
|
|
|
|
|
std::vector<framework::Variable*> ret_vars =
|
|
|
|
|
PyLayer::Apply(op->forward_id_, inputs);
|
|
|
|
|
|
|
|
|
|
for (VarBase* inp : inputs) {
|
|
|
|
|
op->TrackPreOp(inp, PyLayer::kFwdInp);
|
|
|
|
|
}
|
|
|
|
|
op->TrackPreOp(PyLayer::kFwdInp, inputs);
|
|
|
|
|
|
|
|
|
|
std::vector<VarBase*>& outputs = op->output_vars_[PyLayer::kFwdOut];
|
|
|
|
|
outputs.reserve(ret_vars.size());
|
|
|
|
|