Commit 8c081092 authored by Robert Kimball's avatar Robert Kimball Committed by Scott Cyphers

Add windows support for event trace (#2695)

* add windows support for event trace

* add needed windows.h header

* fix linking error

* Enable multi-threaded builds for windows
parent 56d3a46a
......@@ -145,7 +145,7 @@ option(NGRAPH_DISTRIBUTED_ENABLE "Enable distributed training using MLSL/OpenMPI
if (NGRAPH_CPU_ENABLE
AND
((NOT NGRAPH_GPU_ENABLE) AND (NOT NGRAPH_GPUH_ENABLE)
((NOT NGRAPH_GPU_ENABLE) AND (NOT NGRAPH_GPUH_ENABLE)
AND (NOT NGRAPH_GENERIC_CPU_ENABLE) AND (NOT NGRAPH_INTELGPU_ENABLE))
)
set(NGRAPH_INTEL_CPU_ONLY_ENABLE ON)
......@@ -267,7 +267,7 @@ endif()
if (WIN32)
set (CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "/W0 /EHsc")
set(CMAKE_CXX_FLAGS "/W0 /EHsc /MP")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g")
......
......@@ -23,31 +23,36 @@
using namespace std;
static bool read_tracing_env_var()
{
return (std::getenv("NGRAPH_ENABLE_TRACING") != nullptr);
}
mutex ngraph::Event::s_file_mutex;
ofstream ngraph::Event::s_event_log;
bool ngraph::Event::s_tracing_enabled = false;
bool ngraph::Event::s_tracing_enabled = read_tracing_env_var();
void ngraph::Event::write_trace(const ngraph::Event& event)
{
lock_guard<mutex> lock(s_file_mutex);
if (!is_tracing_enabled())
if (is_tracing_enabled())
{
return;
}
lock_guard<mutex> lock(s_file_mutex);
static bool so_initialized = false;
if (!so_initialized)
{
// Open the file
s_event_log.open("ngraph_event_trace.json", ios_base::trunc);
s_event_log << "[\n";
s_event_log << event.to_json() << "\n";
so_initialized = true;
return;
}
static bool so_initialized = false;
if (!so_initialized)
{
// Open the file
s_event_log.open("ngraph_event_trace.json", ios_base::trunc);
s_event_log << "[\n";
so_initialized = true;
}
else
{
s_event_log << ",\n";
}
s_event_log << ",\n";
s_event_log << event.to_json() << "\n" << flush;
s_event_log << event.to_json() << "\n" << flush;
}
}
string ngraph::Event::to_json() const
......@@ -73,3 +78,13 @@ string ngraph::Event::to_json() const
output << json_start << ",\n" << json_end;
return output.str();
}
void ngraph::Event::enable_event_tracing()
{
s_tracing_enabled = true;
}
void ngraph::Event::disable_event_tracing()
{
s_tracing_enabled = false;
}
......@@ -22,7 +22,14 @@
#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
namespace ngraph
{
......@@ -84,21 +91,9 @@ namespace ngraph
}
static void write_trace(const Event& event);
static bool is_tracing_enabled()
{
static bool s_check_env = true;
if (s_check_env)
{
s_check_env = false;
if (std::getenv("NGRAPH_ENABLE_TRACING") != nullptr)
{
s_tracing_enabled = true;
}
}
return s_tracing_enabled;
}
static void enable_event_tracing() { s_tracing_enabled = true; }
static void disable_event_tracing() { s_tracing_enabled = false; }
static bool is_tracing_enabled() { return s_tracing_enabled; }
static void enable_event_tracing();
static void disable_event_tracing();
std::string to_json() const;
Event(const Event&) = delete;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment