@@ -213,7 +213,7 @@ using IdentifiedCommand = std::pair<uint64_t, Command>; | |||||
template <> | template <> | ||||
struct ToStringTrait<interpreter::intl::Command>{ | struct ToStringTrait<interpreter::intl::Command>{ | ||||
std::string operator()(const interpreter::intl::Command& cmd) const { | std::string operator()(const interpreter::intl::Command& cmd) const { | ||||
return std::visit([](auto& cmd){ | |||||
return std::visit([](const auto& cmd){ | |||||
std::string result = cmd.get_name(); | std::string result = cmd.get_name(); | ||||
result += "{"; | result += "{"; | ||||
cmd.get_props([&](const char* key, auto&& value) { | cmd.get_props([&](const char* key, auto&& value) { | ||||
@@ -481,8 +481,8 @@ void ChannelImpl::process_one_task(IdentifiedCommand& icmd) { | |||||
finished = true; | finished = true; | ||||
}; | }; | ||||
//TODO: remove std::visit for support osx 10.12 | //TODO: remove std::visit for support osx 10.12 | ||||
auto cmd_visitor = [&](auto& cmd) { | |||||
using T = std::remove_reference_t<decltype(cmd)>; | |||||
auto cmd_visitor = [&](const auto& cmd) { | |||||
using T = std::decay_t<decltype(cmd)>; | |||||
if constexpr (std::is_same_v<T, Put>) { | if constexpr (std::is_same_v<T, Put>) { | ||||
auto value = cmd.no_cache ? std::make_shared<Tensor>(cmd.value) : Tensor::make(cmd.value); | auto value = cmd.no_cache ? std::make_shared<Tensor>(cmd.value) : Tensor::make(cmd.value); | ||||
produce_tensor(cmd.dest, std::move(value)); | produce_tensor(cmd.dest, std::move(value)); | ||||
@@ -598,10 +598,10 @@ void ChannelImpl::process_one_task(IdentifiedCommand& icmd) { | |||||
do_finish_command(); | do_finish_command(); | ||||
m_worker_state.profiler->record_host<WorkerEndScope>(cmd.scope_name); | m_worker_state.profiler->record_host<WorkerEndScope>(cmd.scope_name); | ||||
} else { | } else { | ||||
static_assert(std::is_same_v<T, T>); | |||||
static_assert(!std::is_same_v<T, T>); | |||||
} | } | ||||
}; | }; | ||||
std::visit([&](auto& cmd){ | |||||
std::visit([&](const auto& cmd){ | |||||
using T = std::decay_t<decltype(cmd)>; | using T = std::decay_t<decltype(cmd)>; | ||||
if (!m_worker_state.options.catch_worker_execption) { | if (!m_worker_state.options.catch_worker_execption) { | ||||
cmd_visitor(cmd); | cmd_visitor(cmd); | ||||
@@ -97,7 +97,7 @@ struct InterpreterProfilerDumpChromeTimelineContext { | |||||
}; | }; | ||||
// convert Command to json object. Has to be an callable object | // convert Command to json object. Has to be an callable object | ||||
static auto constexpr cmd_to_args = [](auto&& cmd) { | |||||
static auto constexpr cmd_to_args = [](const auto& cmd) { | |||||
auto args = json::Object::make(); | auto args = json::Object::make(); | ||||
cmd.get_props([&](const char* key, auto&& value){ | cmd.get_props([&](const char* key, auto&& value){ | ||||
(*args)[key] = json::String::make(to_string(value)); | (*args)[key] = json::String::make(to_string(value)); | ||||
@@ -108,14 +108,14 @@ struct InterpreterProfilerDumpChromeTimelineContext { | |||||
void process() { | void process() { | ||||
// enumerate and process each record | // enumerate and process each record | ||||
for (auto&& record: profile_data.records) { | |||||
std::visit([this](auto& record){ | |||||
for (auto& record: profile_data.records) { | |||||
std::visit([this](const auto& record){ | |||||
using TEvent = std::decay_t<decltype(record.data)>; | using TEvent = std::decay_t<decltype(record.data)>; | ||||
Session<TEvent>(*this, record).process(); | Session<TEvent>(*this, record).process(); | ||||
}, record); | }, record); | ||||
} | } | ||||
for (size_t tid = 0; tid < thread_list.size(); ++tid) { | for (size_t tid = 0; tid < thread_list.size(); ++tid) { | ||||
auto tname = std::visit([&](auto& host_or_device) -> std::string{ | |||||
auto tname = std::visit([&](auto host_or_device) -> std::string{ | |||||
using T = std::decay_t<decltype(host_or_device)>; | using T = std::decay_t<decltype(host_or_device)>; | ||||
if constexpr (std::is_same_v<T, std::thread::id>) { | if constexpr (std::is_same_v<T, std::thread::id>) { | ||||
// take name from host_map | // take name from host_map | ||||
@@ -142,11 +142,11 @@ struct InterpreterProfilerDumpChromeTimelineContext { | |||||
template <typename TEvent> | template <typename TEvent> | ||||
struct Session { | struct Session { | ||||
InterpreterProfilerDumpChromeTimelineContext& ctx; | InterpreterProfilerDumpChromeTimelineContext& ctx; | ||||
ProfilerBase::EventRecord<TEvent>& record; | |||||
TEvent& data; | |||||
const ProfilerBase::EventRecord<TEvent>& record; | |||||
const TEvent& data; | |||||
Session(InterpreterProfilerDumpChromeTimelineContext& ctx, | Session(InterpreterProfilerDumpChromeTimelineContext& ctx, | ||||
ProfilerBase::EventRecord<TEvent>& record) | |||||
const ProfilerBase::EventRecord<TEvent>& record) | |||||
: ctx{ctx}, record{record}, data{record.data} {} | : ctx{ctx}, record{record}, data{record.data} {} | ||||
uint64_t get_host_tid() { | uint64_t get_host_tid() { | ||||
@@ -57,7 +57,7 @@ public: | |||||
Host tid; | Host tid; | ||||
double time; | double time; | ||||
void wait() {} | |||||
void wait() const {} | |||||
}; | }; | ||||
struct DeviceInstant { | struct DeviceInstant { | ||||
@@ -65,7 +65,7 @@ public: | |||||
std::shared_ptr<CompNode::Event> event; | std::shared_ptr<CompNode::Event> event; | ||||
double after; | double after; | ||||
void wait() { | |||||
void wait() const { | |||||
event->host_wait(); | event->host_wait(); | ||||
} | } | ||||
}; | }; | ||||
@@ -77,16 +77,16 @@ public: | |||||
Instant instant; | Instant instant; | ||||
TEvent data; | TEvent data; | ||||
HostInstant& host() { | |||||
const HostInstant& host() const { | |||||
return std::get<HostInstant>(instant); | return std::get<HostInstant>(instant); | ||||
} | } | ||||
DeviceInstant device() { | |||||
const DeviceInstant& device() const { | |||||
return std::get<DeviceInstant>(instant); | return std::get<DeviceInstant>(instant); | ||||
} | } | ||||
void wait() { | |||||
std::visit([&](auto& instant){ instant.wait(); }, instant); | |||||
void wait() const { | |||||
std::visit([&](const auto& instant){ instant.wait(); }, instant); | |||||
} | } | ||||
}; | }; | ||||
protected: | protected: | ||||
@@ -173,7 +173,7 @@ public: | |||||
mgb_assert(m_status == Profiling, "profiler not active"); | mgb_assert(m_status == Profiling, "profiler not active"); | ||||
m_status = Stopped; | m_status = Stopped; | ||||
for (auto&& record: m_record_list) { | for (auto&& record: m_record_list) { | ||||
std::visit([&](auto& record){ | |||||
std::visit([&](const auto& record){ | |||||
record.wait(); | record.wait(); | ||||
}, record); | }, record); | ||||
} | } | ||||
@@ -312,7 +312,7 @@ public: | |||||
return m_content.back(); | return m_content.back(); | ||||
} | } | ||||
std::shared_ptr<json::Array> to_json() { | |||||
std::shared_ptr<json::Array> to_json() const { | |||||
auto result = json::Array::make(); | auto result = json::Array::make(); | ||||
for (auto&& event: m_content) { | for (auto&& event: m_content) { | ||||
result->add(event.to_json()); | result->add(event.to_json()); | ||||