8000 [nativert] move recordfunction (#153088) by dolpm · Pull Request #153630 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

[nativert] move recordfunction (#153088) #153630

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

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 27 additions & 0 deletions torch/csrc/autograd/record_function_ops.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <ATen/record_function.h>
#include <torch/custom_class.h>
#include <torch/library.h>
#include <optional>

namespace torch::autograd::profiler {
Expand All @@ -24,4 +26,29 @@ TORCH_API c10::intrusive_ptr<c10::ivalue::Future> _call_end_callbacks_on_fut_new
const c10::intrusive_ptr<PythonRecordFunction>& record,
const c10::intrusive_ptr<c10::ivalue::Future>& fut);

/**
* RAII wrapper that behaves similarly to torch.profiler.record_function.
*/
class RecordFunction {
public:
RecordFunction() = delete;
RecordFunction(const RecordFunction&) = delete;
RecordFunction& operator=(const RecordFunction&) = delete;
RecordFunction(RecordFunction&&) = delete;
RecordFunction& operator=(RecordFunction&&) = delete;

explicit RecordFunction(const std::string& name) {
recordFunction_ =
torch::autograd::profiler::record_function_enter_new(name);
}

~RecordFunction() {
recordFunction_->record.end();
}

private:
c10::intrusive_ptr<torch::autograd::profiler::PythonRecordFunction>
recordFunction_;
};

} // namespace torch::autograd::profiler
Loading
0