-
Notifications
You must be signed in to change notification settings - Fork 93
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
062d455
[onni] Refactor Interpreter.
a127a127 28b3ae3
[onni] Refactor & add dry-run flag.
a127a127 a169304
[onni] Print weight memory. Add verbose level 3.
a127a127 1bc71c8
[onni] Add CountOperatorsPass.
a127a127 44ee519
[onni] Add OnnxOptPass.
a127a127 6850f4a
[onni] Add memory statistic, verbose level 4.
a127a127 0895d55
[X86] No need to allocate input memory.
a127a127 7a078dd
[onni] Do not show I/O/W operator.
a127a127 1d56ccd
[onni] Code cleanup.
a127a127 e57426c
Fix autotools build.
a127a127 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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()?
There was a problem hiding this comment.
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!