-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from cthsieh/vanilla
Add vanilla backend
- Loading branch information
Showing
14 changed files
with
534 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//===- CodeEmitPass.h ----------------------------------------------------===// | ||
// | ||
// The ONNC Project | ||
// | ||
// See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef ONNC_IR_CODE_EMIT_H | ||
#define ONNC_IR_CODE_EMIT_H | ||
#include <onnc/Core/ModulePass.h> | ||
#include <onnc/Support/IOStream.h> | ||
|
||
namespace onnc { | ||
|
||
class CodeEmit : public ModulePass | ||
{ | ||
public: | ||
static char ID; | ||
|
||
public: | ||
CodeEmit(ComputeVisitor& pCodeEmitVisitor) | ||
: ModulePass(CodeEmit::ID), m_CodeEmitVisitor(pCodeEmitVisitor) {} | ||
|
||
StringRef getPassName() const override { return "CodeEmit"; } | ||
|
||
Pass::ReturnType runOnModule(Module& pModule) override; | ||
|
||
private: | ||
Pass::ReturnType runOnComputeGraph(ComputeGraph& pCG); | ||
|
||
ComputeVisitor& m_CodeEmitVisitor; | ||
}; | ||
|
||
CodeEmit* CreateCodeEmitPass(ComputeVisitor& pCodeEmitVisitor); | ||
|
||
} // 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
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,53 @@ | ||
//===- CodeEmit.cpp -------------------------------------------------------===// | ||
// | ||
// The ONNC Project | ||
// | ||
// See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#include <onnc/IR/CodeEmit.h> | ||
#include <onnc/Core/PassSupport.h> | ||
#include <onnc/Support/IOStream.h> | ||
|
||
using namespace onnc; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// CodeEmit | ||
//===----------------------------------------------------------------------===// | ||
Pass::ReturnType CodeEmit::runOnModule(Module& pModule) | ||
{ | ||
unsigned result = Pass::kModuleNoChanged; | ||
Module::cg_iterator cg, cgEnd = pModule.cgEnd(); | ||
for (cg = pModule.cgBegin(); cg != cgEnd; ++cg) | ||
result |= runOnComputeGraph(*cg->value()); | ||
return result; | ||
} | ||
|
||
Pass::ReturnType CodeEmit::runOnComputeGraph(ComputeGraph& pCG) | ||
{ | ||
ComputeGraph::iterator nodeIt, nEnd = pCG.end(); | ||
for (nodeIt = pCG.begin(); nodeIt != nEnd; ++nodeIt) { | ||
const onnc::ComputeOperator *node = nodeIt; | ||
///beforeEmit(node); | ||
node->accept(m_CodeEmitVisitor); | ||
} | ||
return Pass::kModuleNoChanged; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// CodeEmit factory method | ||
//===----------------------------------------------------------------------===// | ||
char CodeEmit::ID = 0; | ||
|
||
#if 0 | ||
//FIXME a pass class with input parameter cannot be initialized? | ||
namespace onnc | ||
{ | ||
INITIALIZE_PASS(CodeEmit, "CodeEmit") | ||
} | ||
#endif | ||
|
||
CodeEmit* onnc::CreateCodeEmitPass(ComputeVisitor& pCodeEmitVisitor) | ||
{ | ||
return new CodeEmit(pCodeEmitVisitor); | ||
} |
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,64 @@ | ||
//===- CodeEmitVisitor.cpp ------------------------------------------------===// | ||
// | ||
// The ONNC Project | ||
// | ||
// See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#include <onnc/Support/IOStream.h> | ||
#include "CodeEmitVisitor.h" | ||
#include <onnc/IR/Compute/Conv.h> | ||
#include <onnc/IR/Compute/Initializer.h> | ||
#include <onnc/IR/Compute/InputOperator.h> | ||
#include <onnc/IR/Compute/OutputOperator.h> | ||
|
||
using namespace onnc; | ||
using namespace onnc::vanilla; | ||
|
||
void CodeEmitVisitor::visit(Initializer& pInitializer) | ||
{ | ||
pInitializer.print(errs()); | ||
errs() << "\n"; | ||
} | ||
|
||
void CodeEmitVisitor::visit(const Initializer& pInitializer) | ||
{ | ||
pInitializer.print(errs()); | ||
errs() << "\n"; | ||
} | ||
|
||
void CodeEmitVisitor::visit(InputOperator& pInputOperator) | ||
{ | ||
pInputOperator.print(errs()); | ||
errs() << "\n"; | ||
} | ||
|
||
void CodeEmitVisitor::visit(const InputOperator& pInputOperator) | ||
{ | ||
pInputOperator.print(errs()); | ||
errs() << "\n"; | ||
} | ||
|
||
void CodeEmitVisitor::visit(OutputOperator& pOutputOperator) | ||
{ | ||
pOutputOperator.print(errs()); | ||
errs() << "\n"; | ||
} | ||
|
||
void CodeEmitVisitor::visit(const OutputOperator& pOutputOperator) | ||
{ | ||
pOutputOperator.print(errs()); | ||
errs() << "\n"; | ||
} | ||
|
||
void CodeEmitVisitor::visit(Conv& pConv) | ||
{ | ||
pConv.print(errs()); | ||
errs() << "\n"; | ||
} | ||
|
||
void CodeEmitVisitor::visit(const Conv& pConv) | ||
{ | ||
pConv.print(errs()); | ||
errs() << "\n"; | ||
} |
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,46 @@ | ||
//===- CodeEmitVisitor.h --------------------------------------------------===// | ||
// | ||
// The ONNC Project | ||
// | ||
// See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef TARGET_VANILLA_CODE_EMIT_VISITOR_H | ||
#define TARGET_VANILLA_CODE_EMIT_VISITOR_H | ||
#include <onnc/IR/ComputeVisitor.h> | ||
|
||
namespace onnc { | ||
|
||
namespace vanilla { | ||
|
||
class CodeEmitVisitor : public ComputeVisitor | ||
{ | ||
public: | ||
static char ID; | ||
|
||
/// ONNC defined operators @{ | ||
void visit(const Initializer& pInitializer) override; | ||
void visit(const InputOperator& pInputOperator) override; | ||
void visit(const OutputOperator& pOutputOperator) override; | ||
/// @} | ||
|
||
/// ONNX defined operators @{ | ||
void visit(const Conv& pConv) override; | ||
/// @} | ||
|
||
/// ONNC defined operators @{ | ||
void visit(Initializer& pInitializer) override; | ||
void visit(InputOperator& pInputOperator) override; | ||
void visit(OutputOperator& pOutputOperator) override; | ||
/// @} | ||
|
||
/// ONNX defined operators @{ | ||
void visit(Conv& pConv) override; | ||
/// @} | ||
|
||
}; | ||
|
||
} // namespace vanilla | ||
} // namespace 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ONNC_TARGET_SOURCES += \ | ||
Target/Vanilla/VanillaBackend.cpp \ | ||
Target/Vanilla/CodeEmitVisitor.cpp \ | ||
Target/Vanilla/TargetInfo/VanillaTargetInfo.cpp \ | ||
Target/Vanilla/TargetInfo/VanillaTargetMemInfo.cpp | ||
|
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,40 @@ | ||
//===- VanillaTargetInfo.cpp --------------------------------------------------===// | ||
// | ||
// The ONNC Project | ||
// | ||
// See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#include "VanillaTargetInfo.h" | ||
#include <onnc/IR/Quadruple.h> | ||
#include <onnc/Target/TargetRegistry.h> | ||
|
||
using namespace onnc; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Non-member functions | ||
//===----------------------------------------------------------------------===// | ||
|
||
|
||
static unsigned int VanillaMatchFn(const Quadruple& pQuadruple) | ||
{ | ||
unsigned int score = 0; | ||
if (Quadruple::vanilla == pQuadruple.getArch()) { | ||
score += 10; | ||
} | ||
|
||
return score; | ||
} | ||
|
||
|
||
Target& onnc::getTheVanillaTarget() | ||
{ | ||
static Target vanilla_target; | ||
return vanilla_target; | ||
} | ||
|
||
|
||
extern "C" void InitializeVanillaONNCPlatform() { | ||
onnc::TargetRegistry::RegisterTarget(onnc::getTheVanillaTarget(), "vanilla", | ||
"Vanilla DLA", VanillaMatchFn); | ||
} |
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,18 @@ | ||
//===- VanillaTargetInfo.h ----------------------------------------------------===// | ||
// | ||
// The ONNC Project | ||
// | ||
// See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef ONNC_TARGET_VANILLA_TARGET_INFO_H | ||
#define ONNC_TARGET_VANILLA_TARGET_INFO_H | ||
#include <onnc/Target/Target.h> | ||
|
||
namespace onnc { | ||
|
||
Target& getTheVanillaTarget(); | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//===- VanillaTargetMemInfo.cpp ------------------------------------------===// | ||
// | ||
// The ONNC Project | ||
// | ||
// See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#include "VanillaTargetMemInfo.h" | ||
#include <onnc/IR/Compute/Tensor.h> | ||
|
||
using namespace onnc; | ||
|
||
MemSize VanillaTargetMemInfo::getTensorMemorySize(const Tensor& pVal) | ||
{ | ||
uint64_t align, size; | ||
switch (pVal.kind()) { | ||
case kUint8: | ||
case kInt8: | ||
case kBoolean: | ||
align = 16, size = 1; | ||
break; | ||
|
||
case kUint16: | ||
case kInt16: | ||
case kFloat16: | ||
align = 16, size = 2; | ||
break; | ||
|
||
case kFloat: | ||
case kInt32: | ||
case kUint32: | ||
align = 16, size = 4; | ||
break; | ||
|
||
case kInt64: | ||
case kUint64: | ||
align = 16, size = 8; | ||
break; | ||
|
||
default: | ||
assert(false && "Un-support value type."); | ||
return MemSize(); | ||
} | ||
|
||
for (auto i : pVal.getDimensions()) | ||
size *= i; | ||
|
||
return MemSize(align, size); | ||
} |
Oops, something went wrong.