Skip to content

Commit

Permalink
Merge pull request openvinotoolkit#4 from itikhono/itikhono/pdpd/place
Browse files Browse the repository at this point in the history
PDPD Place implementation
  • Loading branch information
nosovmik authored Apr 16, 2021
2 parents 5aed606 + bb1b949 commit f1d5e82
Show file tree
Hide file tree
Showing 13 changed files with 438 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ namespace frontend {

class NGRAPH_API FrontEndPDPD : public FrontEnd
{
std::shared_ptr<Function> convert_model(const std::shared_ptr<InputModelPDPD>& model) const;
std::shared_ptr<opset6::Constant> read_tensor(std::shared_ptr<VarPlacePDPD> place,
std::shared_ptr<InputModelPDPD> model) const;
static std::shared_ptr<Function> convert_model(const std::shared_ptr<InputModelPDPD>& model);
static std::shared_ptr<opset6::Constant> read_tensor(const std::shared_ptr<TensorPlacePDPD>& place,
const std::shared_ptr<InputModelPDPD>& model);
public:

FrontEndPDPD ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ class NGRAPH_API InputModelPDPD : public InputModel

std::vector<float> readWeight(const std::string& name, int64_t tensor_length);
std::vector<std::shared_ptr<OpPlacePDPD>> getOpPlaces(int i) const;
std::map<std::string, std::shared_ptr<VarPlacePDPD>> getVarPlaces(int i) const;
std::map<std::string, std::shared_ptr<TensorPlacePDPD>> getVarPlaces(int i) const;
size_t getBlockNumber() const;

public:
InputModelPDPD (const std::string& _path);
std::vector<Place::Ptr> getInputs () const;
std::vector<Place::Ptr> getOutputs () const;
Place::Ptr getPlaceByTensorName (const std::string& tensorName) const;
void overrideAllOutputs (const std::vector<Place::Ptr>& outputs);
void overrideAllInputs (const std::vector<Place::Ptr>& inputs);
void extractSubgraph (const std::vector<Place::Ptr>& inputs, const std::vector<Place::Ptr>& outputs);
void setDefaultShape (Place::Ptr place, const ngraph::Shape&);
void setPartialShape (Place::Ptr place, const ngraph::PartialShape&);
explicit InputModelPDPD (const std::string& _path);
std::vector<Place::Ptr> getInputs () const override;
std::vector<Place::Ptr> getOutputs () const override;
Place::Ptr getPlaceByTensorName (const std::string& tensorName) const override;
void overrideAllOutputs (const std::vector<Place::Ptr>& outputs) override;
void overrideAllInputs (const std::vector<Place::Ptr>& inputs) override;
void extractSubgraph (const std::vector<Place::Ptr>& inputs, const std::vector<Place::Ptr>& outputs) override;
void setDefaultShape (Place::Ptr place, const ngraph::Shape&) override;
void setPartialShape (Place::Ptr place, const ngraph::PartialShape&) override;
};

} // namespace frontend
Expand Down
185 changes: 158 additions & 27 deletions ngraph/frontend/paddlepaddle/include/paddlepaddle_frontend/place.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//*****************************************************************************
// Copyright 2017-2021 Intel Corporation
// Copyright 2021 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,46 +17,177 @@
#pragma once

#include <frontend_manager/frontend_manager.hpp>
#include <paddlepaddle_frontend/utility.hpp>

namespace paddle {
namespace framework {
namespace proto {

class OpDesc;
class VarDesc;

} // proto
} // framework
} // paddle

namespace ngraph {
namespace frontend {

class PlacePDPD : public Place
{
// TODO
class TensorPlacePDPD;
class OpPlacePDPD;

class PlacePDPD : public Place {
public:
PlacePDPD(const InputModel& input_model, const std::vector<std::string>& names)
: m_input_model(input_model),
m_names(names) {
}

explicit PlacePDPD(const InputModel& input_model) : PlacePDPD(input_model, std::vector<std::string>{}) {
}

~PlacePDPD() override = default;

bool isInput() const override;

bool isOutput() const override;

bool isEqual(Ptr another) const override { return this == another.get(); }

std::vector<std::string> getNames() const override { return m_names; }

private:
std::vector<std::string> m_names;
const InputModel& m_input_model;
};

class InPortPlacePDPD : public PlacePDPD
{
// TODO
class InPortPlacePDPD : public PlacePDPD {
public:
explicit InPortPlacePDPD(const InputModel& input_model)
: PlacePDPD(input_model) {
}

void setOp(const std::weak_ptr<OpPlacePDPD>& op) {
m_op = op;
}

void addSourceTensor(const std::weak_ptr<TensorPlacePDPD>& source_tensor) {
m_source_tensors.push_back(source_tensor);
}

std::vector<std::shared_ptr<TensorPlacePDPD>> getSourceTensors() const;

std::shared_ptr<Place> getSourceTensor(int idx) const override;

std::shared_ptr<TensorPlacePDPD> getSourceTensorPDPD(int idx) const;

std::shared_ptr<OpPlacePDPD> getOp();
private:
std::vector<std::weak_ptr<TensorPlacePDPD>> m_source_tensors;
std::weak_ptr<OpPlacePDPD> m_op;
};

class OutPortPlacePDPD : public PlacePDPD
{
// TODO
class OutPortPlacePDPD : public PlacePDPD {
public:
explicit OutPortPlacePDPD(const InputModel& input_model)
: PlacePDPD(input_model) {
}

void setOp(const std::weak_ptr<OpPlacePDPD>& op) { m_op = op; }

void addTargetTensor(const std::weak_ptr<TensorPlacePDPD>& target_tensor) {
m_target_tensors.push_back(target_tensor);
}

std::shared_ptr<Place> getTargetTensor(int idx) const override;

std::shared_ptr<TensorPlacePDPD> getTargetTensorPDPD(int idx) const;

std::vector<std::shared_ptr<TensorPlacePDPD>> getTargetTensors() const;
private:
std::weak_ptr<OpPlacePDPD> m_op;
std::vector<std::weak_ptr<TensorPlacePDPD>> m_target_tensors;
};

class VarPlacePDPD;
class OpPlacePDPD : public PlacePDPD
{
class OpPlacePDPD : public PlacePDPD {
public:
InputModel* model;
const void* op; // TODO: make it cleaner
std::map<std::string, std::vector<std::weak_ptr<VarPlacePDPD>>> outputs;
std::map<std::string, std::vector<std::weak_ptr<VarPlacePDPD>>> inputs;
OpPlacePDPD(const void* _op) : op(_op) {}
OpPlacePDPD(const InputModel& input_model,
const std::vector<std::string>& names,
const std::shared_ptr<paddle::framework::proto::OpDesc>& op_desc);

OpPlacePDPD(const InputModel& input_model,
const std::shared_ptr<paddle::framework::proto::OpDesc>& op_desc);

void addInPort(const std::shared_ptr<InPortPlacePDPD>& input, const std::string& name) {
m_input_ports[name] = input;
}

void addOutPort(const std::shared_ptr<OutPortPlacePDPD>& output, const std::string& name) {
m_output_ports[name] = output;
}

const std::map<std::string, std::shared_ptr<OutPortPlacePDPD>>& getOutputPorts() const {
return m_output_ports;
}

const std::map<std::string, std::shared_ptr<InPortPlacePDPD>>& getInputPorts() const {
return m_input_ports;
}

std::shared_ptr<OutPortPlacePDPD> getOutputPortByName(const std::string& name) {
return m_output_ports[name];
}

std::shared_ptr<InPortPlacePDPD> getInputPortByName(const std::string& name) {
return m_input_ports[name];
}

const std::shared_ptr<paddle::framework::proto::OpDesc>& getDesc() const { return m_op_desc; }

private:
std::shared_ptr<paddle::framework::proto::OpDesc> m_op_desc;
std::map<std::string, std::shared_ptr<InPortPlacePDPD>> m_input_ports;
std::map<std::string, std::shared_ptr<OutPortPlacePDPD>> m_output_ports;
};

class VarPlacePDPD : public PlacePDPD
{
class TensorPlacePDPD : public PlacePDPD {
public:
InputModel* model;
const void* var; // TODO: make it cleaner
std::vector<std::weak_ptr<OpPlacePDPD>> producing_ops; // should never have more than 1 element
std::vector<std::weak_ptr<OpPlacePDPD>> consuming_ops;
PartialShape shape;
element::Type type;
VarPlacePDPD(const void* _var) : var(_var) {}
TensorPlacePDPD(const InputModel& input_model,
const std::vector<std::string>& names,
const std::shared_ptr<paddle::framework::proto::VarDesc>& var_desc);

TensorPlacePDPD(const InputModel& input_model,
const std::shared_ptr<paddle::framework::proto::VarDesc>& var_desc);

void addProducingPort(const std::shared_ptr<OutPortPlacePDPD>& out_port) {
m_producing_ports.push_back(out_port);
}

void addConsumingPort(const std::shared_ptr<InPortPlacePDPD>& in_port) {
m_consuming_ports.push_back(in_port);
}

std::vector<Place::Ptr> getConsumingPorts () const override;

Ptr getProducingPort () const override;

const PartialShape& getPartialShape() const { return m_pshape; }

const element::Type& getElementType() const { return m_type; }

void setPartialShape(const PartialShape& pshape) { m_pshape = pshape; }

void setElementType(const element::Type& type) { m_type = type; }

const std::shared_ptr<paddle::framework::proto::VarDesc>& getDesc() const { return m_var_desc; }

private:
std::shared_ptr<paddle::framework::proto::VarDesc> m_var_desc;
PartialShape m_pshape;
element::Type m_type;

std::vector<std::weak_ptr<OutPortPlacePDPD>> m_producing_ports;
std::vector<std::weak_ptr<InPortPlacePDPD>> m_consuming_ports;
};

} // namespace frontend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

#include <frontend_manager/frontend_manager.hpp>

#include <paddlepaddle_frontend/place.hpp>

namespace ngraph {
namespace frontend {

Expand Down
Loading

0 comments on commit f1d5e82

Please sign in to comment.