Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experimental] ONNI v2 #91

Merged
merged 10 commits into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ ONNC_SOURCES = \
Option/Option.cpp \
Option/OptionPool.cpp \
Option/OptParser.cpp \
Runtime/onnc-runtime.c \
Runtime/operator/abs.c \
Runtime/operator/acos.c \
Runtime/operator/add.c \
Expand Down
3 changes: 2 additions & 1 deletion lib/Target/X86/X86RemoveWeightFromLiveIntervals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <onnc/CodeGen/LiveIntervals.h>
#include <onnc/Core/PassAnalysisSupport.h>
#include <onnc/IR/Compute/Initializer.h>
#include <onnc/IR/Compute/InputOperator.h>

using namespace onnc;

Expand All @@ -24,7 +25,7 @@ Pass::ReturnType X86RemoveWeightFromLiveIntervals::runOnModule(Module& pModule)
// TODO: check if Define is ComputeOperator before casting.
ComputeOperator* op = static_cast<ComputeOperator*>(v->getDefine());
// If the value is weight, remove it from liveness table.
if (isa<Initializer>(op))
if (isa<Initializer>(op) || isa<InputOperator>(op))
liveIntrvlPass->removeLiveInterval(v);
}

Expand Down
3 changes: 2 additions & 1 deletion tools/onni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

include_directories(${ONNC_INCLUDE_DIRS})

add_executable(onni main.cpp ONNIApp.cpp ONNIConfig.cpp Interpreter.cpp)
add_executable(onni main.cpp ONNIApp.cpp ONNIConfig.cpp Interpreter.cpp
InterpreterPass.cpp CountOperatorsPass.cpp OnnxOptPass.cpp)
target_link_libraries(onni libonnc)

install(TARGETS onni
Expand Down
76 changes: 76 additions & 0 deletions tools/onni/CountOperatorsPass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//===- CountOperatorsPass.cpp ---------------------------------------------===//
//
// The ONNC Project
//
// See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "CountOperatorsPass.h"

#include <onnc/IR/ComputeOperator.h>
#include <onnc/IR/Compute/Initializer.h>
#include <onnc/IR/Compute/InputOperator.h>
#include <onnc/IR/Compute/OutputOperator.h>
#include <onnc/IR/Module.h>
#include <onnc/Support/IOStream.h>

#include <algorithm>
#include <iomanip>
#include <unordered_map>

using namespace onnc;

//===----------------------------------------------------------------------===//
// CountOperatorsPass
//===----------------------------------------------------------------------===//
Pass::ReturnType CountOperatorsPass::runOnModule(Module &pModule)
{
std::unordered_map<std::string, int> count;
size_t op_len = 8;
uint64_t total = 0;

for (ComputeOperator &cm : *pModule.getRootComputeGraph()) {
if (dyn_cast<InputOperator>(&cm)) continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with a function? IsIOWOperator() or SkipInCountStatistics()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that's Great! Thanks a lot!

if (dyn_cast<Initializer>(&cm)) continue;
if (dyn_cast<OutputOperator>(&cm)) continue;
onnc::StringRef name = cm.name();
count[name] += 1;
op_len = std::max(op_len, name.size());
++total;
}

const std::string sep{" |"};
size_t count_len = (total > 99999) ? 10 : 5;

count_len += 1;

outs() << m_Prefix << std::setw(op_len) << "Operator" << sep
<< std::setw(count_len) << "Count" << std::endl;
outs() << m_Prefix
<< std::setfill('-')
<< std::setw(op_len) << '-' << "-+" << std::setw(count_len) << '-'
<< std::setfill(' ')
<< std::endl;
for (auto c : count) {
outs() << m_Prefix << std::setw(op_len) << c.first << sep
<< std::setw(count_len) << c.second << std::endl;
}
outs() << m_Prefix
<< std::setfill('-')
<< std::setw(op_len) << '-' << "-+" << std::setw(count_len) << '-'
<< std::setfill(' ')
<< std::endl;
outs() << m_Prefix << std::setw(op_len) << "Total" << sep
<< std::setw(count_len) << total << std::endl;

return Pass::kModuleNoChanged;
}

//===----------------------------------------------------------------------===//
// Factory method
//===----------------------------------------------------------------------===//
char CountOperatorsPass::ID = 0;

CountOperatorsPass *onnc::CreateCountOperatorsPass(const std::string &pPrefix) {
return new CountOperatorsPass(pPrefix);
}
43 changes: 43 additions & 0 deletions tools/onni/CountOperatorsPass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//===- CountOperatorsPass.h ------------------------------------------------===//
//
// The ONNC Project
//
// See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef ONNC_COUNT_OPERATORS_PASS_H
#define ONNC_COUNT_OPERATORS_PASS_H
#include <onnc/Core/ModulePass.h>

#include <string>

namespace onnc {

class TargetBackend;

// XXX: Experimental

/** \class CountOperatorsPass
* \brief Count & print Operators count statistics
*/
class CountOperatorsPass : public ModulePass
{
public:
static char ID;

public:
CountOperatorsPass(const std::string &pPrefix)
: ModulePass(ID), m_Prefix(pPrefix) {}

ReturnType runOnModule(Module& pModule) override;

private:
std::string m_Prefix;
};

// XXX: Experimental
CountOperatorsPass *CreateCountOperatorsPass(const std::string &pPrefix);

} // namespace of onnc

#endif
6 changes: 1 addition & 5 deletions tools/onni/Interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ namespace onnc {
class Interpreter : public ComputeVisitor
{
public:
Interpreter(void *pContext) : m_pContext(pContext) {};

// XXX
typedef std::unordered_map<Value *, void *> AddressTable;
AddressTable m_ATable;
void *m_pContext;

virtual void visit(Abs& pAbs);
virtual void visit(Acos& pAcos);
Expand Down Expand Up @@ -139,9 +138,6 @@ class Interpreter : public ComputeVisitor
virtual void visit(Scale& pScale);
virtual void visit(ScaledTanh& pScaledTanh);
virtual void visit(ThresholdedRelu& pThresholdedRelu);

private:
void *m_pContext;
};

} // namespace of onnc
Expand Down
Loading