Skip to content
Snippets Groups Projects
Commit 519e386e authored by Cyril Moineau's avatar Cyril Moineau Committed by Maxence Naud
Browse files

Make ProducerOp registrable in Python.

parent b83eb580
No related branches found
No related tags found
2 merge requests!105version 0.2.0,!85Initial working python registrar.
...@@ -28,7 +28,7 @@ enum class ProdAttr { Constant }; ...@@ -28,7 +28,7 @@ enum class ProdAttr { Constant };
class Producer_Op class Producer_Op
: public OperatorTensor, : public OperatorTensor,
public Registrable<Producer_Op, std::string, std::unique_ptr<OperatorImpl>( public Registrable<Producer_Op, std::string, std::shared_ptr<OperatorImpl>(
const Producer_Op &)>, const Producer_Op &)>,
public StaticAttributes<ProdAttr, bool> { public StaticAttributes<ProdAttr, bool> {
public: public:
...@@ -92,9 +92,7 @@ public: ...@@ -92,9 +92,7 @@ public:
inline const std::vector<DimSize_t> dims() const noexcept { return mOutputs[0]->dims(); } inline const std::vector<DimSize_t> dims() const noexcept { return mOutputs[0]->dims(); }
void setBackend(const std::string& name, DeviceIdx_t device = 0) override { void setBackend(const std::string& name, DeviceIdx_t device = 0) override {
if (Registrar<Producer_Op>::exists({name})) { SET_IMPL_MACRO(Producer_Op, *this, name);
mImpl = Registrar<Producer_Op>::create({name})(*this);
}
mOutputs[0]->setBackend(name, device); mOutputs[0]->setBackend(name, device);
} }
......
...@@ -139,8 +139,10 @@ void declare_registrable(py::module& m, const std::string& class_name){ ...@@ -139,8 +139,10 @@ void declare_registrable(py::module& m, const std::string& class_name){
(op).setImpl(Registrar<T_Op>::create(backend_name)(op)); \ (op).setImpl(Registrar<T_Op>::create(backend_name)(op)); \
} }
#else #else
#define SET_IMPL_MACRO(T_Op, op, backend_name) \ #define SET_IMPL_MACRO(T_Op, op, backend_name) \
(op).setImpl(Registrar<T_Op>::create(backend_name)(op)); if (Registrar<T_Op>::exists(backend_name)) { \
(op).setImpl(Registrar<T_Op>::create(backend_name)(op)); \
}
#endif #endif
} }
......
...@@ -26,6 +26,7 @@ void declare_Producer(py::module &m) { ...@@ -26,6 +26,7 @@ void declare_Producer(py::module &m) {
// m.def(("Producer_" + std::to_string(DIM)+"D").c_str(), py::overload_cast<shared_ptr<Node>&>(&Producer<DIM>), py::arg("dims"), py::arg("name")); // m.def(("Producer_" + std::to_string(DIM)+"D").c_str(), py::overload_cast<shared_ptr<Node>&>(&Producer<DIM>), py::arg("dims"), py::arg("name"));
m.def("Producer", static_cast<std::shared_ptr<Node>(*)(const std::array<DimSize_t, DIM>&, const std::string&, bool)>(&Producer), py::arg("dims"), py::arg("name") = "", py::arg("constant") = false); m.def("Producer", static_cast<std::shared_ptr<Node>(*)(const std::array<DimSize_t, DIM>&, const std::string&, bool)>(&Producer), py::arg("dims"), py::arg("name") = "", py::arg("constant") = false);
} }
...@@ -39,7 +40,7 @@ void init_Producer(py::module &m) { ...@@ -39,7 +40,7 @@ void init_Producer(py::module &m) {
.def("get_outputs_name", &Producer_Op::getOutputsName) .def("get_outputs_name", &Producer_Op::getOutputsName)
.def("attributes_name", &Producer_Op::staticGetAttrsName); .def("attributes_name", &Producer_Op::staticGetAttrsName);
m.def("Producer", static_cast<std::shared_ptr<Node>(*)(const std::shared_ptr<Tensor>, const std::string&, bool)>(&Producer), py::arg("tensor"), py::arg("name") = "", py::arg("constant") = false); m.def("Producer", static_cast<std::shared_ptr<Node>(*)(const std::shared_ptr<Tensor>, const std::string&, bool)>(&Producer), py::arg("tensor"), py::arg("name") = "", py::arg("constant") = false);
declare_registrable<Producer_Op>(m, "ProducerOp");
declare_Producer<1>(m); declare_Producer<1>(m);
declare_Producer<2>(m); declare_Producer<2>(m);
declare_Producer<3>(m); declare_Producer<3>(m);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment