Skip to content

[Inference] add nvtx event for profiling #66133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
#include "paddle/fluid/pir/dialect/operator/utils/op_yaml_info_parser.h"
#include "paddle/fluid/platform/collective_helper.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/profiler/event_tracing.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/core/meta_tensor.h"
#include "paddle/phi/core/type_defs.h"

#include "paddle/pir/include/core/builtin_attribute.h"
#include "paddle/pir/include/core/operation.h"
#include "paddle/pir/include/core/value.h"
Expand Down Expand Up @@ -178,11 +178,20 @@ PhiKernelInstruction::~PhiKernelInstruction() { delete phi_kernel_; }
void PhiKernelInstruction::Run() {
VLOG(6) << "Begin run op " << phi_op_name_ << " infer meta.";
if (infer_meta_interface_) {
platform::RecordEvent record_event("PhiKernelInstruction::infermeta",
platform::TracerEventType::UserDefined,
1);
infer_meta_interface_->infer_meta_(&(infer_meta_context_));
}
VLOG(6) << "End run op " << phi_op_name_ << " infer meta.";
VLOG(6) << "Begin run op " << phi_op_name_ << " kernel.";
(*(phi_kernel_))(&(kernel_context_));
{
platform::RecordEvent record_event("PhiKernelInstruction::kernel launch",
platform::TracerEventType::UserDefined,
1);
(*(phi_kernel_))(&(kernel_context_));
}

VLOG(6) << "End run op " << phi_op_name_ << " kernel.";
}

Expand Down
6 changes: 5 additions & 1 deletion paddle/fluid/framework/new_executor/pir_interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,11 @@ void PirInterpreter::RunInstructionBase(InstructionBase* instr_node) {
}

if (!instr_node->IsArtificial()) {
instr_node->Run();
{
platform::RecordEvent record(
"InstrRun", platform::TracerEventType::UserDefined, 10);
instr_node->Run();
}

if (FLAGS_benchmark) {
instr_node->DeviceContext().Wait();
Expand Down
15 changes: 15 additions & 0 deletions paddle/fluid/ir_adaptor/translator/op_translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3179,6 +3179,20 @@ struct RepeatInterLeaveGradOpTranscriber : public OpTranscriber {
}
};

struct TopPSamplingOpTranscriber : public OpTranscriber {
void HandleNonexistentAttribute(pir::IrContext* ctx,
pir::AttributeMap* attribute_map,
const OpAttributeInfo& info) override {
if (info.name == "seed") {
(*attribute_map)[info.name] = pir::Int32Attribute::get(ctx, -1);
} else if (info.name == "k") {
(*attribute_map)[info.name] = pir::Int32Attribute::get(ctx, 0);
} else if (info.name == "mode") {
(*attribute_map)[info.name] = pir::StrAttribute::get(ctx, "truncated");
}
}
};

struct FusedElemwiseAddActivationOpTranscriber : public OpTranscriber {
void HandleNonexistentAttribute(pir::IrContext* ctx,
pir::AttributeMap* attribute_map,
Expand Down Expand Up @@ -3629,6 +3643,7 @@ OpTranslator::OpTranslator() {
special_handlers["slice"] = SliceOpTranscriber();
special_handlers["split"] = SplitOpTranscriber();
special_handlers["sum"] = AddNOpTranscriber();
special_handlers["top_p_sampling"] = TopPSamplingOpTranscriber();
special_handlers["tril_triu"] = TrilAndTriuOpTranscriber();
special_handlers["tril_triu_grad"] = TrilAndTriuGradOpTranscriber();
special_handlers["matmul"] = LegacyMatmulOpTranscriber();
Expand Down