mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[4/N] Move remaining c10::variant calls to std::variant (#110382)
Fixes #ISSUE_NUMBER Pull Request resolved: https://github.com/pytorch/pytorch/pull/110382 Approved by: https://github.com/Skylion007
This commit is contained in:
@ -7,7 +7,6 @@
|
||||
#include <c10/util/flat_hash_map.h>
|
||||
#include <c10/util/irange.h>
|
||||
#include <c10/util/overloaded.h>
|
||||
#include <c10/util/variant.h>
|
||||
|
||||
#include <torch/csrc/profiler/api.h>
|
||||
#include <torch/csrc/profiler/collection.h>
|
||||
@ -150,7 +149,7 @@ auto parseArgData(
|
||||
struct MetadataBase {
|
||||
MetadataBase(const std::shared_ptr<Result>& result)
|
||||
: kineto_activity_{result->kineto_activity_} {
|
||||
if (c10::holds_alternative<ExtraFields<EventType::Kineto>>(
|
||||
if (std::holds_alternative<ExtraFields<EventType::Kineto>>(
|
||||
result->extra_fields_)) {
|
||||
// In order to add metadata we have to downcast from
|
||||
// `libkineto::ITraceActivity` to `libkineto::GenericTraceActivity`. We
|
||||
@ -743,20 +742,25 @@ const c10::ArrayRef<std::string> KinetoEvent::stack() const {
|
||||
return !i.jit_stack_.empty() ? i.jit_stack_ : python_stack_;
|
||||
};
|
||||
|
||||
using out_t = const c10::ArrayRef<std::string>;
|
||||
return result_->visit(c10::overloaded(
|
||||
[&](const ExtraFields<EventType::TorchOp>& i) -> out_t { return get(i); },
|
||||
[&](const ExtraFields<EventType::Backend>& i) -> out_t { return get(i); },
|
||||
[&](const auto&) -> out_t { return python_stack_; }));
|
||||
auto const& extra_fields = result_->extra_fields_;
|
||||
if (auto p = std::get_if<ExtraFields<EventType::TorchOp>>(&extra_fields)) {
|
||||
return get(*p);
|
||||
}
|
||||
if (auto p = std::get_if<ExtraFields<EventType::Backend>>(&extra_fields)) {
|
||||
return get(*p);
|
||||
}
|
||||
return python_stack_;
|
||||
}
|
||||
|
||||
const c10::ArrayRef<std::string> KinetoEvent::moduleHierarchy() const {
|
||||
return result_->visit(c10::overloaded(
|
||||
[](const ExtraFields<EventType::TorchOp>& e)
|
||||
-> const c10::ArrayRef<std::string> { return e.jit_modules_; },
|
||||
[](const ExtraFields<EventType::Backend>& e)
|
||||
-> const c10::ArrayRef<std::string> { return e.jit_modules_; },
|
||||
[](const auto&) -> const c10::ArrayRef<std::string> { return {}; }));
|
||||
auto const& extra_fields = result_->extra_fields_;
|
||||
if (auto p = std::get_if<ExtraFields<EventType::TorchOp>>(&extra_fields)) {
|
||||
return p->jit_modules_;
|
||||
}
|
||||
if (auto p = std::get_if<ExtraFields<EventType::Backend>>(&extra_fields)) {
|
||||
return p->jit_modules_;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
uint64_t KinetoEvent::durationUs() const {
|
||||
|
@ -963,7 +963,7 @@ class PostProcess {
|
||||
const auto initial_size = out.size();
|
||||
auto pop = [](stack_t& stack, time_t t) {
|
||||
TORCH_INTERNAL_ASSERT(!stack.empty(), "Python replay stack is empty.");
|
||||
c10::get<ExtraFields<E>>(stack.back()->extra_fields_).end_time_ns_ = t;
|
||||
std::get<ExtraFields<E>>(stack.back()->extra_fields_).end_time_ns_ = t;
|
||||
stack.pop_back();
|
||||
};
|
||||
|
||||
@ -1002,7 +1002,7 @@ class PostProcess {
|
||||
auto it = out.rbegin();
|
||||
for (C10_UNUSED auto _ : c10::irange(initial_size, out.size())) {
|
||||
const auto python_tid =
|
||||
c10::get<ExtraFields<E>>((*it)->extra_fields_).python_tid_;
|
||||
std::get<ExtraFields<E>>((*it)->extra_fields_).python_tid_;
|
||||
if ((*it)->start_tid_ == NoTID && SOFT_ASSERT(E == EventType::PyCall)) {
|
||||
const auto& tid_info =
|
||||
tid_map.insert({python_tid, {NoTID, kineto::DeviceAndResource()}})
|
||||
@ -1072,7 +1072,7 @@ std::vector<std::shared_ptr<Result>> PythonTracer::getEvents(
|
||||
|
||||
PythonIDVisitor id_visitor;
|
||||
for (auto& i : out) {
|
||||
c10::visit(id_visitor, i->extra_fields_);
|
||||
std::visit(id_visitor, i->extra_fields_);
|
||||
}
|
||||
|
||||
return out;
|
||||
|
@ -694,7 +694,7 @@ void generateForwardBackwardLink(
|
||||
std::unordered_map<uint64_t, libkineto::GenericTraceActivity*>&
|
||||
tidSeq2activity) {
|
||||
const ExtraFields<EventType::TorchOp>& extra_fields =
|
||||
c10::get<ExtraFields<EventType::TorchOp>>(profiler_result.extra_fields_);
|
||||
std::get<ExtraFields<EventType::TorchOp>>(profiler_result.extra_fields_);
|
||||
if (extra_fields.forward_tid_ > 0) {
|
||||
// act is backward op.
|
||||
uint64_t key = getForwardThreadKey(
|
||||
@ -777,9 +777,9 @@ void generateForwardBackwardLinks(
|
||||
torch_events.end(),
|
||||
[](const result_activity_t& left, const result_activity_t& right) {
|
||||
auto left_end_time =
|
||||
c10::get<ExtraFields<EventType::TorchOp>>(left.first->extra_fields_)
|
||||
std::get<ExtraFields<EventType::TorchOp>>(left.first->extra_fields_)
|
||||
.end_time_ns_;
|
||||
auto right_end_time = c10::get<ExtraFields<EventType::TorchOp>>(
|
||||
auto right_end_time = std::get<ExtraFields<EventType::TorchOp>>(
|
||||
right.first->extra_fields_)
|
||||
.end_time_ns_;
|
||||
return left_end_time < right_end_time;
|
||||
@ -1140,7 +1140,7 @@ void build_tree(std::vector<std::shared_ptr<Result>>& sorted_events) {
|
||||
// events are already marked finished before the main tree building
|
||||
// algorithm. It's fine to ignore them; the root event of these subtrees
|
||||
// not a Kineto op and will be handled normally.
|
||||
if (c10::holds_alternative<ExtraFields<EventType::Kineto>>(
|
||||
if (std::holds_alternative<ExtraFields<EventType::Kineto>>(
|
||||
event->extra_fields_) &&
|
||||
event->finished_) {
|
||||
return;
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include <c10/macros/Macros.h>
|
||||
#include <c10/util/flat_hash_map.h>
|
||||
#include <c10/util/strong_type.h>
|
||||
#include <c10/util/variant.h>
|
||||
#include <torch/csrc/profiler/containers.h>
|
||||
#include <torch/csrc/profiler/data_flow.h>
|
||||
#include <torch/csrc/profiler/events.h>
|
||||
@ -346,12 +345,12 @@ struct TORCH_API Result : public std::enable_shared_from_this<Result> {
|
||||
|
||||
template <typename T>
|
||||
decltype(auto) visit(T&& visitor) {
|
||||
return c10::visit(std::forward<T>(visitor), extra_fields_);
|
||||
return std::visit(std::forward<T>(visitor), extra_fields_);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
decltype(auto) visit(T&& visitor) const {
|
||||
return c10::visit(std::forward<T>(visitor), extra_fields_);
|
||||
return std::visit(std::forward<T>(visitor), extra_fields_);
|
||||
}
|
||||
|
||||
template <typename T, typename Fn>
|
||||
@ -380,7 +379,7 @@ struct TORCH_API Result : public std::enable_shared_from_this<Result> {
|
||||
int64_t start_time_ns_;
|
||||
uint64_t start_tid_;
|
||||
kineto::DeviceAndResource kineto_info_;
|
||||
c10::variant<
|
||||
std::variant<
|
||||
ExtraFields<EventType::TorchOp>,
|
||||
ExtraFields<EventType::Backend>,
|
||||
ExtraFields<EventType::Vulkan>,
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <torch/csrc/profiler/data_flow.h>
|
||||
|
||||
#include <c10/util/overloaded.h>
|
||||
#include <c10/util/variant.h>
|
||||
#include <torch/csrc/profiler/collection.h>
|
||||
|
||||
namespace torch {
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <c10/core/TensorImpl.h>
|
||||
#include <c10/macros/Macros.h>
|
||||
#include <c10/util/strong_type.h>
|
||||
#include <c10/util/variant.h>
|
||||
|
||||
namespace torch {
|
||||
namespace profiler {
|
||||
|
Reference in New Issue
Block a user