Skip to content

Commit

Permalink
Introduce explaining type.
Browse files Browse the repository at this point in the history
ONNX may use -DONNX_NAMESPACE to change the default namespace. To
support this, we collect all ONNX types in <onnc/Config/ONNX.h>.
  • Loading branch information
lubatang committed Aug 6, 2018
1 parent eaaa5d3 commit 048dd79
Show file tree
Hide file tree
Showing 438 changed files with 3,380 additions and 3,298 deletions.
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Autoconf/Automake Initialization

dnl AC_INIT(PKG_NAME, BUILD_VERSION, BUG_REPORTER)
AC_INIT([ONNC],[dev],[bugs@onnc.org])
AC_INIT([ONNC],[dev],[bugs@onnc.ai])
AC_PREREQ(2.59)

AC_CONFIG_SRCDIR([LICENSE.TXT])
Expand Down Expand Up @@ -93,6 +93,7 @@ AC_CONFIG_FILES([include/Makefile])
AC_CONFIG_FILES([include/onnc/Makefile])
AC_CONFIG_FILES([include/onnc/Config/Platforms.def])
AC_CONFIG_FILES([include/onnc/Config/Backends.def])
AC_CONFIG_FILES([include/onnc/Config/ONNX.h])
AC_CONFIG_FILES([lib/Makefile])
AC_CONFIG_FILES([tools/Makefile])
AC_CONFIG_FILES([tools/unittests/Makefile])
Expand Down
12 changes: 6 additions & 6 deletions include/onnc/Analysis/LivenessAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define ONNC_LIVENESS_ANALYSIS_H
#include <onnc/Core/ModulePass.h>
#include <onnc/Core/PassSupport.h>
#include <onnx/common/ir.h>
#include <onnc/Config/ONNX.h>
#include <string>
#include <iosfwd>
#include <vector>
Expand All @@ -24,13 +24,13 @@ class LiveInterval
typedef unsigned SlotIndex;

public:
LiveInterval(SlotIndex pStart, SlotIndex pEnd, const ::onnx::Value& pValue);
LiveInterval(SlotIndex pStart, SlotIndex pEnd, const xValue& pValue);

SlotIndex getStart() const { return m_Start; }

SlotIndex getEnd() const { return m_End; }

const ::onnx::Value& getValue() const { return m_Value; }
const xValue& getValue() const { return m_Value; }

/// return true if two live intervals have intersection
bool intersect(const LiveInterval& pLive) const;
Expand All @@ -39,7 +39,7 @@ class LiveInterval
// Live interval = [start, end]
SlotIndex m_Start;
SlotIndex m_End;
const ::onnx::Value& m_Value;
const xValue& m_Value;
};

/** \class GraphLivenessAnalysis
Expand All @@ -56,14 +56,14 @@ class GraphLivenessAnalysis : public ModulePass

ReturnType runOnModule(Module& pModule) override;

ReturnType runOnGraph(onnx::Graph &pGraph);
ReturnType runOnGraph(xGraph &pGraph);

const LiveIntervalList& getLiveIntervals() const { return m_LiveIntervals; }

void print(std::ostream& pOS) const;

private:
void calculateLiveness(::onnx::Graph &pGraph);
void calculateLiveness(xGraph &pGraph);

/// delete LiveIntervals in m_LiveIntervals
void clear();
Expand Down
12 changes: 6 additions & 6 deletions include/onnc/Analysis/MemoryAllocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <onnc/Core/ModulePass.h>
#include <onnc/Core/PassSupport.h>
#include <onnc/Target/TargetMemInfo.h>
#include <onnx/common/ir.h>
#include <onnc/Config/ONNX.h>
#include <vector>

namespace onnc {
Expand All @@ -30,15 +30,15 @@ struct MemAllocEntry
};

typedef std::vector<MemAllocEntry*> MemAllocList;
typedef std::unordered_map<const ::onnx::Value *, MemSize> ValMemSizeMap;
typedef std::unordered_map<const xValue *, MemSize> ValMemSizeMap;

/** \class MemoryAllocation
* Perform memory allocation and generate allocation map.
*/
class MemoryAllocation : public ModulePass
{
public:
typedef std::unordered_map<::onnx::Graph *, MemAllocList> GraphMemAllocList;
typedef std::unordered_map<xGraph *, MemAllocList> GraphMemAllocList;

static char ID;

Expand All @@ -51,18 +51,18 @@ class MemoryAllocation : public ModulePass

void getAnalysisUsage(AnalysisUsage& pUsage) const override;

void printGraphAlloc(OStream &pOS, const ::onnx::Graph *pGraph) const;
void printGraphAlloc(OStream &pOS, const xGraph *pGraph) const;

void print(OStream& pOS) const;

private:
/// Return total size of this allocation.
uint64_t allocByLiveness(::onnx::Graph &pGraph,
uint64_t allocByLiveness(xGraph &pGraph,
ValMemSizeMap &pValMemSizeMap,
GraphLivenessAnalysis &pLiveAnaly);

/// delete MemAllocEntries of graph.
void clearGraphAlloc(::onnx::Graph *pGraph);
void clearGraphAlloc(xGraph *pGraph);

void clear();

Expand Down
14 changes: 7 additions & 7 deletions include/onnc/Analysis/NodeIRScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace onnc {

typedef std::vector<::onnx::Node *> Nodes;
typedef std::vector<xNode *> Nodes;

/** \class NodeIRScheduler
* \brief onnx Graph IR scheduler. Reorder IR, especially load/store for
Expand All @@ -33,19 +33,19 @@ class NodeIRScheduler : public ModulePass
public:
struct ExeResUser
{
::onnx::Node *user;
xNode *user;
uint64_t remainCycles; /// Remaining cycles to finish executing the user.

ExeResUser(::onnx::Node *user, uint64_t rcycles)
ExeResUser(xNode *user, uint64_t rcycles)
: user(user), remainCycles(rcycles) {}
};

struct ExeCycle
{
::onnx::Node *node;
xNode *node;
uint64_t begin, end; /// Execution time: [begin, end)

ExeCycle(::onnx::Node *pNode, uint64_t pBegin, uint64_t pEnd)
ExeCycle(xNode *pNode, uint64_t pBegin, uint64_t pEnd)
: node(pNode), begin(pBegin), end(pEnd) {}
};

Expand All @@ -62,7 +62,7 @@ class NodeIRScheduler : public ModulePass

ReturnType runOnModule(Module& pModule) override;

ReturnType runOnGraph(::onnx::Graph &pGraph);
ReturnType runOnGraph(xGraph &pGraph);

void getAnalysisUsage(AnalysisUsage& pUsage) const override;

Expand All @@ -77,7 +77,7 @@ class NodeIRScheduler : public ModulePass

bool isAllExeResEmpty() const;

void addExeResUser(const ExeResource *pExeRes, ::onnx::Node *pUser);
void addExeResUser(const ExeResource *pExeRes, xNode *pUser);

Nodes issue();

Expand Down
34 changes: 17 additions & 17 deletions include/onnc/Analysis/SplitNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace onnc {

typedef std::unordered_map<const onnx::Value *, MemSize> ValMemSizeMap;
typedef std::unordered_map<const xValue *, MemSize> ValMemSizeMap;

/** \class SplitNode
* Represent a node, encapsulate the knowledge of inferring new input sizes
Expand All @@ -22,7 +22,7 @@ typedef std::unordered_map<const onnx::Value *, MemSize> ValMemSizeMap;
class SplitNode
{
public:
SplitNode(onnx::Node& pN, bool pSizeDecideByUser = false);
SplitNode(xNode& pN, bool pSizeDecideByUser = false);

virtual ~SplitNode() {}

Expand All @@ -36,13 +36,13 @@ class SplitNode

virtual LongInts getNewOutputSize(unsigned pIdx) const;

onnx::NodeKind kind() const { return m_Node.kind(); }
xNodeKind kind() const { return m_Node.kind(); }

void resetSize() { m_NewOutSizes = m_OutSizes; }

const onnx::Node &getNode() const { return m_Node; }
const xNode &getNode() const { return m_Node; }

onnx::Node &getNode() { return m_Node; }
xNode &getNode() { return m_Node; }

/// Should SplitGraph skip this node when calculating memory usage?
/// For example:
Expand All @@ -59,16 +59,16 @@ class SplitNode

/// The input and output size is calculated by other nodes.
bool m_SizeCalByOtherNode;
onnx::Node& m_Node;
xNode& m_Node;
};

class SplitGraphManager;
class SplitGraph
{
public:
typedef std::unordered_map<onnx::Node*, SplitNode*> SplitNodeHash;
typedef std::unordered_map<xNode*, SplitNode*> SplitNodeHash;

SplitGraph(SplitGraphManager &pSgMgr, onnx::Graph &pGraph);
SplitGraph(SplitGraphManager &pSgMgr, xGraph &pGraph);

~SplitGraph();

Expand All @@ -79,13 +79,13 @@ class SplitGraph
/// Reduce size of all values in a group to meet memory size constraint.
void shrinkSize();

onnx::Graph & getGraph() { return m_Graph; }
xGraph & getGraph() { return m_Graph; }

SplitNode* getSplitNode(onnx::Node* pN);
SplitNode* getSplitNode(xNode* pN);

const SplitNode* getSplitNode(onnx::Node* pN) const;
const SplitNode* getSplitNode(xNode* pN) const;

bool hasSplitNode(onnx::Node *pN) const;
bool hasSplitNode(xNode *pN) const;

void rebuildSplitNodes();

Expand All @@ -98,21 +98,21 @@ class SplitGraph

/// @param pN Split from node pN.
/// @param pUpdateUpper Propagate new size to upper levels.
void splitNodeByFactor(onnx::Node* pN, unsigned pAxis, unsigned pFactor,
void splitNodeByFactor(xNode* pN, unsigned pAxis, unsigned pFactor,
bool pUpdateUpper = true);

bool splitNodeBySize(onnx::Node* pN, const LongInts& pNewOutSize,
bool splitNodeBySize(xNode* pN, const LongInts& pNewOutSize,
bool pUpdateUpper = true);

private:
SplitGraphManager &m_SgMgr;

onnx::Graph &m_Graph;
xGraph &m_Graph;

SplitNodeHash m_SplitNodes;

/// split parameters for each output value.
std::vector<onnx::Node *> m_Stores;
std::vector<xNode *> m_Stores;
std::vector<unsigned> m_CurSplitAxis;
std::vector<unsigned> m_CurSplitFactor;

Expand All @@ -130,7 +130,7 @@ class SplitGraphManager
public:
typedef std::vector<SplitGraph*> SplitGraphs;

SplitGraphManager(onnx::Graph& pGraph, DLATargetBackend& pDLATB);
SplitGraphManager(xGraph& pGraph, DLATargetBackend& pDLATB);
~SplitGraphManager();

SplitGraphs &getSplitGraphs() { return m_SubGraphs; }
Expand Down
8 changes: 4 additions & 4 deletions include/onnc/Analysis/UpdateGraphOutputSize.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define ONNC_UPDATE_GRAPH_OUTPUT_SIZE_H
#include <onnc/Core/ModulePass.h>
#include <onnc/Core/PassSupport.h>
#include <onnx/common/ir.h>
#include <onnc/Config/ONNX.h>

namespace onnc {

Expand All @@ -32,9 +32,9 @@ class UpdateGraphOutputSize : public ModulePass
void setBatchSize(unsigned pBatchSize) { m_BatchSize = pBatchSize; }

private:
void updateInputBatchSize(onnx::Graph *pGraph);
void updateOutputValueInfo(onnx::Graph *pGraph);
bool updateReshapeOutputInfo(onnx::Graph *pGraph);
void updateInputBatchSize(xGraph *pGraph);
void updateOutputValueInfo(xGraph *pGraph);
bool updateReshapeOutputInfo(xGraph *pGraph);

private:
unsigned m_BatchSize;
Expand Down
3 changes: 3 additions & 0 deletions include/onnc/Config/Config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@
/* Define if this is Win32ish platform */
#undef ONNC_ON_WIN32

/* default onnx namespace */
#undef ONNX_NAMESPACE

/* Name of package */
#undef PACKAGE

Expand Down
85 changes: 85 additions & 0 deletions include/onnc/Config/ONNX.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//===- onnc/Config/Namespace.h --------------------------------------------===//
//
// The ONNC Project
//
// See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef ONNC_CONFIG_NAMESPACE_DEFINITION_H
#define ONNC_CONFIG_NAMESPACE_DEFINITION_H
#include <onnc/Config/Config.h>
#include <onnx/common/ir.h>
#include <onnx/common/ir_pb_converter.h>
#include <onnx/onnx_pb.h>
#include <onnx/checker.h>
#include <onnx/shape_inference/implementation.h>
#include <onnx/defs/schema.h>

namespace onnc {

typedef ::@ONNX_NAMESPACE@::TensorProto_DataType xTensorProtoDataType;
typedef ::@ONNX_NAMESPACE@::BuiltinSymbol xBuiltinSymbol;
typedef ::@ONNX_NAMESPACE@::Symbol xSymbol;
typedef ::@ONNX_NAMESPACE@::Dimension xDimension;
typedef ::@ONNX_NAMESPACE@::AttributeKind xAttributeKind;
typedef ::@ONNX_NAMESPACE@::Tensor xTensor;
typedef ::@ONNX_NAMESPACE@::Value xValue;
typedef ::@ONNX_NAMESPACE@::NodeKind xNodeKind;
typedef ::@ONNX_NAMESPACE@::Node xNode;
typedef ::@ONNX_NAMESPACE@::Graph xGraph;
typedef ::@ONNX_NAMESPACE@::ModelProto xProto;
typedef ::@ONNX_NAMESPACE@::graph_node_list_iterator xGraphNodeListIterator;
typedef ::@ONNX_NAMESPACE@::const_graph_node_list_iterator
ConstxGraphNodeListIterator;
typedef ::@ONNX_NAMESPACE@::checker::ValidationError xValidationError;

template<typename Derived>
using xAttributes = ::@ONNX_NAMESPACE@::Attributes<Derived>;

typedef ::@ONNX_NAMESPACE@::FloatAttr xFloatAttr;
typedef ::@ONNX_NAMESPACE@::FloatsAttr xFloatsAttr;
typedef ::@ONNX_NAMESPACE@::IntAttr xIntAttr;
typedef ::@ONNX_NAMESPACE@::IntsAttr xIntsAttr;
typedef ::@ONNX_NAMESPACE@::StringAttr xStringAttr;
typedef ::@ONNX_NAMESPACE@::StringsAttr xStringsAttr;
typedef ::@ONNX_NAMESPACE@::TensorAttr xTensorAttr;
typedef ::@ONNX_NAMESPACE@::TensorsAttr xTensorsAttr;
typedef ::@ONNX_NAMESPACE@::GraphAttr xGraphAttr;
typedef ::@ONNX_NAMESPACE@::GraphsAttr xGraphsAttr;
typedef ::@ONNX_NAMESPACE@::OpSchemaRegistry xOpSchemaRegistry;

const static auto& xExportModelProto = ::@ONNX_NAMESPACE@::ExportModelProto;
const static auto& xImportModelProto = ::@ONNX_NAMESPACE@::ImportModelProto;
const static auto& xcheck_model = ::@ONNX_NAMESPACE@::checker::check_model;
const static auto& xInferShapes =
::@ONNX_NAMESPACE@::shape_inference::InferShapes;

enum xValueType {
kUndefined = ::@ONNX_NAMESPACE@::TensorProto_DataType_UNDEFINED,

// Basic types.
kFloat = ::@ONNX_NAMESPACE@::TensorProto_DataType_FLOAT, // float
kUint8 = ::@ONNX_NAMESPACE@::TensorProto_DataType_UINT8, // uint8_t
kInt8 = ::@ONNX_NAMESPACE@::TensorProto_DataType_INT8, // int8_t
kUint16 = ::@ONNX_NAMESPACE@::TensorProto_DataType_UINT16, // uint16_t
kInt16 = ::@ONNX_NAMESPACE@::TensorProto_DataType_INT16, // int16_t
kInt32 = ::@ONNX_NAMESPACE@::TensorProto_DataType_INT32, // int32_t
kInt64 = ::@ONNX_NAMESPACE@::TensorProto_DataType_INT64, // int64_t
kString = ::@ONNX_NAMESPACE@::TensorProto_DataType_STRING, // string
kBoolean = ::@ONNX_NAMESPACE@::TensorProto_DataType_BOOL, // bool

// Advanced types
kFloat16 = ::@ONNX_NAMESPACE@::TensorProto_DataType_FLOAT16,
kDouble = ::@ONNX_NAMESPACE@::TensorProto_DataType_DOUBLE,
kUint32 = ::@ONNX_NAMESPACE@::TensorProto_DataType_UINT32,
kUint64 = ::@ONNX_NAMESPACE@::TensorProto_DataType_UINT64,

// complex with float32 real and imaginary components
kComplex64 = ::@ONNX_NAMESPACE@::TensorProto_DataType_COMPLEX64,
// complex with float64 real and imaginary components
kComplex128 = ::@ONNX_NAMESPACE@::TensorProto_DataType_COMPLEX128
};

} // namespace onnc

#endif
Loading

0 comments on commit 048dd79

Please sign in to comment.