Fix nGraph doxygen for master (#3899)

* Changed style of some headers

* Fixed shared buffer

* Remove chrome_trace

* Fixed comment
This commit is contained in:
Ilya Churaev authored and GitHub committed 2021-01-19 13:39:32 +03:00
1 parent 9cc58fc66a
commit 94b98c484c
6 files changed
+57 -454

No files matched your search

-143
View File
@@ -1,143 +0,0 @@
//*****************************************************************************
// Copyright 2017-2021 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#pragma once
#include <chrono>
#include <fstream>
#include <iostream>
#include <mutex>
#include <string>
#include <thread>
#ifdef _WIN32
#include <windows.h>
// windows.h must be before processthreadsapi.h so we need this comment
#include <processthreadsapi.h>
#define getpid() GetCurrentProcessId()
#else
#include <unistd.h>
#endif
#include <ngraph/ngraph_visibility.hpp>
namespace ngraph
{
namespace event
{
class Duration;
class Object;
class Manager;
}
}
//
// This class records timestamps for a given user defined event and
// produces output in the chrome tracing format that can be used to view
// the events of a running program
//
// Following is the format of a trace event
//
// {
// "name": "myName",
// "cat": "category,list",
// "ph": "B",
// "ts": 12345,
// "pid": 123,
// "tid": 456,
// "args": {
// "someArg": 1,
// "anotherArg": {
// "value": "my value"
// }
// }
// }
//
// The trace file format is defined here:
// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
//
// The trace file can be viewed by Chrome browser using the
// URL: chrome://tracing/
//
// More information about this is at:
// http://dev.chromium.org/developers/how-tos/trace-event-profiling-tool
class ngraph::event::Manager
{
friend class Duration;
friend class Object;
public:
static void open(const std::string& path = "runtime_event_trace.json");
static void close();
static bool is_tracing_enabled() { return s_tracing_enabled; }
static void enable_event_tracing();
static void disable_event_tracing();
static bool is_event_tracing_enabled();
private:
static std::ofstream& get_output_stream();
static const std::string& get_process_id();
static size_t get_current_microseconds()
{
return std::chrono::high_resolution_clock::now().time_since_epoch().count() / 1000;
}
static std::string get_thread_id();
static std::mutex& get_mutex() { return s_file_mutex; }
static std::ostream s_ostream;
static std::mutex s_file_mutex;
static bool s_tracing_enabled;
};
class NGRAPH_API ngraph::event::Duration
{
public:
explicit Duration(const std::string& name,
const std::string& category,
const std::string& args = "");
~Duration() { write(); }
/// \brief stop the timer without writing the data to the log file. To write the data
/// call the `write` method
/// Calls to stop() are optional
void stop();
/// \brief write the log data to the log file for this event
/// This funtion has an implicit stop() if stop() has not been previously called
void write();
Duration(const Duration&) = delete;
Duration& operator=(Duration const&) = delete;
private:
std::string to_json() const;
size_t m_start{0};
size_t m_stop{0};
std::string m_name;
std::string m_category;
std::string m_args;
};
class ngraph::event::Object
{
public:
Object(const std::string& name, const std::string& args);
void snapshot(const std::string& args);
void destroy();
private:
void write_snapshot(std::ostream& out, const std::string& args);
const std::string m_name;
size_t m_id{0};
};
+35 -38
View File
@@ -13,43 +13,40 @@ namespace ngraph
{
namespace pass
{
class NGRAPH_API LowLatency;
/**
* @brief The transformation finds all TensorIterator layers in the network,
* processes all back edges that describe a connection between Result and Parameter
* of the TensorIterator body,and inserts ReadValue layer between Parameter
* and the next layers after this Parameter, and Assign layer after the layers
* before the Result layer. Supported platforms: CPU, GNA.
*
* The example below describes the changes to the inner part (body, back edges) of the
* Tensor Iterator layer.
* [] - TensorIterator body
* () - new layer
*
* before applying the transformation:
* back_edge_1 -> [Parameter -> some layers ... -> Result ] -> back_edge_1
*
* after applying the transformation:
* back_edge_1 -> [Parameter -> (ReadValue layer) -> some layers ... -> (Assign layer) ]
* \
* -> Result ] -> back_edge_1
*
* It is recommended to use this transformation in conjunction with the Reshape feature to
* set sequence dimension to 1 and with the UnrollTensorIterator transformation.
* For convenience, we have already enabled the unconditional execution of the
* UnrollTensorIterator transformation when using the LowLatency transformation for
* CPU, GNA plugins, no action is required here.
* After applying both of these transformations, the resulting network can be inferred step
* by step, the states will store between inferences.
*/
class NGRAPH_API LowLatency : public ngraph::pass::MatcherPass
{
public:
NGRAPH_RTTI_DECLARATION;
LowLatency();
};
} // namespace pass
} // namespace ngraph
/**
* @brief The transformation finds all TensorIterator layers in the network, processes all back
* edges that describe a connection between Result and Parameter of the TensorIterator body,
* and inserts ReadValue layer between Parameter and the next layers after this Parameter,
* and Assign layer after the layers before the Result layer.
* Supported platforms: CPU, GNA.
*
* The example below describes the changes to the inner part (body, back edges) of the Tensor
* Iterator layer.
* [] - TensorIterator body
* () - new layer
*
* before applying the transformation:
* back_edge_1 -> [Parameter -> some layers ... -> Result ] -> back_edge_1
*
* after applying the transformation:
* back_edge_1 -> [Parameter -> (ReadValue layer) -> some layers ... -> (Assign layer) ]
* \
* -> Result ] -> back_edge_1
*
* It is recommended to use this transformation in conjunction with the Reshape feature to set
* sequence dimension to 1 and with the UnrollTensorIterator transformation.
* For convenience, we have already enabled the unconditional execution of the UnrollTensorIterator
* transformation when using the LowLatency transformation for CPU, GNA plugins, no action is
* required here.
* After applying both of these transformations, the resulting network can be inferred step by
* step, the states will store between inferences.
*
*/
class ngraph::pass::LowLatency : public ngraph::pass::MatcherPass
{
public:
NGRAPH_RTTI_DECLARATION;
LowLatency();
};
@@ -24,31 +24,28 @@ namespace ngraph
{
namespace runtime
{
/// \brief SharedBuffer class to store pointer to pre-acclocated buffer.
template <typename T>
class SharedBuffer;
class SharedBuffer : public ngraph::runtime::AlignedBuffer
{
public:
SharedBuffer(char* data, size_t size, T& shared_object)
: _shared_object(shared_object)
{
m_allocated_buffer = data;
m_aligned_buffer = data;
m_byte_size = size;
}
virtual ~SharedBuffer()
{
m_aligned_buffer = nullptr;
m_allocated_buffer = nullptr;
m_byte_size = 0;
}
private:
T _shared_object;
};
}
}
/// \brief SharedBuffer class to store pointer to pre-acclocated buffer.
template <typename T>
class ngraph::runtime::SharedBuffer : public ngraph::runtime::AlignedBuffer
{
public:
SharedBuffer(char* data, size_t size, T& shared_object)
: _shared_object(shared_object)
{
m_allocated_buffer = data;
m_aligned_buffer = data;
m_byte_size = size;
}
virtual ~SharedBuffer()
{
m_aligned_buffer = nullptr;
m_allocated_buffer = nullptr;
m_byte_size = 0;
}
private:
T _shared_object;
};
-241
View File
@@ -1,241 +0,0 @@
//*****************************************************************************
// Copyright 2017-2021 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include "ngraph/chrome_trace.hpp"
#include "ngraph/env_util.hpp"
#include "ngraph/log.hpp"
using namespace std;
using namespace ngraph;
static bool read_tracing_env_var()
{
static const bool is_enabled = getenv_bool("NGRAPH_ENABLE_TRACING");
return is_enabled;
}
mutex event::Manager::s_file_mutex;
bool event::Manager::s_tracing_enabled = read_tracing_env_var();
event::Duration::Duration(const string& name, const string& category, const string& args)
{
if (Manager::is_tracing_enabled())
{
m_start = Manager::get_current_microseconds();
m_stop = 0;
m_name = name;
m_category = category;
m_args = args;
}
}
void event::Duration::stop()
{
if (Manager::is_tracing_enabled())
{
m_stop = Manager::get_current_microseconds();
}
}
void event::Duration::write()
{
if (Manager::is_tracing_enabled())
{
size_t stop_time = (m_stop != 0 ? m_stop : Manager::get_current_microseconds());
lock_guard<mutex> lock(Manager::get_mutex());
ofstream& out = event::Manager::get_output_stream();
string str;
if (out.is_open() == false)
{
event::Manager::open();
}
else
{
str += ",\n";
}
str +=
R"({"name":")" + m_name + R"(","cat":")" + m_category + R"(","ph":"X","pid":)" +
Manager::get_process_id() + R"(,"tid":)" + Manager::get_thread_id() +
R"(,"ts":)" + to_string(m_start) + R"(,"dur":)" + to_string(stop_time - m_start);
if (!m_args.empty())
{
str += R"(,"args":)" + m_args;
}
str += "}";
out << str;
}
}
event::Object::Object(const string& name, const string& args)
: m_name{name}
, m_id{static_cast<size_t>(chrono::high_resolution_clock::now().time_since_epoch().count())}
{
if (Manager::is_tracing_enabled())
{
lock_guard<mutex> lock(Manager::get_mutex());
ofstream& out = event::Manager::get_output_stream();
string str;
if (out.is_open() == false)
{
event::Manager::open();
}
else
{
str += ",\n";
}
str += R"({"name":")" + m_name + R"(","ph":"N","id":")" + to_string(m_id) +
R"(","ts":)" + to_string(Manager::get_current_microseconds()) +
R"(,"pid":)" + Manager::get_process_id() + R"(,"tid":)" + Manager::get_thread_id();
if (!args.empty())
{
str += R"(,"args":)" + args;
}
str += "}";
write_snapshot(out, args);
}
}
void event::Object::snapshot(const string& args)
{
if (Manager::is_tracing_enabled())
{
lock_guard<mutex> lock(Manager::get_mutex());
ofstream& out = event::Manager::get_output_stream();
if (out.is_open() == false)
{
event::Manager::open();
}
else
{
Manager::get_output_stream() << ",\n";
}
write_snapshot(out, args);
}
}
void event::Object::write_snapshot(ostream& out, const string& args)
{
string str = R"({"name":")" + m_name + R"(","ph":"O","id":")" + to_string(m_id) +
R"(","ts":)" + to_string(Manager::get_current_microseconds()) +
R"(,"pid":)" + Manager::get_process_id() + R"(,"tid":)" + Manager::get_thread_id();
if (!args.empty())
{
str += R"(,"args":)" + args;
}
str += "}";
out << str;
}
void event::Object::destroy()
{
if (Manager::is_tracing_enabled())
{
lock_guard<mutex> lock(Manager::get_mutex());
ofstream& out = event::Manager::get_output_stream();
if (out.is_open() == false)
{
event::Manager::open();
}
else
{
Manager::get_output_stream() << ",\n";
}
string str = R"({"name":")" + m_name + R"(","ph":"D","id":")" + to_string(m_id) +
R"(","ts":)" + to_string(Manager::get_current_microseconds()) +
R"(,"pid":)" + Manager::get_process_id() + R"(,"tid":)" +
Manager::get_thread_id() + "}";
}
}
void event::Manager::open(const string& path)
{
ofstream& out = get_output_stream();
if (out.is_open() == false)
{
out.open(path, ios_base::trunc);
out << "[\n";
}
}
void event::Manager::close()
{
ofstream& out = get_output_stream();
if (out.is_open())
{
out << "\n]\n";
out.close();
}
}
ofstream& event::Manager::get_output_stream()
{
static ofstream s_event_log;
return s_event_log;
}
const string& event::Manager::get_process_id()
{
static const string s_pid = to_string(getpid());
return s_pid;
}
void event::Manager::enable_event_tracing()
{
s_tracing_enabled = true;
}
void event::Manager::disable_event_tracing()
{
s_tracing_enabled = false;
}
bool event::Manager::is_event_tracing_enabled()
{
return s_tracing_enabled;
}
string event::Manager::get_thread_id()
{
thread::id tid = this_thread::get_id();
static map<thread::id, string> tid_map;
auto it = tid_map.find(tid);
string rc;
if (it == tid_map.end())
{
stringstream ss;
ss << "\"" << tid << "\"";
rc = ss.str();
tid_map.insert({tid, rc});
}
else
{
rc = it->second;
}
return rc;
}
-3
View File
@@ -17,7 +17,6 @@
#include <cstring>
#include <memory>
#include "ngraph/chrome_trace.hpp"
#include "ngraph/op/constant.hpp"
#include "ngraph/runtime/host_tensor.hpp"
#include "ngraph/util.hpp"
@@ -140,7 +139,6 @@ const void* runtime::HostTensor::get_data_ptr() const
void runtime::HostTensor::write(const void* source, size_t n)
{
event::Duration d1("write", "HostTensor");
void* target = get_data_ptr();
if (n != m_buffer_size)
{
@@ -158,7 +156,6 @@ void runtime::HostTensor::write(const void* source, size_t n)
void runtime::HostTensor::read(void* target, size_t n) const
{
event::Duration d1("read", "HostTensor");
const void* source = get_data_ptr();
if (n != m_buffer_size)
{
@@ -18,7 +18,6 @@
#include <cstring>
#include "backend_manager.hpp"
#include "evaluates_map.hpp"
#include "ngraph/chrome_trace.hpp"
#include "ngraph/except.hpp"
#include "ngraph/ops.hpp"
#include "ngraph/type/bfloat16.hpp"
@@ -116,8 +115,6 @@ runtime::interpreter::INTExecutable::INTExecutable(const shared_ptr<Function>& f
bool runtime::interpreter::INTExecutable::call(const vector<shared_ptr<runtime::Tensor>>& outputs,
const vector<shared_ptr<runtime::Tensor>>& inputs)
{
event::Duration d1("call", "Interpreter");
// convert inputs to HostTensor
vector<shared_ptr<HostTensor>> func_inputs;
for (const auto& tensor : inputs)
@@ -165,7 +162,6 @@ bool runtime::interpreter::INTExecutable::call(const vector<shared_ptr<runtime::
// for each ordered op in the graph
for (const auto& op : m_nodes)
{
event::Duration d2(op->description(), "Interpreter");
if (dynamic_pointer_cast<op::Parameter>(op) != nullptr)
{
continue;