aboutsummaryrefslogtreecommitdiff
path: root/src/armnnUtils
diff options
context:
space:
mode:
authorsurmeh01 <surabhi.mehta@arm.com>2018-03-29 16:29:27 +0100
committersurmeh01 <surabhi.mehta@arm.com>2018-03-29 16:29:27 +0100
commitbceff2fb3fc68bb0aa88b886900c34b77340c826 (patch)
treed867d3e090d58d3012dfbbac456e9ea8c7f789bc /src/armnnUtils
parent4fcda0101ec3d110c1d6d7bee5c83416b645528a (diff)
downloadarmnn-bceff2fb3fc68bb0aa88b886900c34b77340c826.tar.gz
Release 18.03
Diffstat (limited to 'src/armnnUtils')
-rw-r--r--src/armnnUtils/DotSerializer.cpp219
-rw-r--r--src/armnnUtils/DotSerializer.hpp131
2 files changed, 350 insertions, 0 deletions
diff --git a/src/armnnUtils/DotSerializer.cpp b/src/armnnUtils/DotSerializer.cpp
new file mode 100644
index 0000000000..1feea54dbd
--- /dev/null
+++ b/src/armnnUtils/DotSerializer.cpp
@@ -0,0 +1,219 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#include "DotSerializer.hpp"
+
+#include <boost/assert.hpp>
+#include <sstream>
+#include <cstring>
+
+namespace armnn
+{
+
+namespace
+{
+std::string Indent(int numSpaces)
+{
+ std::stringstream ss;
+ for (int i = 0; i < numSpaces; i++)
+ {
+ ss << " ";
+ }
+ return ss.str();
+}
+} //namespace
+
+
+HtmlFont::HtmlFont(std::ostream& stream, int fontSize, const char *color, const char *face)
+ : DotBase(stream)
+{
+ GetStream() << "<FONT";
+
+ if (fontSize > -1)
+ {
+ GetStream() << " POINT-SIZE=" << "\"" << fontSize << "\"";
+ }
+
+ if (color && std::strlen(color) != 0)
+ {
+ GetStream() << " COLOR=\"" << color << "\" ";
+ }
+
+ if (face && std::strlen(face) != 0)
+ {
+ GetStream() << " FACE=\"" << face << "\" ";
+ }
+
+ GetStream() << ">";
+}
+
+
+HtmlFont::HtmlFont(std::ostream& stream)
+ : HtmlFont(stream, -1, nullptr, nullptr)
+{}
+
+HtmlFont::~HtmlFont()
+{
+ GetStream() << "</FONT>";
+}
+
+
+DotAttributeSet::DotAttributeSet(std::ostream& stream)
+ : DotBase(stream)
+{
+ GetStream() << "[";
+}
+
+DotAttributeSet::~DotAttributeSet()
+{
+ bool doSpace=false;
+ for (auto attrib : m_Attributes)
+ {
+ if (doSpace)
+ {
+ GetStream() << " ";
+ }
+
+ GetStream() << attrib;
+ doSpace=true;
+ }
+
+ GetStream() << "]";
+}
+
+DotAttributeSet & DotAttributeSet::AddAttribute(const std::string& name, const std::stringstream& value)
+{
+ std::stringstream ss;
+ ss << name <<"=" << value.str();
+ m_Attributes.push_back(ss.str());
+ return *this;
+}
+
+DotAttributeSet & DotAttributeSet::AddAttribute(const std::string& name, int value)
+{
+ std::stringstream ss;
+ ss << name <<"=" << value;
+ m_Attributes.push_back(ss.str());
+ return *this;
+}
+
+DotAttributeSet & DotAttributeSet::AddAttribute(const std::string& name, const std::string& value)
+{
+ std::stringstream ss;
+ ss << name <<"=\"" << value << "\"";
+ m_Attributes.push_back(ss.str());
+ return *this;
+}
+
+DotEdge::DotEdge(std::ostream& stream, unsigned int fromNodeId, unsigned int toNodeId)
+ : DotBase(stream)
+{
+ std::stringstream ss;
+ ss << Indent(4) << fromNodeId << " -> " << toNodeId << " ";
+ GetStream() << ss.str();
+
+ m_Attributes = std::make_unique<DotAttributeSet>(stream);
+}
+
+DotEdge::~DotEdge()
+{
+ m_Attributes.reset(nullptr);
+ GetStream() << ";" << std::endl;
+}
+
+
+NodeContent::NodeContent(std::ostream& stream)
+ : DotBase(stream)
+{
+}
+
+NodeContent & NodeContent::SetName(const std::string & name)
+{
+ m_Name = name;
+ return *this;
+}
+
+NodeContent & NodeContent::AddContent(const std::string & content)
+{
+ m_Contents.push_back(content);
+ return *this;
+}
+
+NodeContent::~NodeContent()
+{
+ std::stringstream ss;
+ ss << "label=\"{" << m_Name;
+ if (!m_Contents.empty())
+ {
+ ss << "|";
+ }
+ for (auto & content : m_Contents)
+ {
+ ss << content;
+ ss << "\\l";
+ }
+ ss << "}\"";
+ GetStream() << ss.str();
+}
+
+DotNode::DotNode(std::ostream& stream, unsigned int nodeId, const char* label)
+ : DotBase(stream)
+{
+ std::stringstream ss;
+ ss << Indent(4) << nodeId;
+
+ GetStream() << ss.str() << " ";
+
+ m_Contents = std::make_unique<NodeContent>(stream);
+ m_Attributes = std::make_unique<DotAttributeSet>(stream);
+
+ if (std::strlen(label) != 0)
+ {
+ m_Contents->SetName(label);
+ }
+ else
+ {
+ m_Contents->SetName("<noname>");
+ }
+}
+
+DotNode::~DotNode()
+{
+ m_Contents.reset(nullptr);
+ m_Attributes.reset(nullptr);
+ GetStream() << ";" << std::endl;
+}
+
+
+DotDefaults::DotDefaults(std::ostream& stream, const char* type)
+ : DotBase(stream)
+{
+ std::stringstream ss;
+ ss << Indent(4) << type;
+
+ GetStream() << ss.str() << " ";
+ m_Attributes = std::make_unique<DotAttributeSet>(stream);
+}
+
+DotDefaults::~DotDefaults()
+{
+ m_Attributes.reset(nullptr);
+ GetStream() << ";" << std::endl;
+}
+
+DotGraph::DotGraph(std::ostream& stream, const char* name)
+ : DotBase(stream)
+{
+ GetStream() << "digraph " << name << " {" << std::endl;
+}
+
+DotGraph::~DotGraph()
+{
+ GetStream() << "}" << std::endl;
+}
+
+} //namespace armnn
+
+
diff --git a/src/armnnUtils/DotSerializer.hpp b/src/armnnUtils/DotSerializer.hpp
new file mode 100644
index 0000000000..3cb591ca72
--- /dev/null
+++ b/src/armnnUtils/DotSerializer.hpp
@@ -0,0 +1,131 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#pragma once
+
+#include <ostream>
+#include <vector>
+#include <memory>
+
+namespace armnn
+{
+
+class DotBase
+{
+public:
+ explicit DotBase(std::ostream& stream)
+ : m_Stream(stream) {}
+
+ std::ostream& GetStream() { return m_Stream; }
+
+private:
+ std::ostream& m_Stream;
+};
+
+class HtmlSection : public DotBase
+{
+public:
+ explicit HtmlSection(std::ostream& stream)
+ : DotBase(stream) { GetStream() << "<";}
+ ~HtmlSection() { GetStream() << ">"; }
+};
+
+class HtmlSimpleTag : public DotBase
+{
+public:
+ explicit HtmlSimpleTag(std::ostream& stream, const char* name)
+ : DotBase(stream)
+ , m_Name(name){ GetStream() << "<" << m_Name << ">"; }
+ ~HtmlSimpleTag() { GetStream() << "</" << m_Name << ">"; }
+
+private:
+ const char* m_Name;
+};
+
+class HtmlBold : public HtmlSimpleTag
+{
+public:
+ explicit HtmlBold(std::ostream &stream)
+ : HtmlSimpleTag(stream, "B") {}
+};
+
+class HtmlFont : public DotBase
+{
+public:
+ explicit HtmlFont(std::ostream& stream, int fontSize, const char* color, const char* face);
+ explicit HtmlFont(std::ostream& stream);
+ ~HtmlFont();
+};
+
+class DotAttributeSet : public DotBase
+{
+public:
+ explicit DotAttributeSet(std::ostream& stream);
+ ~DotAttributeSet();
+
+ DotAttributeSet & AddAttribute(const std::string& name, const std::stringstream& value);
+ DotAttributeSet & AddAttribute(const std::string& name, int value);
+ DotAttributeSet & AddAttribute(const std::string& name, const std::string& value);
+private:
+ std::vector<std::string> m_Attributes;
+};
+
+class DotEdge : public DotBase
+{
+public:
+ explicit DotEdge(std::ostream& stream, unsigned int fromNodeId, unsigned int toNodeId);
+ ~DotEdge();
+
+ DotAttributeSet& GetAttributeSet() { return *m_Attributes.get(); }
+private:
+ std::unique_ptr<DotAttributeSet> m_Attributes;
+};
+
+class NodeContent : public DotBase
+{
+public:
+ explicit NodeContent(std::ostream& stream);
+ NodeContent & SetName(const std::string & name);
+ NodeContent & AddContent(const std::string & content);
+
+ ~NodeContent();
+private:
+ std::string m_Name;
+ std::vector<std::string> m_Contents;
+};
+
+class DotNode : public DotBase
+{
+public:
+ explicit DotNode(std::ostream& stream, unsigned int nodeId, const char* label);
+ ~DotNode();
+
+ NodeContent& GetContents() { return *m_Contents.get(); }
+ DotAttributeSet& GetAttributeSet() { return *m_Attributes.get(); }
+private:
+ std::unique_ptr<NodeContent> m_Contents;
+ std::unique_ptr<DotAttributeSet> m_Attributes;
+};
+
+class DotDefaults : public DotBase
+{
+public:
+ explicit DotDefaults(std::ostream& stream, const char* type);
+ ~DotDefaults();
+
+ DotAttributeSet& GetAttributeSet() { return *m_Attributes.get(); }
+private:
+ std::unique_ptr<DotAttributeSet> m_Attributes;
+};
+
+class DotGraph : public DotBase
+{
+public:
+ explicit DotGraph(std::ostream& stream, const char* name);
+ ~DotGraph();
+private:
+};
+
+} //namespace armnn