Permalink
Browse files

Let `TargetBackend` owns a `TargetMemInfo`

  • Loading branch information...
Po Yen Chen
Po Yen Chen committed Jan 21, 2019
1 parent 20a8888 commit 9fd59bc32de309fba3774ca11de2e498f9a2fd2f
@@ -8,12 +8,14 @@
#ifndef ONNC_TARGET_TARGET_BACKEND_H
#define ONNC_TARGET_TARGET_BACKEND_H
#include <onnc/Core/PassManager.h>
#include <onnc/Target/TargetMemInfo.h>
#include <onnc/Target/TargetOptions.h>
#include <onnc/Support/Path.h>

#include <memory>

namespace onnc {

class TargetMemInfo;
class TargetOptions;
class TargetTransformInfo;
class LowerRegistry;
@@ -22,7 +24,7 @@ class TargetBackend
{
public:
TargetBackend(const TargetOptions& pOptions)
: m_pMemInfo(nullptr), m_TargetOptions(pOptions) {
: m_TargetOptions(pOptions) {
}

virtual ~TargetBackend() { }
@@ -44,12 +46,12 @@ class TargetBackend

/// This is not a constant function. Because there in case memory emulator
/// must change its internal state.
TargetMemInfo* getMemInfo() { return m_pMemInfo; }
TargetMemInfo* getMemInfo() { return m_pMemInfo.get(); }

const TargetMemInfo* getMemInfo() const { return m_pMemInfo; }
const TargetMemInfo* getMemInfo() const { return m_pMemInfo.get(); }

protected:
TargetMemInfo* m_pMemInfo;
std::unique_ptr<TargetMemInfo> m_pMemInfo;

private:
const TargetOptions& m_TargetOptions;
@@ -54,6 +54,7 @@

#include <onnc/Transforms/TensorSel/Standards/UnsqueezeLower.h>

#include <memory>

using namespace onnc;

@@ -65,12 +66,7 @@ NvDlaBackend::NvDlaBackend(const TargetOptions& pOptions)
, m_pMeta{}
, m_CodeEmitVisitor{m_pMeta}
{
m_pMemInfo = new NvDlaTargetMemInfo();
}

NvDlaBackend::~NvDlaBackend()
{
delete m_pMemInfo;
m_pMemInfo = std::make_unique<NvDlaTargetMemInfo>();
}

void NvDlaBackend::addTensorSel(PassManager& pPM)
@@ -20,7 +20,7 @@ class NvDlaBackend : public TargetBackend
public:
NvDlaBackend(const TargetOptions& pOptions);

virtual ~NvDlaBackend();
virtual ~NvDlaBackend() = default;

void addTensorSel(PassManager& pPM) override;

@@ -69,7 +69,7 @@ using namespace onnc;
BM1880Backend::BM1880Backend(const TargetOptions &pOptions)
: TGBackend(pOptions)
{
m_pMemInfo = new BM188xTargetMemInfo(this);
m_pMemInfo = std::make_unique<BM188xTargetMemInfo>(this);
m_pTTI = new BM188xTargetTransformInfo(this);
}

@@ -49,6 +49,7 @@
#include <onnc/Transforms/TensorSel/Standards/TransposeLower.h>
#include <onnc/Transforms/TensorSel/Standards/UpsampleLower.h>

#include <memory>

using namespace onnc;

@@ -57,12 +58,7 @@ using namespace onnc;
//===----------------------------------------------------------------------===//
VanillaBackend::VanillaBackend(const TargetOptions& pOptions)
: TargetBackend(pOptions) {
m_pMemInfo = new VanillaTargetMemInfo();
}

VanillaBackend::~VanillaBackend()
{
delete m_pMemInfo;
m_pMemInfo = std::make_unique<VanillaTargetMemInfo>();
}

void VanillaBackend::addTensorSel(PassManager& pPM)
@@ -17,7 +17,7 @@ class VanillaBackend : public TargetBackend
public:
VanillaBackend(const TargetOptions& pOptions);

virtual ~VanillaBackend();
virtual ~VanillaBackend() = default;

void addTensorSel(PassManager& pPM) override;

@@ -130,19 +130,17 @@
#include <onnc/Transforms/TensorSel/Standards/UnsqueezeLower.h>
#include <onnc/Transforms/TensorSel/Standards/UpsampleLower.h>
#include <onnc/Transforms/TensorSel/Standards/XorLower.h>

#include <memory>

using namespace onnc;

//===----------------------------------------------------------------------===//
// X86Backend
//===----------------------------------------------------------------------===//
X86Backend::X86Backend(const TargetOptions& pOptions)
: NPUTargetBackend(pOptions) {
m_pMemInfo = new X86TargetMemInfo();
}

X86Backend::~X86Backend()
{
delete m_pMemInfo;
m_pMemInfo = std::make_unique<X86TargetMemInfo>();
}

void X86Backend::addTensorSel(PassManager& pPM)
@@ -17,7 +17,7 @@ class X86Backend : public NPUTargetBackend
public:
X86Backend(const TargetOptions& pOptions);

virtual ~X86Backend();
virtual ~X86Backend() = default;

void addTensorSel(PassManager& pPM) override;

@@ -36,6 +36,8 @@
#include <skypat/skypat.h>
#include "../../lib/Target/X86/X86RemoveWeightFromLiveIntervals.h"

#include <memory>

using namespace onnc;

//===----------------------------------------------------------------------===//
@@ -244,12 +246,10 @@ class VTargetMemInfo : public TargetMemInfo
class VTargetBackend : public TargetBackend
{
public:
VTargetBackend(const TargetOptions& pOptions)
explicit VTargetBackend(const TargetOptions& pOptions)
: TargetBackend(pOptions) {
m_pMemInfo = &m_VTMI;
m_pMemInfo = std::make_unique<VTargetMemInfo>();
}

VTargetMemInfo m_VTMI;
};

//===----------------------------------------------------------------------===//

0 comments on commit 9fd59bc

Please sign in to comment.